From 038ec39e5585cc14b6414c1dc029ce4aad8ae318 Mon Sep 17 00:00:00 2001 From: Nicolas Schteinschraber Date: Thu, 1 Aug 2013 02:55:33 -0300 Subject: [PATCH] Added BASEPATH and SUBFOLDER configs for PIDFILE Checks if the path exists, if it does not, it is created, if there is an error a message is printed with the problematic path. --- cronjobs/run-crons.sh | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/cronjobs/run-crons.sh b/cronjobs/run-crons.sh index ae211091..89d265d4 100755 --- a/cronjobs/run-crons.sh +++ b/cronjobs/run-crons.sh @@ -15,8 +15,13 @@ CRONS="findblock.php proportional_payout.php pplns_payout.php pps_payout.php blo # Output additional runtime information VERBOSE="0" -# Prefix to add to PIDFILE name, so it will be unique in a multipool server. -PIDPREFIX="" +# Base path for PIDFILE, (full path). +BASEPATH="/tmp" + +# Subfolder for PIDFILE, so it's path will be unique in a multipool server. +# Path relative to BASEPATH. +# Eg. SUBFOLDER="LTC" +SUBFOLDER="" ################################################################ # # @@ -28,15 +33,15 @@ PIDPREFIX="" ME=$( basename $0 ) # Overwrite some settings via command line arguments -while getopts "hvp:x:" opt; do +while getopts "hvp:d:" opt; do case "$opt" in h|\?) - echo "Usage: $0 [-v] [-p PHP_BINARY] [-x PIDPREFIX]"; + echo "Usage: $0 [-v] [-p PHP_BINARY] [-d SUBFOLDER]"; exit 0 ;; v) VERBOSE=1 ;; p) PHP_BIN=$OPTARG ;; - x) PIDPREFIX=$OPTARG ;; + d) SUBFOLDER=$OPTARG ;; :) echo "Option -$OPTARG requires an argument." >&2 exit 1 @@ -45,7 +50,16 @@ while getopts "hvp:x:" opt; do done # Path to PID file, needs to be writable by user running this -PIDFILE="/tmp/${PIDPREFIX}${ME}.pid" +PIDFILE="${BASEPATH}/${SUBFOLDER}/${ME}.pid" +# Clean PIDFILE path +PIDFILE=$(readlink -m "$PIDFILE") + +# Create folders recursively if necessary +if + !(mkdir -p $( dirname $PIDFILE) ) +then + echo "Error creating PIDFILE path: $( dirname $PIDFILE )" +fi # Find scripts path if [[ -L $0 ]]; then