Forked from marlonbernardes/run-jar-as-a-service.md
Last active
September 12, 2018 07:18
-
-
Save hinhmd/132446ce93c0038354c3aaa600041beb to your computer and use it in GitHub Desktop.
How to make a jar file run on startup
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 | |
| 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