1234567891011121314151617181920212223242526272829303132 |
- #!/usr/bin/env bash
- # Arch Linux and Debian has different names for Apache service.
- # Some people may like Mysql over Mariadb, which has different service
- # names.
- # This script detects which service is available and starts or stops it.
- # So it basically lets you start or stop the server in one command.
- # This is great for maintaining one piece of code that can be used on
- # different distros.
- # To use it, place the code below on your ~/.bashrc or if you have it,
- # on your ~/.bash_aliases, then run:
- # source ~/.bashrc or source ~/.bash_aliases
- # then use `start-server` or `stop-server` as you need.
- handleServer() {
- services=$(sudo systemctl list-unit-files)
- if echo $services | grep -q apache2; then
- sudo systemctl ${1} apache2
- fi
- if echo $services | grep -q httpd; then
- sudo systemctl ${1} httpd
- fi
- if echo $services | grep -q mariadb; then
- sudo systemctl ${1} mariadb
- fi
- if echo $services | grep -q mysql; then
- sudo systemctl ${1} mysql
- fi
- }
- alias start-server='handleServer start'
- alias stop-server='handleServer stop'
- alias restart-server='handleServer restart'
|