Skip to content

Instantly share code, notes, and snippets.

@juandbc
Created April 18, 2021 20:15
Show Gist options
  • Save juandbc/d2710417f2aa096a3e677664639620df to your computer and use it in GitHub Desktop.
Save juandbc/d2710417f2aa096a3e677664639620df to your computer and use it in GitHub Desktop.
Spring boot as sysv service
#!/bin/sh
### BEGIN INIT INFO
# Provides:
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: app description
# Description: app description
### END INIT INFO
# Get function from functions library
. /lib/lsb/init-functions
name=`basename $0`
pid_file="/var/run/$name.pid"
# Star the service
start() {
log_daemon_msg "Starting covid tracking app: "
java -jar -Dspring.profiles.active=local spring-jar-or-war &
### Create the lock file ###
touch /var/lock/subsys/FILE
success $"covid-tracking startup"
echo $! > "$pid_file"
}
# Restart the service
stop() {
kill $(cat $pid_file)
### Now, delete the lock file ###
rm -f /var/lock/subsys/FILE
rm "$pid_file"
echo
log_end_msg
}
### main logic ###
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status COVID
;;
restart|reload|condrestart)
stop
start
;;
*)
echo $"Usage: $0 {start|stop|restart|reload|status}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment