Skip to content

Instantly share code, notes, and snippets.

@holysugar
Forked from oranie/gist:3697669
Last active December 14, 2015 18:58
Show Gist options
  • Save holysugar/5132691 to your computer and use it in GitHub Desktop.
Save holysugar/5132691 to your computer and use it in GitHub Desktop.
/etc/init.d/growthforecast
#!/bin/bash
#
# /etc/rc.d/init.d/growthforecast
#
# chkconfig: - 80 20
# description: growthforecast
# processname: growthforecast
# pidfile: /var/run/growthforecast/growthforecast.pid
#
### BEGIN INIT INFO
# Provides: growthforecast
# Default-Stop: 0 1 6
# Required-Start: $local_fs
# Required-Stop: $local_fs
### END INIT INFO
# Source function library.
. /etc/init.d/functions
name="growthforecast"
prog="growthforecast.pl"
USER="growthforecast"
PERLVER=5.16.2
PROG_PATH=/home/${USER}/perl5/perlbrew/perls/perl-${PERLVER}/bin/growthforecast.pl
DATADIR=/home/${USER}/gfdata
#LISTEN=127.0.0.1
LISTEN=0.0.0.0
LOG="/var/log/${name}/${name}.log"
DAEMON_ARGS="--user ${USER}"
PIDFILE=/var/run/${name}/${name}.pid
PROG_ARGS="--data-dir ${DATADIR} --host ${LISTEN} --front-proxy 127.0.0.1 --port 5125 >> $LOG 2>&1 & echo \$! > ${PIDFILE}"
start() {
if [ -f /var/lock/subsys/$prog ];then
echo "${prog} is runnig......"
exit
fi
echo -n "Starting $name: "
daemon $DAEMON_ARGS $PROG_PATH "$PROG_ARGS"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
return $RETVAL
}
stop() {
echo -n "Shutting down $name: "
if [ -e "${PIDFILE}" ]; then
killproc -p ${PIDFILE} || killproc $prog
else
killproc $prog
fi
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $PIDFILE && rm -f /var/lock/subsys/$prog
return $RETVAL
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
killproc $prog -HUP
;;
condrestart)
[ -f /var/lock/subsys/$prog ] && restart || :
;;
status)
status $prog
;;
*)
echo "Usage: $prog {start|stop|reload|restart|condrestart|status}"
exit 1
;;
esac
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment