gogs-init.j2 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #! /bin/bash
  2. # /etc/init.d/gogs
  3. #
  4. ### BEGIN INIT INFO
  5. # Provides: gogs
  6. # Required-Start: $remote_fs $syslog
  7. # Required-Stop: $remote_fs $syslog
  8. # Default-Start: 2 3 4 5
  9. # Default-Stop: 0 1 6
  10. # Short-Description: Start gogs at boot time.
  11. # Description: Control gogs.
  12. ### END INIT INFO
  13. start_gogs() {
  14. nohup {{ gogs_user_home }}/gogs/start.sh > {{ gogs_user_home }}/gogs/log/gogs.log 2>&1&
  15. }
  16. # Gogs needs a home path.
  17. export HOME={{ gogs_user_home }}
  18. # Carry out specific functions when asked to by the system
  19. case "$1" in
  20. start)
  21. ps aux | grep 'gogs' | grep -v grep | grep -vq start
  22. if [ $? = 0 ]; then
  23. echo "Gogs is already running."
  24. else
  25. start_gogs
  26. fi
  27. ;;
  28. stop)
  29. ps aux | grep 'gogs' | grep -v grep | grep -vq stop
  30. if [ $? = 0 ]; then
  31. echo "Stopping Gogs."
  32. kill `ps -ef | grep 'gogs' | grep -v grep | awk '{print $2}'`
  33. else
  34. echo "Gogs is already stopped."
  35. fi
  36. ;;
  37. restart)
  38. ps aux | grep 'gogs' | grep -v grep | grep -vq restart
  39. if [ $? = 0 ]; then
  40. kill `ps -ef | grep 'gogs' | grep -v grep | awk '{print $2}'`
  41. fi
  42. start_gogs
  43. ;;
  44. status)
  45. ps aux | grep 'gogs' | grep -v grep | grep -vq status
  46. if [ $? = 0 ]; then
  47. echo "Gogs is running."
  48. else
  49. echo "Gogs is stopped."
  50. fi
  51. ;;
  52. *)
  53. echo "Usage: /etc/init.d/gogs {start|stop|restart|status}"
  54. exit 1
  55. ;;
  56. esac
  57. exit 0