Skip to content

Instantly share code, notes, and snippets.

@hinhmd
Forked from marlonbernardes/run-jar-as-a-service.md
Last active September 12, 2018 07:18
Show Gist options
  • Select an option

  • Save hinhmd/132446ce93c0038354c3aaa600041beb to your computer and use it in GitHub Desktop.

Select an option

Save hinhmd/132446ce93c0038354c3aaa600041beb to your computer and use it in GitHub Desktop.
How to make a jar file run on startup
#!/bin/bash
JAR_PATH=/root/app.jar
LOG_PATH=/root/app.log
case $1 in
start)
java -jar $JAR_PATH -a >> $LOG_PATH
;;
stop)
fuser $LOG_PATH -k || true
;;
restart)
fuser $LOG_PATH -k || true
java -jar $JAR_PATH -a >> $LOG_PATH
;;
status)
f=$( fuser app.log 2> /dev/null )
if [[ -z "$f" ]]; then
echo "Running"
else
echo "Stopped"
fi
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment