Skip to content

Instantly share code, notes, and snippets.

@gerard-kanters
Last active January 26, 2017 12:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gerard-kanters/b54c297bcddb4d18316f to your computer and use it in GitHub Desktop.
Save gerard-kanters/b54c297bcddb4d18316f to your computer and use it in GitHub Desktop.
HHVM init script
#!/bin/bash
#
# hhvm Startup script for the HipHop Server
#
# chkconfig: - 85 15
# description: HHVM is an open-source virtual machine designed for executing programs written in Hack and PHP
# processname: hhvm
# config: /etc/php.ini
# config: /etc/hhvm/server.ini
# pidfile: /var/run/hhvm/hhvm.pid
#
### BEGIN INIT INFO
# Provides: hhvm
# Short-Description: start and stop HipHop Server
# Description: HHVM is an open-source virtual machine designed for executing programs written in Hack and PHP
### END INIT INFO
HHVM=${HHVM-/usr/local/bin/hhvm}
prog=hhvm
lockfile=${LOCKFILE-/var/lock/subsys/hhvm}
pidfile=${PIDFILE-/var/run/hhvm/hhvm.pid}
MODE=daemon
USER=apache
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
CONFIG1=/etc/hhvm/server.ini
#CONFIG2=/etc/hhvm/php.ini
# Source function library.
. /etc/rc.d/init.d/functions
start() {
echo -n $"Starting $prog: "
#daemon ${HHVM} --mode ${MODE} --user ${USER} -c ${CONFIG1} -c ${CONFIG2} ${ARGS}
daemon ${HHVM} --mode ${MODE} --user ${USER} -c ${CONFIG1} ${ARGS}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $HHVM
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${PID}
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $HHVM
RETVAL=$?
;;
restart)
stop
start
;;
*)
echo $"Usage: $prog {start|stop|restart}"
RETVAL=2
esac
exit $RETVAL
@gerard-kanters
Copy link
Author

This script can be used in /etc/init.d to run hhvm as a service and let it start in the different run levels on Linux. Important is that you need to define the PID in /etc/hhvm/server.ini or the service cannot be stopped or restarted.

We tested with php.ini and server.ini but since hhvm is moving most of the ini settings into the last it is better to use that. Not all php.ini setting are recognised yet but have an undocumented counterpart in hhvm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment