starfry

rc.d script to launch rvm gemdocs

Mar 8th, 2012
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.77 KB | None | 0 0
  1. --file /etc/rc.d/rvm
  2. #!/bin/bash
  3. #
  4. # rc.d init script for rvm environment. It does the following:
  5. #      1: starts GemDocs for each gemset listed in $GEMSETS
  6. #
  7.  
  8. # Run as user "rvm"
  9. RUNUSER="rvm"
  10. [ "$USER" = "root" ] && { su ${RUNUSER} -c "$0 $*"; exit; }
  11. [ "$USER" = "${RUNUSER}" ] || { echo "$0 must run as ${RUNUSER}"; exit; }
  12.  
  13. . /etc/profile # Needed to set up rvm environment
  14.  
  15. . /etc/rc.conf
  16. . /etc/rc.d/functions
  17.  
  18. [ -r /etc/conf.d/rvm ] && . /etc/conf.d/rvm
  19.  
  20. GEMSETS=${GEMSETS:-system}
  21. GEMDOCS_PORT=8808
  22.  
  23. for GEMSET in ${GEMSETS[@]}
  24. do
  25.         GEMDOCS_CMD="gem server --daemon --port $GEMDOCS_PORT"
  26.  
  27.         # Get PID if a process exists with that command line
  28.         PID=$(ps -e -o pid= -o cmd= | grep "$GEMDOCS_CMD" | grep -v grep | awk '{print $1}')
  29.  
  30.         case "$1" in
  31.          start)
  32.            stat_busy "Starting GemDocs for ${GEMSET}"
  33.            [ -z "$PID" ] && rvm use ${GEMSET} > /dev/null && $GEMDOCS_CMD > /dev/null
  34.            if [ $? = 0 ]; then
  35.              stat_done
  36.            else
  37.              stat_fail
  38.              exit 1
  39.            fi
  40.            ;;
  41.          stop)
  42.            stat_busy "Stopping GemDocs for ${GEMSET}"
  43.            [ -n "$PID" ] && kill $PID &>/dev/null
  44.            if [ $? = 0 ]; then
  45.              stat_done
  46.            else
  47.              stat_fail
  48.              exit 1
  49.            fi
  50.            ;;
  51.          restart)
  52.            $0 stop
  53.            sleep 1
  54.            $0 start
  55.            ;;
  56.          *)
  57.            echo "usage: $0 {start|stop|restart}"  
  58.            exit
  59.         esac
  60.            
  61.         let GEMDOCS_PORT+=1
  62.        
  63. done
  64. --file /etc/conf.d/rvm#
  65. #
  66. # Arguments to be passed to the rvm daemons
  67.  
  68. # Run GemDocs for these gemsets
  69. GEMSETS=(system ruby-1.8.6-p420@rails-2.0.2 ruby-1.9.3-p0@rails)
Advertisement
Add Comment
Please, Sign In to add comment