handle-server.sh-e-e 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. # Arch Linux and Debian has different names for Apache service.
  3. # Some people may like Mysql over Mariadb, which has different service
  4. # names.
  5. # This script detects which service is available and starts or stops it.
  6. # So it basically lets you start or stop the server in one command.
  7. # This is great for maintaining one piece of code that can be used on
  8. # different distros.
  9. # To use it, place the code below on your ~/.bashrc or if you have it,
  10. # on your ~/.bash_aliases, then run:
  11. # source ~/.bashrc or source ~/.bash_aliases
  12. # then use `start-server` or `stop-server` as you need.
  13. handleServer() {
  14. services=$(sudo systemctl list-unit-files)
  15. if echo $services | grep -q apache2; then
  16. sudo systemctl ${1} apache2
  17. fi
  18. if echo $services | grep -q httpd; then
  19. sudo systemctl ${1} httpd
  20. fi
  21. if echo $services | grep -q mariadb; then
  22. sudo systemctl ${1} mariadb
  23. fi
  24. if echo $services | grep -q mysql; then
  25. sudo systemctl ${1} mysql
  26. fi
  27. }
  28. alias start-server='handleServer start'
  29. alias stop-server='handleServer stop'
  30. alias restart-server='handleServer restart'