-
-
Save retrohacker/7f63b2a4b6c7a9a6a7db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
### BEGIN INIT INFO | |
# Provides: {{SERVICE_NAME}} | |
# Required-Start: $all | |
# Required-Stop: $all | |
# Should-Start: | |
# Should-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: A Node Service | |
# Description: | |
# A longer description of your node service. | |
# Please be a good citizen and update the following sections | |
# with the information for your service: | |
# * Provides | |
# * Short-Description | |
# * Description | |
# | |
### END INIT INFO | |
BASE=service | |
NODE=$(which node) | |
# Note: index.js MUST be excutable with the proper shebang: | |
# #!/usr/bin/env node | |
SERVICE=/path/to/service/index.js | |
SERVICE_PIDFILE=/var/run/${BASE}.pid | |
SERVICE_LOGFILE=/var/log/${BASE}.log | |
SERVICE_OPTS= | |
SERVICE_DESC="SERVICE" | |
# Import lsb functions | |
. /lib/lsb/init-functions | |
# Check for node | |
if [ ! -x $NODE ]; then | |
log_failure_msg "$NODE not present or not executable" | |
fi | |
case "$1" in | |
start) | |
touch "$SERVICE_LOGFILE" | |
log_begin_msg "Starting $SERVICE_DESC" | |
start-stop-daemon --start --background --no-close \ | |
--exec "$SERVICE" \ | |
--pidfile "$SERVICE_PIDFILE" \ | |
--make-pidfile \ | |
-- \ | |
$SERVICE_OPTS \ | |
>> "$SERVICE_LOGFILE" 2>&1 | |
log_end_msg $? | |
;; | |
stop) | |
log_begin_msg "Stopping $SERVICE_DESC" | |
start-stop-daemon --stop --pidfile "$SERVICE_PIDFILE" | |
log_end_msg $? | |
;; | |
status) | |
status_of_proc -p "$SERVICE_PIDFILE" "$SERVICE" "$SERVICE_DESC" | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status}" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment