#!/bin/bash

function system_env_config() {
    for ip in ${IP_LIST[@]}; do
        # deploy flush cache
        $SSH root@${ip} "mkdir /opt/scripts"
        $SCP scripts/clean-cache.sh root@${ip}:/opt/scripts/
        $SCP scripts/clean-container.sh root@${ip}:/opt/scripts/
        $SSH root@${ip} "echo '1 */1 * * * /bin/bash /opt/scripts/clean-cache.sh &> /dev/null' > /var/spool/cron/root"
        $SSH root@${ip} "echo '0 0 * * *' /bin/bash /opt/scripts/clean-container.sh >> /var/spool/cron/root"

        # deploy resources monitor
        $SCP scripts/edoc2-monitor.sh root@${ip}:/opt/scripts/
        $SSH root@${ip} "echo '*/2 * * * * flock -xn /tmp/edoc2.lock -c /opt/scripts/edoc2-monitor.sh' >> /var/spool/cron/root"

        # config system
        $SCP scripts/system-config.sh root@${ip}:/tmp/system-config.sh
        $SSH root@${ip} "export FIREWALLD=${FIREWALLD}; sh /tmp/system-config.sh && rm -rf /tmp/system-config.sh"

        # copy some check scripts
        $SCP scripts/check-middleware.sh root@${ip}:/opt/scripts/
        $SCP scripts/logsave.sh root@${ip}:/opt/scripts/
    done
}
