Skip to content

Instantly share code, notes, and snippets.

@doppioslash doppioslash/phd forked from FunTimeCoding/phd
Created Nov 18, 2018

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.