Skip to content

Instantly share code, notes, and snippets.

@shirishp
Created March 5, 2013 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shirishp/5089019 to your computer and use it in GitHub Desktop.
Save shirishp/5089019 to your computer and use it in GitHub Desktop.
init.d script
#!/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
@hablutzel1
Copy link

where does $YOUR_APP_PID come from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment