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.
This commit is contained in:
Nicolas Schteinschraber 2013-08-01 02:55:33 -03:00
parent fee9d82192
commit 038ec39e55

View File

@ -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