From 2902601157bcd606b2b8773dbf432ecc4d05138a Mon Sep 17 00:00:00 2001 From: Alan Garcia Date: Thu, 12 Sep 2013 09:28:31 +0000 Subject: [PATCH] Fix #1066 Permet de locker tout les jobs --- bureau/class/config.php | 1 + bureau/class/m_admin.php | 8 ++++++++ install/alternc.install | 6 ++++++ src/compress_logs.sh | 2 ++ src/cron_users.sh | 2 ++ src/delete_logs.sh | 3 ++- src/do_actions.php | 2 ++ src/functions.sh | 21 +++++++++++++++++++++ src/lxc_stopexpired.php | 2 ++ src/update_domains.sh | 2 ++ src/update_mails.sh | 2 ++ 11 files changed, 50 insertions(+), 1 deletion(-) diff --git a/bureau/class/config.php b/bureau/class/config.php index 1085e688..a5dd6b9a 100644 --- a/bureau/class/config.php +++ b/bureau/class/config.php @@ -102,6 +102,7 @@ if(isset($L_ALTERNC_LOGS_ARCHIVE)) define('ALTERNC_LOGS', "$L_ALTERNC_LOGS"); define('ALTERNC_PANEL', "/usr/share/alternc/panel"); define('ALTERNC_LOCALES', ALTERNC_PANEL."/locales"); +define('ALTERNC_LOCK_JOBS', '/var/run/alternc/jobs-lock'); /* PHPLIB inclusions : */ $root=ALTERNC_PANEL."/"; diff --git a/bureau/class/m_admin.php b/bureau/class/m_admin.php index bbc5cfc7..7bd0d283 100644 --- a/bureau/class/m_admin.php +++ b/bureau/class/m_admin.php @@ -134,6 +134,14 @@ class m_admin { return $obj; } + function stop_if_jobs_locked() { + if ( file_exists(ALTERNC_LOCK_JOBS)) { + echo "There is a file ".ALTERNC_LOCK_JOBS."\n"; + echo "So no jobs are allowed\n"; + echo "Did you launch alternc.install ?\n"; + die(); + } + } /* ----------------------------------------------------------------- */ /** Returns the known information about a hosted account diff --git a/install/alternc.install b/install/alternc.install index 6f791fab..b570f4bf 100644 --- a/install/alternc.install +++ b/install/alternc.install @@ -45,6 +45,9 @@ done . /usr/lib/alternc/functions.sh +# Lock the jobs ! +lock_jobs + # hook run-parts --arg=startup /usr/lib/alternc/install.d @@ -573,3 +576,6 @@ echo "Compile PO files" # hook run-parts --arg=end /usr/lib/alternc/install.d + +# Unlock jobs ! +unlock_jobs diff --git a/src/compress_logs.sh b/src/compress_logs.sh index 925bc6db..1dc84737 100644 --- a/src/compress_logs.sh +++ b/src/compress_logs.sh @@ -14,6 +14,8 @@ for CONFIG_FILE in \ . "$CONFIG_FILE" done +stop_if_jobs_locked + # ALTERNC_LOGS is from local.sh #Compress logs older than XX days diff --git a/src/cron_users.sh b/src/cron_users.sh index 49e2eb92..576a99ed 100755 --- a/src/cron_users.sh +++ b/src/cron_users.sh @@ -13,6 +13,8 @@ for CONFIG_FILE in \ . "$CONFIG_FILE" done +stop_if_jobs_locked + max_process=2 tasks () { diff --git a/src/delete_logs.sh b/src/delete_logs.sh index 4feecaa8..3fb76285 100644 --- a/src/delete_logs.sh +++ b/src/delete_logs.sh @@ -14,6 +14,7 @@ for CONFIG_FILE in \ . "$CONFIG_FILE" done -# ALTERNC_LOGS is from local.sh +stop_if_jobs_locked +# ALTERNC_LOGS is from local.sh nice 10 -n find "$ALTERNC_LOGS" -mtime +$DAYS -delete diff --git a/src/do_actions.php b/src/do_actions.php index 8ac42392..f5029116 100644 --- a/src/do_actions.php +++ b/src/do_actions.php @@ -53,6 +53,8 @@ function mail_it(){ require_once("/usr/share/alternc/panel/class/config_nochk.php"); +$admin->stop_if_jobs_locked(); + $LOCK_FILE='/var/run/alternc/do_actions_cron.lock'; $SCRIPT='/usr/bin/php do_actions.php'; $MY_PID=getmypid(); diff --git a/src/functions.sh b/src/functions.sh index 19685e41..e1d576a1 100755 --- a/src/functions.sh +++ b/src/functions.sh @@ -32,6 +32,7 @@ mysql_query() { /usr/bin/mysql --defaults-file=/etc/alternc/my.cnf -Bs -e "$@" ; DOMAIN_LOG_FILE="/var/log/alternc/update_domains.log" VHOST_FILE="$VHOST_DIR/vhosts_all.conf" VHOST_MANUALCONF="$VHOST_DIR/manual/" +LOCK_JOBS="/var/run/alternc/jobs-lock" # Some useful miscellaneous shell functions @@ -119,3 +120,23 @@ generate_string() { echo } +lock_jobs() { + test -d "$(dirname "$LOCK_JOBS")" || mkdir -p "$(dirname "$LOCK_JOBS")" + touch "$LOCK_JOBS" +} + +unlock_jobs() { + test -e "$LOCK_JOBS" && rm -f "$LOCK_JOBS" +} + +are_jobs_locked() { + return $(test -e "$LOCK_JOBS") +} + +stop_if_jobs_locked() { + are_jobs_locked || return + echo "There is a file $LOCK_JOBS" + echo "So no jobs are allowed, not even for $0" + echo "Did you launch alternc.install ?" + exit 42 +} diff --git a/src/lxc_stopexpired.php b/src/lxc_stopexpired.php index 67eaea45..50ad9bcc 100755 --- a/src/lxc_stopexpired.php +++ b/src/lxc_stopexpired.php @@ -30,6 +30,8 @@ */ require_once("/usr/share/alternc/panel/class/config_nochk.php"); +$admin->stop_if_jobs_locked(); + # Be super user #$mem->setid(2000); $admin->enabled=1; diff --git a/src/update_domains.sh b/src/update_domains.sh index f89167a7..89df3bc6 100644 --- a/src/update_domains.sh +++ b/src/update_domains.sh @@ -14,6 +14,8 @@ for CONFIG_FILE in \ . "$CONFIG_FILE" done +stop_if_jobs_locked + # Some vars umask 022 LOCK_FILE="/usr/share/alternc/panel/cron.lock" # FIXME doesn't seem clean to be here diff --git a/src/update_mails.sh b/src/update_mails.sh index e5f7e8e5..2ea9e577 100755 --- a/src/update_mails.sh +++ b/src/update_mails.sh @@ -13,6 +13,8 @@ for CONFIG_FILE in \ . "$CONFIG_FILE" done +stop_if_jobs_locked + LOCK_FILE="/var/run/alternc/update_mails" # ALTERNC_MAIL is from local.sh