diff --git a/Bash/initScript.sh b/Bash/initScript.sh new file mode 100644 index 0000000..3caa77d --- /dev/null +++ b/Bash/initScript.sh @@ -0,0 +1,69 @@ +#!/bin/sh +# +### BEGIN INIT INFO +# Provides: scriptName +# Required-Start: $remote_fs $syslog +# Required-Stop: $remote_fs $syslog +# Should-Start: $portmap +# Should-Stop: $portmap +# X-Start-Before: nis +# X-Stop-After: nis +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# X-Interactive: true +# Short-Description: Short description of the script +# Description: description of the script +# a big one :) +### END INIT INFO + +####################### +name="kage" +dirPath="/path/to/app" +####################### +sh="/bin/bash" +pidPath="$dirPath/$name.pid" +####################### + +do_start() { + # TODO do start app + /bin/echo $! > $pidPath +} + +do_stop() { + if [ -e $pidPath ] + then + pid=$(/bin/cat $pidPath) + kill $pid + rm $pidPath + fi +} + +get_status() { + if [ -e $pidPath ] ; then + pid=$(/bin/cat $pidPath) ; + /bin/echo "$name is running with PID $pid" ; + else + /bin/echo "$name is stopped" ; + fi +} + + +case $1 in + start) + do_start + ;; + stop) + do_stop + ;; + restart) + do_stop + do_start + ;; + status) + get_status + ;; + *) + /bin/echo "Usage: $0 {start|stop|restart|status}" + exit 2 + ;; +esac