Created
October 22, 2015 07:26
-
-
Save kj187/63da3e2df01dfe03d763 to your computer and use it in GitHub Desktop.
Dashing service script
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 | |
NAME=dashing | |
DASHING_PORT=3030 | |
DASHING_DIR=$2 | |
PID_DIR=$DASHING_DIR/tmp/pids | |
PIDFILE=$PID_DIR/thin.pid | |
GEM_HOME=$GEM_HOME | |
if [ ! -d ${DASHING_DIR} ] ; then echo "Could not find ${DASHING_DIR} directory"; exit 1 ; fi | |
# Store dashing pid in $PID, else empty string | |
if [ -f $PIDFILE ]; then | |
PID=$(<"$PIDFILE") | |
else echo "" | |
fi | |
run() { | |
$* | |
if [ $? -ne 0 ] | |
then | |
echo "$* failed with exit code $?" | |
exit 1 | |
fi | |
} | |
function startDashing() { | |
echo "Starting Dashing ... ($DASHING_DIR)" | |
cd $DASHING_DIR | |
echo $PWD | |
run /usr/local/bin/dashing start -d -p $DASHING_PORT && sleep 2s | |
echo "Success!" | |
} | |
function stopDashing() { | |
echo | |
echo "Killing Dashing ... (PIDFILE: $PIDFILE; PID: $PID)" | |
if [ -f $PIDFILE ]; then | |
kill -9 $PID && rm -rf $PIDFILE && sleep 2s | |
echo "Dashing killed (PID: $PID)" | |
else | |
echo "Dashing is already dead!" | |
fi | |
} | |
case "$1" in | |
restart) | |
stopDashing | |
echo "Restart now ..." && sleep 2s | |
startDashing | |
;; | |
start) | |
startDashing | |
;; | |
stop) | |
stopDashing | |
;; | |
logs) | |
tail -f $DASHING_DIR/log/thin.log | |
;; | |
status) | |
ps aux | grep -i 3030 | |
;; | |
*) | |
echo "Dashing" | |
echo $"Usage: $0 {start|stop|restart|status|logs} dashingRootDir" | |
echo "Example: $0 start /var/www/dashing/" | |
exit 1 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment