Last active
August 29, 2015 14:00
-
-
Save nathandarnell/ba6b72f056611c9bae94 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/bash | |
#Copied from wintermute at http://forum.subsonic.org/forum/viewtopic.php?t=1546 | |
#and adjusted to be more genaric and capable of being quickly adapted for multiple programs | |
#Haven't actually tested this yet though... 5/1/2014 | |
PROGRAM= | |
PID="" | |
PATH= | |
function get_pid { | |
PID=`ps ax |grep java |grep $PROGRAM |cut -d " " -f 1` | |
} | |
function stop { | |
get_pid | |
if [ -z $PID ]; then | |
echo "$PROGRAM is not running." | |
exit 1 | |
else | |
echo -n "Stopping $PROGRAM..." | |
kill $PID | |
sleep 1 | |
echo ".. Done." | |
fi | |
} | |
function start { | |
get_pid | |
if [ -z $PID ]; then | |
echo "Starting $PROGRAM..." | |
$PATH | |
get_pid | |
echo "Done. PID=$PID" | |
else | |
echo "$PROGRAM is already running, PID=$PID" | |
fi | |
} | |
function restart { | |
echo "Restarting $PROGRAM..." | |
get_pid | |
if [ -z $PID ]; then | |
start | |
else | |
stop | |
start | |
fi | |
} | |
function status { | |
get_pid | |
if [ -z $PID ]; then | |
echo "$PROGRAM is not running." | |
exit 1 | |
else | |
echo "$PROGRAM is running, PID=$PID" | |
fi | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart | |
;; | |
status) | |
status | |
;; | |
*) | |
echo "Usage: $0 {start|stop|restart|status}" | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment