Last active
May 8, 2023 14:24
-
-
Save alissa-maria/e7b638d82af3fb6bf20ab9b94e608d82 to your computer and use it in GitHub Desktop.
Script to start/stop/restart known applications as daemons
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 | |
| declare -a apps=( | |
| "rain" | |
| "quotes" | |
| ) | |
| app="$2" | |
| start_app() { | |
| if [[ ! " ${apps[@]} " =~ " $app " ]]; then | |
| echo ". . . ┐(´-`)┌" | |
| exit 1 | |
| fi | |
| if screen -list | grep -q "${app:0:6}"; then | |
| echo "Server $app is already running!" | |
| exit 1 | |
| fi | |
| screen -dmS "${app:0:6}" bash "${app}.sh" | |
| cat <<EOF | |
| REMINDER: pull changes from Git. | |
| Server $app started successfully! (ෆ˙ᵕ˙ෆ)♡ | |
| $(screen -ls) | |
| EOF | |
| } | |
| stop_app() { | |
| if ! screen -list | grep -q "${app:0:6}"; then | |
| echo "$app is not running." | |
| exit 1 | |
| fi | |
| screen -S "${app:0:6}" -X quit | |
| echo "Stopped "$app". (´・ω・)ノ" | |
| } | |
| case "$1" in | |
| start) | |
| start_app | |
| ;; | |
| stop) | |
| stop_app | |
| ;; | |
| restart) | |
| stop_app | |
| sleep 1 | |
| start_app | |
| ;; | |
| *) | |
| echo "Usage: $0 {start|stop|restart} app" | |
| exit 1 | |
| esac | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment