Simple start/stop shell-script
Posted: Thu Feb 05, 2009 6:54 am
Nothing fancy but maybe useful for someone.
- Code: Select all
#!/bin/bash
PID=""
function get_pid {
PID=`ps ax |grep java |grep subsonic |cut -d " " -f 1`
}
function stop {
get_pid
if [ -z $PID ]; then
echo "Subsonic is not running."
exit 1
else
echo -n "Stopping Subsonic.."
kill $PID
sleep 1
echo ".. Done."
fi
}
function start {
get_pid
if [ -z $PID ]; then
echo "Starting Subsonic.."
/var/subsonic/subsonic.sh
get_pid
echo "Done. PID=$PID"
else
echo "Subsonic is already running, PID=$PID"
fi
}
function restart {
echo "Restarting Subsonic.."
get_pid
if [ -z $PID ]; then
start
else
stop
start
fi
}
function status {
get_pid
if [ -z $PID ]; then
echo "Subsonic is not running."
exit 1
else
echo "Subsonic is running, PID=$PID"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
status)
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
esac