HAProxy + Dockers + SSH + rsync + cron

#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    # local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local0
    log         127.0.0.1 local1 notice
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats
    
#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option                  http-server-close
    option                  forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend  http
    bind                        *:80

    use_backend site1

backend site1
    balance source
    hash-type consistent
    #balance leastconn
    #option httpclose
    #option forwardfor
    server server1 172.17.0.2:80
    server server2 172.17.0.3:80


listen admin
    bind 127.0.0.1:8080
    stats enable
# Contenedor Webserver + WebDAV + SSH + RSYNC
# Using RHEL 7 base image and Apache Web server
# Version 1

# Pull the rhel image from the local registry
FROM rhel7:latest
USER root

MAINTAINER Fernando Leal

# Fix per https://bugzilla.redhat.com/show_bug.cgi?id=1192200
RUN yum -y install deltarpm yum-utils --disablerepo=*-eus-* --disablerepo=*-htb-* *-sjis-*\
    --disablerepo=*-ha-* --disablerepo=*-rt-* --disablerepo=*-lb-* --disablerepo=*-rs-* --disablerepo=*-sap-*

RUN yum-config-manager --disable *-eus-* *-htb-* *-ha-* *-rt-* *-lb-* *-rs-* *-sap-* *-sjis* > /dev/null

# Instalacion de Paquetes
RUN yum -y install httpd net-tools mlocate wget bind-utils bash-completion openssh-clients openssh-server rsync hostname

# Add configuration file
ADD webdav.conf /etc/httpd/conf.d/webdav.conf
ADD htpasswd /etc/httpd/.htpasswd
RUN mkdir -p /var/www/html/webdav/
RUN touch /tmp/DavLock
RUN chown apache:apache /var/www/html/webdav /tmp/DavLock /etc/httpd/.htpasswd
RUN chmod 640 /etc/httpd/.htpasswd
RUN echo "The Web Server is Running" > /var/www/html/index.html

#
# Configuracion de SSH Server
#
RUN mkdir /var/run/sshd
RUN echo 'root:root' | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

RUN sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config

RUN /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -C '' -N ''
RUN /usr/bin/ssh-keygen -t rsa -f /etc/ssh/ssh_host_dsa_key -C '' -N ''

ENV NOTVISIBLE "in users profile"
RUN echo "export VISIBLE=now" >> /etc/profile

#
# Copia del script rsync.sh y la generacion de CRON
#
COPY rsync.cron /var/spool/cron/root
COPY rsync.sh /rsync.sh
RUN chmod 755 /rsync.sh

#
# Copia del archivo start.sh que va a levantar los servicios de HTTP + SSH + CRON
#
COPY start.sh /start.sh
RUN chmod 755 /start.sh

EXPOSE 22 80

CMD ["/start.sh"]
dev:$apr1$.3qwBDL8$vDLJ2aCr32yBNToeoKcMy.
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/webdav/
    ErrorLog /var/log/httpd/error.log
    CustomLog /var/log/httpd/access.log combined
        Alias /webdav /var/www/html/webdav
        <Directory /var/www/html/webdav>
            DAV On
            AuthType Basic
            AuthName "webdav"
            AuthUserFile /etc/httpd/.htpasswd
            Require valid-user
            Options Indexes FollowSymLinks
        </Directory>
</VirtualHost>

<IfModule mod_dav_fs.c>
    # Location of the WebDAV lock database.
    DAVLockDB /tmp/DavLock
</IfModule>
#!/bin/bash +x

IP=`hostname -I `

case "$IP"  in

       "172.17.0.2 ")
        /usr/bin/rsync --verbose --recursive  --links --times --stats -h --log-file=/tmp/rsync.log /var/www/html/webdav/ 172.17.0.3:/var/www/html/webdav/ 
       ;;

       "172.17.0.3 ")
         /usr/bin/rsync --verbose --recursive  --links --times --stats -h --log-file=/tmp/rsync.log /var/www/html/webdav/ 172.17.0.2:/var/www/html/webdav/
       ;;
 esac
######################################################################
#
# minuto(0-59) hora(0-23) dia(1-31) mes(1-12) diasemana(0-7) comando
#

* * * * * /rsync.sh

#!/bin/bash -x

/usr/sbin/sshd -D & rm -rf /run/httpd/* /tmp/httpd* && /usr/sbin/httpd -DFOREGROUND & /usr/sbin/crond -n