Skip to content

Instantly share code, notes, and snippets.

@gmambro
Created August 9, 2014 22:33
Show Gist options
  • Save gmambro/4a102fe873014906e122 to your computer and use it in GitHub Desktop.
Save gmambro/4a102fe873014906e122 to your computer and use it in GitHub Desktop.
RHEL/Centos init script for a Catalyst FCGI server
#!/bin/sh
#
# chkconfig: 345 86 14
# description: MyApp FCGI server
# pidfile: /var/run/myapp/pid
PATH=/sbin:/bin:/usr/bin:/usr/sbin
# Source function library.
. /etc/rc.d/init.d/functions
# Get config.
test -f /etc/sysconfig/network && . /etc/sysconfig/network
# Check that we are root ... so non-root users stop here
[ `id -u` = 0 ] || exit 1
# Check that networking is up.
[ "${NETWORKING}" = "yes" ] || exit 0
APP_HOME=/opt/myapp
RUN_DIR=/var/run/myapp
USER=myapprun
PID_FILE=$RUN_DIR/pid
SOCKET_FILE=$RUN_DIR/socket
SUBSYS_FILE=/var/lock/subsys/myapp
SCRIPT=$APP_HOME/script/myapp_fastcgi.pl
SCRIPT_ARGS="-l $SOCKET_FILE -p $PID_FILE -d"
# Check that the script is executable
[ -x $SCRIPT ] || exit 5
start(){
echo -n $"Starting myapp: "
daemon --user $USER $SCRIPT "$SCRIPT_ARGS >/dev/null 2>&1"
RETVAL=$?
echo
touch $SUBSYS_FILE
return $RETVAL
}
stop(){
echo -n $"Stopping myapp: "
killproc -p $PID_FILE myapp
RETVAL=$?
echo
rm -f $SUBSYS_FILE
return $RETVAL
}
restart(){
stop
start
}
condrestart(){
[ -e $SUBSYS_FILE ] && restart
return 0
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p $PID_FILE myapp
;;
restart)
restart
;;
condrestart)
condrestart
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart}"
RETVAL=1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment