#!/bin/sh # # hhvm-fcgi -- startup script for HHVM FastCGI # # chkconfig: 345 80 20 # # description: Starts The HHVM FastCGI Daemon # processname: hhvm-fcgi # config: /etc/hhvm/server.hdf # pidfile: /var/run/hhvm/hhvm-fcgi.pid # # Source function library . /etc/rc.d/init.d/functions # Get network config . /etc/sysconfig/network # Check that networking is up. if is_yes "${NETWORKING}"; then if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then msg_network_down "HHVM FastCGI Daemon" exit 1 fi else exit 0 fi # Set defaults # Default values. This values can be overwritten in '/etc/sysconfig/hhvm-fcgi' DAEMON="/usr/bin/hhvm" NAME="hhvm" CONFIG_FILE="/etc/hhvm/server.hdf" RUN_AS_USER="http" LISTEN_PORT="9000" ADDITIONAL_ARGS="" # Get service config - may override defaults [ -f /etc/sysconfig/hhvm-fcgi ] && . /etc/sysconfig/hhvm-fcgi PIDFILE="/var/run/hhvm/hhvm-fcgi.pid" DAEMON_ARGS="--config ${CONFIG_FILE} \ --user ${RUN_AS_USER} \ --mode daemon \ -vServer.Type=fastcgi \ -vServer.Port=${LISTEN_PORT} \ -vPidFile=${PIDFILE} \ ${ADDITIONAL_ARGS}" # configtest itself # must return non-zero if check failed # output is discarded if checkconfig is ran without details configtest() { start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test } # wrapper for configtest checkconfig() { local details=${1:-0} if [ $details = 1 ]; then # run config test and display report (status action) show "Checking %s configuration" "HHVM FastCGI Daemon"; busy local out out=$(configtest 2>&1) RETVAL=$? if [ $RETVAL = 0 ]; then ok else fail fi [ "$out" ] && echo >&2 "$out" else # run config test and abort with nice message if failed # (for actions checking status before action). configtest >/dev/null 2>&1 RETVAL=$? if [ $RETVAL != 0 ]; then show "Checking %s configuration" "HHVM FastCGI Daemon"; fail nls 'Configuration test failed. See details with %s "checkconfig"' $0 exit $RETVAL fi fi } start() { # Check if the service is already running? if [ -f /var/lock/subsys/hhvm-fcgi ]; then msg_already_running "HHVM FastCGI Daemon" return fi checkconfig msg_starting "HHVM FastCGI Daemon" daemon --pidfile $PIDFILE $DAEMON $DAEMON_ARGS RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/hhvm-fcgi } stop() { if [ ! -f /var/lock/subsys/hhvm-fcgi ]; then msg_not_running "HHVM FastCGI Daemon" return fi # Stop daemons. msg_stopping "HHVM FastCGI Daemon" killproc --pidfile $PIDFILE $NAME -TERM RETVAL=$? rm -f /var/lock/subsys/hhvm-fcgi } condrestart() { if [ ! -f /var/lock/subsys/hhvm-fcgi ]; then msg_not_running "HHVM FastCGI Daemon" RETVAL=$1 return fi checkconfig stop start } RETVAL=0 # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) checkconfig stop start ;; try-restart) condrestart 0 ;; force-reload) condrestart 7 ;; checkconfig|configtest) checkconfig 1 ;; status) status --pidfile $PIDFILE hhvm-fcgi hhvm RETVAL=$? ;; *) msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|checkconfig|status}" exit 3 esac exit $RETVAL