bash 'common configuration for all appservers, like syslog setup' do

    code <<-EOF
        mkdir -p /root/tmp
        cd /root/tmp

        # install rsyslog configs
        #
        rm -rf *.conf       # in case old files exit from a previously failed run
        wget https://s3.amazonaws.com/frequency_deploy/rsyslog/50-default.conf
        [ -r 50-default.conf ] || exit 2
        wget https://s3.amazonaws.com/frequency_deploy/rsyslog/catalina-remote.conf
        [ -r catalina-remote.conf ] || exit 2
        wget https://s3.amazonaws.com/frequency_deploy/rsyslog/cron-remote.conf
        [ -r cron-remote.conf ] || exit 2
        wget https://s3.amazonaws.com/frequency_deploy/rsyslog/kern-remote.conf
        [ -r kern-remote.conf ] || exit 2
        wget https://s3.amazonaws.com/frequency_deploy/rsyslog/tomcat-access-remote.conf
        [ -r tomcat-access-remote.conf ] || exit 2

        mv -f *.conf /etc/rsyslog.d/.
        service rsyslog restart


        # ensure we always have hotdeploy and colddeploy scripts
        #
        rm -rf *.sh         # in case old files exit from a previously failed run
        wget https://s3.amazonaws.com/frequency_deploy/hotdeploy.sh
        [[ ! -r hotdeploy.sh ]] && echo "No hotdeploy.sh" && exit 2
        chmod 755 hotdeploy.sh
        mv -f hotdeploy.sh /usr/local/.

        wget https://s3.amazonaws.com/frequency_deploy/colddeploy.sh
        [[ ! -r colddeploy.sh ]] && echo "No colddeploy.sh" && exit 2
        chmod 755 colddeploy.sh
        mv -f colddeploy.sh /usr/local/.

        # also get undeploy script
        #
        rm -rf *.sh         # in case old files exit from a previously failed run
        wget https://s3.amazonaws.com/frequency_deploy/undeploy.sh
        [[ ! -r undeploy.sh ]] && echo "No undeploy.sh" && exit 2
        mv -f undeploy.sh /usr/local/.
        chmod 754 /usr/local/undeploy.sh

        # write JMX credentials that Tomcat will be looking for. these can be insecure since SSH tunnelling is required anyway anyway.
        #
        tomcat_home=/usr/local/tomcat7
        cat - > ${tomcat_home}/conf/jmxremote.access <<JMXACCESS
observer readonly
admin readwrite
JMXACCESS
        cat - > ${tomcat_home}/conf/jmxremote.password <<JMXPASSWD
observer observer
admin admin
JMXPASSWD
        chmod 600 ${tomcat_home}/conf/jmxremote.password

        # support logrotate
        #
        rm -rf logrotate-tomcat
        wget https://s3.amazonaws.com/frequency_deploy/logrotate-tomcat
        [[ ! -r logrotate-tomcat ]] && echo "No logrotate-tomcat" && exit 2
        mv -f logrotate-tomcat /etc/logrotate.d/tomcat
        chmod 644 /etc/logrotate.d/tomcat

    EOF
end

