Skip to content

Instantly share code, notes, and snippets.

@FunTimeCoding
Created June 21, 2014 17:46
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save FunTimeCoding/da210e2a3b7389a72682 to your computer and use it in GitHub Desktop.
Save FunTimeCoding/da210e2a3b7389a72682 to your computer and use it in GitHub Desktop.
phabricator daemons init script
#! /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: Alexander Reitzel <funtimecoding@gmail.com>
# Do NOT "set -e"
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="phabricator daemons"
NAME=phd
USER=shiin
DAEMON=/var/www/phabricator/phabricator/bin/${NAME}
SCRIPTNAME=/etc/init.d/${NAME}
[ -x "${DAEMON}" ] || exit 0
[ -r /etc/default/${NAME} ] && . /etc/default/${NAME}
. /lib/init/vars.sh
. /lib/lsb/init-functions
run_as_user()
{
sudo -u "${USER}" -s /bin/bash -c "${1}"
}
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"
return 0
}
do_stop()
{
if ! is_running; then
return 1
fi
run_as_user "${DAEMON} stop"
return 0
}
case "${1}" in
start)
[ "${VERBOSE}" != no ] && log_daemon_msg "Starting ${DESC}" "${NAME}"
do_start
;;
stop)
[ "${VERBOSE}" != no ] && log_daemon_msg "Stopping ${DESC}" "${NAME}"
do_stop
;;
status)
if is_running; then
exit 0
else
exit 1
fi
;;
restart)
log_daemon_msg "Restarting ${DESC}" "${NAME}"
do_stop
do_start
;;
*)
echo "Usage: ${SCRIPTNAME} {start|stop|status|restart}" >&2
exit 3
;;
esac
@mormegil-cz
Copy link

I had the phd daemons crashed (the Daemon console reported them yellow, with This daemon has not reported its status recently. It may have exited uncleanly.), after which phd status lists them as active, so is_running returns true, and the script refuses to (re)start them. I seem to have fixed it by using --local flag in the phd status command inside is_running. With that argument, phd status responds There are no running Phabricator daemons., so this script starts them correctly, when asked to.

@mormegil-cz
Copy link

…or maybe not. Now even phd status --local lists those dead daemons, only marking them with <DEAD>. Not sure what is the proper way to detect running daemons.

@HSchmale16
Copy link

Even with the --local modification it seems to only want to spin up one of the daemons on boot. The taskmaster one to be precise. It will only start them all if you restart it.

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