Skip to content

Instantly share code, notes, and snippets.

@alissa-maria
Last active May 8, 2023 14:24
Show Gist options
  • Select an option

  • Save alissa-maria/e7b638d82af3fb6bf20ab9b94e608d82 to your computer and use it in GitHub Desktop.

Select an option

Save alissa-maria/e7b638d82af3fb6bf20ab9b94e608d82 to your computer and use it in GitHub Desktop.
Script to start/stop/restart known applications as daemons
#!/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