description "Upstart script to run rsync replication between datasets"
author "Sam Zaydel"
env NODE_BIN=/usr/bin/node
env NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
env APP_DIR=/opt/zfs-poola-rsync/bin
env SCRIPT_FILE="runme.js" # Entry point for the nodejs app
env LOG_FILE=/var/log/zfs-poola-rsync.log
env RUN_AS="root" # Upstart can only be run nicely as root, need to drop privileges
#env SERVER_ENV="anything" # Usual apps can be run in different environments (development, test, production ...)
# I typically use the environment variable NODE_ENV (see below)
# If not needed simply remove the "NODE_ENV=$SERVER_ENV" below
# Start service on startup, stop on shutdown
start on runlevel [2345]
stop on runlevel [016]
# Respawn in case of a crash, with default parameters
respawn
script
# Make sure logfile exists and can be written by the user we drop privileges to
touch $LOG_FILE
chown $RUN_AS:$RUN_AS $LOG_FILE
chdir $APP_DIR
echo "===== Begin Current Environment =====" >> $LOG_FILE
env >> $LOG_FILE
echo "===== End Current Environment =====" >> $LOG_FILE
NODE_ENV=$SERVER_ENV su -s /bin/sh -c 'exec "$0" "$@"' $RUN_AS -- $NODE_BIN $SCRIPT_FILE >> $LOG_FILE 2>&1
end script
post-start script
echo "===== App restarted =====" >> $LOG_FILE
end script