Create a gist now

Instantly share code, notes, and snippets.

@jhogendorn /phd
Last active Feb 2, 2016

What would you like to do?
Centos init.d script for Phabricator PHD
#!/bin/sh
### BEGIN INIT INFO
# Provides: phd
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: phabricator
# Description: manages phd
### END INIT INFO
# Author: Joshua Hogendorn <jhogendorn@gmail.com>
# Original Author: Alexander Reitzel <funtimecoding@gmail.com>
# Do NOT "set -e"
# source function library
. /etc/rc.d/init.d/functions
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="Phabricator Daemons"
NAME=phd
USER=phd
DAEMON=/var/phabricator/phabricator/bin/${NAME}
SCRIPTNAME=/etc/init.d/${NAME}
[ -x "${DAEMON}" ] || exit 0
run_as_user()
{
OUTPUT=$(sudo -u "${USER}" -s /bin/bash -c "${1} 2>&1")
return $?
}
is_running()
{
if run_as_user "${DAEMON} status"; then
return 0
else
return 1
fi
}
do_start()
{
if is_running; then
return 1
fi
run_as_user "${DAEMON} start"
touch /var/lock/subsys/phd
return 0
}
do_stop()
{
if ! is_running; then
return 1
fi
run_as_user "${DAEMON} stop"
rm -f /var/lock/subsys/phd
return 0
}
case "${1}" in
start)
echo -n $"Starting ${DESC}: "
do_start && success || failure
echo
;;
stop)
echo -n $"Stopping ${DESC}: "
do_stop && success || failure
echo
;;
status)
if is_running; then
exit 0
else
exit 1
fi
;;
restart)
echo -n $"Restarting ${DESC}: "
do_stop
sleep 3 # The phd controller is a bit async so hack around that by waiting
do_start
success
echo
;;
*)
echo "Usage: ${SCRIPTNAME} {start|stop|status|restart}" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment