Moved to dedicated repository: lmammino/cube-daemons
Last active
August 29, 2015 13:57
-
-
Save lmammino/9871386 to your computer and use it in GitHub Desktop.
This file contains 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
#/etc/init.d/cube-collector | |
NAME="cube-collector" | |
NODE_PREFIX="/usr" | |
PIDFILE="/var/run/cube/collector.pid" | |
APP_DIR="/usr/bin" | |
APP_BIN="env" | |
APP_ARGS="node $NODE_PREFIX/lib/node_modules/cube/bin/collector.js" | |
USER="cube" | |
GROUP="cube" | |
start() { | |
echo "Starting $NAME..." | |
start-stop-daemon --background --make-pidfile --pidfile $PIDFILE -o --chuid $USER:$GROUP --start --exec "$APP_DIR/$APP_BIN" -- $APP_ARGS | |
} | |
stop() { | |
echo "Stopping $NAME..." | |
start-stop-daemon -o --chuid $USER:$GROUP cube -K --pidfile $PIDFILE | |
} | |
status() { | |
PID=$(cat $PIDFILE) | |
if ! ps -p $PID > /dev/null 2>&1; then | |
echo "$NAME not running." | |
else | |
echo "$NAME running." | |
fi | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart|reload|force-reload) | |
stop | |
start | |
;; | |
status) | |
status | |
;; | |
*) | |
echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart|status}" | |
exit 1 | |
esac | |
exit 0 |
This file contains 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
#/etc/init.d/cube-evaluator | |
NAME="cube-evaluator" | |
NODE_PREFIX="/usr" | |
PIDFILE="/var/run/cube/evaluator.pid" | |
APP_DIR="/usr/bin" | |
APP_BIN="env" | |
APP_ARGS="node $NODE_PREFIX/lib/node_modules/cube/bin/evaluator.js" | |
USER="cube" | |
GROUP="cube" | |
start() { | |
echo "Starting $NAME..." | |
start-stop-daemon --background --make-pidfile --pidfile $PIDFILE -o --chuid $USER:$GROUP --start --exec "$APP_DIR/$APP_BIN" -- $APP_ARGS | |
} | |
stop() { | |
echo "Stopping $NAME..." | |
start-stop-daemon -o --chuid $USER:$GROUP cube -K --pidfile $PIDFILE | |
} | |
status() { | |
PID=$(cat $PIDFILE) | |
if ! ps -p $PID > /dev/null 2>&1; then | |
echo "$NAME not running." | |
else | |
echo "$NAME running." | |
fi | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart|reload|force-reload) | |
stop | |
start | |
;; | |
status) | |
status | |
;; | |
*) | |
echo "Usage: /etc/init.d/$NAME {start|stop|reload|force-reload|restart|status}" | |
exit 1 | |
esac | |
exit 0 |
This file contains 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/bash | |
#run as sudo | |
#install cube | |
echo "\n\n====\n1. Installing cube...\n====\n\n" | |
npm install --global cube | |
#create cube user and group | |
echo "\n\n====\n2. Creating cube user...\n====\n\n" | |
useradd -r -s /bin/false cube | |
#create cube run dir (for pid files) | |
echo "\n\n====\n3. Creating /var/run/cube folder...\n====\n\n" | |
mkdir -p /var/run/cube | |
#copying scripts | |
echo "\n\n====\n4. Copying start/stop scripts...\n====\n\n" | |
chmod +x cube-collector cube-evaluator | |
cp cube-collector /etc/init.d/cube-collector | |
cp cube-evaluator /etc/init.d/cube-evaluator | |
#running daemons | |
echo "\n\n====\n5. Starting daemons...\n====\n\n" | |
/etc/init.d/cube-collector start | |
/etc/init.d/cube-evaluator start | |
echo "\n\n Done.\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment