Skip to content

Commit

Permalink
Fix #1066
Browse files Browse the repository at this point in the history
Permet de locker tout les jobs
  • Loading branch information
fufroma committed Sep 12, 2013
1 parent 4e0f0ee commit 2902601
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions bureau/class/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ function alternc_shutdown() {
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."/";
Expand Down
8 changes: 8 additions & 0 deletions bureau/class/m_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ function hook_menu() {
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
Expand Down
6 changes: 6 additions & 0 deletions install/alternc.install
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -573,3 +576,6 @@ echo "Compile PO files"

# hook
run-parts --arg=end /usr/lib/alternc/install.d

# Unlock jobs !
unlock_jobs
2 changes: 2 additions & 0 deletions src/compress_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/cron_users.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ for CONFIG_FILE in \
. "$CONFIG_FILE"
done

stop_if_jobs_locked

max_process=2

tasks () {
Expand Down
3 changes: 2 additions & 1 deletion src/delete_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/do_actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
21 changes: 21 additions & 0 deletions src/functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions src/lxc_stopexpired.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/update_domains.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/update_mails.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2902601

Please sign in to comment.