Skip to content

Instantly share code, notes, and snippets.

@scottsweb
Last active August 31, 2015 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottsweb/9312f799bc3d60a03853 to your computer and use it in GitHub Desktop.
Save scottsweb/9312f799bc3d60a03853 to your computer and use it in GitHub Desktop.
init.d script for Node-RED
#!/bin/bash
### BEGIN INIT INFO
# Provides: node-red
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start or stop the node-red server
### END INIT INFO
# User that launches node-RED (it's advised to create a new user for Node-RED)
# You can do : sudo useradd node-red
# then change the USER=root by USER=node-red
# if you change the user, dont forget to also change the ownership of the log file (and create it if it doesn't exist):
# sudo chown NEWUSER /var/log/node-red.log
# else the log won't be writtable
USER=scott
# USER_DIR='/home/scott/.node-red/'
NAME=node-red
DAEMON=/usr/bin/node-red-pi
OPTIONS="--max-old-space-size=256"
if [ -n "$USER_DIR" ]; then
OPTIONS="$OPTIONS --userDir=$USER_DIR"
fi
LOG='/var/log/node-red.log'
PIDFILE=/var/run/node-red.pid
. /lib/lsb/init-functions
case "$1" in
start)
log_daemon_msg "Starting daemon" "$NAME"
if [ ! -f "$LOG" ]; then
touch $LOG
chown $USER $LOG
fi
start-stop-daemon --start --background --quiet \
--chuid $USER \
--make-pidfile --pidfile $PIDFILE \
--startas /bin/bash -- -c "exec $DAEMON $OPTIONS >> $LOG 2>&1"
log_end_msg 0
;;
stop)
log_daemon_msg "Stopping daemon" "$NAME"
pkill -SIGINT ^node-red$
rm -f $PIDFILE
sleep 1
log_end_msg 0
;;
restart)
$0 stop
sleep 5
$0 start
;;
status)
status_of_proc "$NAME"
exit $?
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment