Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Show comment
Hide comment
@mormegil-cz

mormegil-cz Oct 15, 2014

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 commented Oct 15, 2014

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

This comment has been minimized.

Show comment
Hide comment
@mormegil-cz

mormegil-cz Oct 15, 2014

…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.

mormegil-cz commented Oct 15, 2014

…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

This comment has been minimized.

Show comment
Hide comment
@HSchmale16

HSchmale16 Jun 14, 2016

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.

HSchmale16 commented Jun 14, 2016

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