rc.merecat 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh
  2. #
  3. # Start/stop/restart Merecat.
  4. #
  5. # Copyright (C) 2023 Ricardo García Jiménez <ricardogj08@riseup.net>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. #
  20. merecat_start() {
  21. if [ -r /var/run/merecat.pid ]; then
  22. echo "Merecat is already running: $(cat /var/run/merecat.pid)"
  23. exit 1
  24. fi
  25. if [ -x /usr/sbin/merecat ]; then
  26. /usr/sbin/merecat -f /etc/merecat.conf -I merecat -l err -P /var/run/merecat.pid -n -s /var/merecat/www & > /dev/null
  27. echo "Starting Merecat: /usr/sbin/merecat -f /etc/merecat.conf -I merecat -l err -P /var/run/merecat.pid -n -s /var/merecat/www & > /dev/null"
  28. fi
  29. }
  30. merecat_error() {
  31. echo "Merecat does not seem to be running"
  32. exit 1
  33. }
  34. merecat_stop() {
  35. if [ -r /var/run/merecat.pid ]; then
  36. kill "$(cat /var/run/merecat.pid)"
  37. rm -f /var/run/merecat.pid
  38. else
  39. merecat_error
  40. fi
  41. }
  42. merecat_restart() {
  43. merecat_stop
  44. merecat_start
  45. }
  46. merecat_status() {
  47. if [ -r /var/run/merecat.pid ]; then
  48. echo "Merecat is running: $(cat /var/run/merecat.pid)"
  49. else
  50. merecat_error
  51. fi
  52. }
  53. case "$1" in
  54. 'start')
  55. merecat_start
  56. ;;
  57. 'status')
  58. merecat_status
  59. ;;
  60. 'stop')
  61. merecat_stop
  62. ;;
  63. 'restart')
  64. merecat_restart
  65. ;;
  66. *)
  67. echo "usage $0 start|stop|restart|status"
  68. esac