Created
March 5, 2013 09:21
-
-
Save shirishp/5089019 to your computer and use it in GitHub Desktop.
init.d script
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 | |
### BEGIN INIT INFO | |
# Provides: appstarted | |
# Required-Start:$all | |
# Required-Stop: $all | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Starts application | |
# Description: Starts application | |
### END INIT INFO | |
APP="My Application" | |
start() { | |
# Start your application | |
java -jar /home/application/myapp.jar | |
} | |
stop() { | |
# Stop your application | |
kill $YOUR_APP_PID | |
} | |
case "$1" in | |
start) | |
echo "Starting $APP" | |
start | |
echo "$APP started." | |
;; | |
stop) | |
echo "Stopping $APP" | |
stop | |
echo "$APP stopped." | |
;; | |
restart) | |
echo "Restarting $APP." | |
stop | |
sleep 2 | |
start | |
echo "$APP restarted." | |
;; | |
status) | |
# Logic to check if application is running | |
*) | |
service_name=/etc/init.d/$APP | |
echo "Usage: $service_name {start|stop|restart|status}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
where does $YOUR_APP_PID come from?