Skip to content

Instantly share code, notes, and snippets.

@kolosseo
Last active June 28, 2021 18:11
Show Gist options
  • Save kolosseo/a5407f2259f620bf5a35910b23e35170 to your computer and use it in GitHub Desktop.
Save kolosseo/a5407f2259f620bf5a35910b23e35170 to your computer and use it in GitHub Desktop.
Light script to manage LAMP stack super easily
#!/bin/bash
# ------------------------------
# gio 2 nov 2017, 20.11.52, CET
# ------------------------------
# author: jacopo pace
# ------------------------------
# desc:
# small script to start/stop/check web services (LAMP)
# ------------------------------
aflag=1 # all services
toggle=restart
sudo="sudo "
getHelp() {
cat <<EOF
lamp [options]
[-o, --off] stop service[s] (default is "(re)start")
[-s, --status] print service[s] status
[-d, --db] manage only database service
[-w, --web] manage only web-server service
[-h, --help] print help
EXAMPLES
start (or restart) all LAMP services:
lamp
stop all LAMP services:
lamp -o
start (or restart) only database server:
lamp -d
stop only web server:
lamp -o -w
same thing:
lamp -w -o
lamp --web --off
check services status:
lamp -s
check db service status:
lamp -s -d
EOF
exit 0
}
toggle() {
echo "${sudo}systemctl -l $toggle $1"
${sudo}systemctl -l $toggle $1
}
while [ $# -gt 0 ]; do
case $1 in
-d|--db) unset aflag; dflag=1;;
-w|--web) unset aflag; wflag=1;;
-o|--off) toggle=stop;;
-s|--status) toggle="status --no-pager"; sudo="";;
-h|--help) getHelp;;
(--) shift; break;;
(-*) echo "$0: error - unrecognized option \"$1\"" 1>&2; exit 1;;
(*) break;;
esac
shift
done
([ -n "$aflag" ] || [ -n "$wflag" ]) && toggle httpd.service
([ -n "$aflag" ] || [ -n "$dflag" ]) && toggle mariadb.service
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment