Created
September 11, 2021 14:02
-
-
Save rainbowdashlabs/323b0f8f1fdf67c226f63202b440df73 to your computer and use it in GitHub Desktop.
Recover, restart and upgrade your process via exit codes with bash
This file contains 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 | |
# switch to config directory | |
while true; do | |
# Of course you can use any other executable file here. We use java. | |
java \ | |
-Xms256m \ | |
-Xmx2048m \ | |
<jvm args> \ | |
-jar ./my_jar.jar | |
code=$? | |
case $code in | |
0) # proper shutdown | |
echo "Performed proper shutdown, exiting restart loop" | |
exit 0 | |
;; | |
10) # restart request | |
echo "Requested to restart" | |
continue | |
;; | |
20) # upgrade requested | |
echo "Requested to upgrade" | |
./upgrade.sh | |
continue | |
;; | |
*) # Recovering | |
echo "Unknown exit code, attempting recovery restart in a few seconds" | |
sleep 2 | |
continue | |
;; | |
esac | |
done |
This file contains 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/sh | |
#rm screenlog.0 | |
cd "$(dirname "$0")" | |
# set your screen name | |
screen -dmS <screen_name> \ | |
./loop.sh |
This file contains 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 | |
# this requires that you clone the git repository to a directory names repo | |
# To do this you need to execute | |
# git clone <remote_url> repo | |
BRANCH=${1:-master} | |
cd repo | |
git fetch --all | |
git checkout $BRANCH | |
git reset --hard origin/$BRANCH | |
git pull -f --no-rebase | |
./gradlew clean <shadowJar/build> --no-build-cache --refresh-dependencies | |
cd .. | |
# replace the my_jar name with the name of your jar file without the version numbers. | |
# this will select the matching file. when your build process outputs multiple jar you need to define the file name with the classifier | |
mv repo/build/libs/my_jar*.jar my_jar.jar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment