Advertisement
IchHabRecht

[BASH] CentOS service script for Redmine

Jan 9th, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.42 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # redmine          Start/Stop the redmine webrick daemon.
  4. #
  5. # chkconfig: 2345 90 60
  6. # description: Redmine is a flexible project management web application \
  7. #              written using Ruby on Rails framework.
  8.  
  9. ### BEGIN INIT INFO
  10. # Provides: redmine
  11. # Required-Start: $local_fs $syslog
  12. # Required-Stop: $local_fs $syslog
  13. # Default-Start:  2345
  14. # Default-Stop: 90
  15. # Short-Description: run redmine daemon
  16. # Description: Redmine is a flexible project management web application \
  17. #              written using Ruby on Rails framework.
  18. ### END INIT INFO
  19.  
  20. [ -f /var/www/vhosts/redmine/script/rails ] || {
  21.     [ "$1" = "status" ] && exit 4 || exit 6
  22. }
  23.  
  24. RETVAL=0
  25. prog="redmine"
  26. exec=/usr/local/bin/ruby
  27. exec_args="/var/www/vhosts/redmine/script/rails server webrick -e production -d"
  28. pid_file=/var/www/vhosts/redmine/tmp/pids/server.pid
  29.  
  30. # Source function library.
  31. . /etc/rc.d/init.d/functions
  32.  
  33. [ $UID -eq 0 ] && [ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
  34.  
  35. start() {
  36.     if [ $UID -ne 0 ] ; then
  37.         echo "User has insufficient privilege."
  38.         exit 4
  39.     fi
  40.     [ -x $exec ] || exit 5
  41.     echo -n $"Starting $prog: "
  42.     daemon --pidfile $pid_file $exec $exec_args
  43.     retval=$?
  44.     echo
  45. }
  46.  
  47. stop() {
  48.     if [ $UID -ne 0 ] ; then
  49.         echo "User has insufficient privilege."
  50.         exit 4
  51.     fi
  52.     echo -n $"Stopping $prog: "
  53.     pid=$(cat $pid_file)
  54.     if [ -n "$pid" ]; then
  55.         killproc -p $pid_file $pid
  56.         RETVAL=3
  57.     else
  58.         failure $"Stopping $prog"
  59.     fi
  60.     retval=$?
  61.     echo
  62. }
  63.  
  64. restart() {
  65.     rh_status_q && stop
  66.     start
  67. }
  68.  
  69. reload() {
  70.     restart
  71. }
  72.  
  73. force_reload() {
  74.     restart
  75. }
  76.  
  77. rh_status() {
  78.     # run checks to determine if the service is running or use generic status
  79.     status -p $pid_file $prog
  80. }
  81.  
  82. rh_status_q() {
  83.     rh_status >/dev/null 2>&1
  84. }
  85.  
  86. case "$1" in
  87.     start)
  88.         rh_status_q && exit 0
  89.         $1
  90.         ;;
  91.     stop)
  92.         rh_status_q || exit 0
  93.         $1
  94.         ;;
  95.     restart)
  96.         $1
  97.         ;;
  98.     reload)
  99.         rh_status_q || exit 7
  100.         $1
  101.         ;;
  102.     force-reload)
  103.         force_reload
  104.         ;;
  105.     status)
  106.         rh_status
  107.         ;;
  108.     condrestart|try-restart)
  109.         rh_status_q || exit 0
  110.         restart
  111.         ;;
  112.     *)
  113.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
  114.         exit 2
  115. esac
  116. exit $?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement