SHARE
TWEET

Untitled

a guest Dec 16th, 2010 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #! /bin/sh
  2.  
  3. # PATH should only include /usr/* if it runs after the mountnfs.sh script
  4. PATH=/usr/sbin:/usr/bin:/sbin:/bin
  5. DESC="VirtualBox Web Service"
  6. NAME=vm-manage
  7. SCRIPTNAME=/etc/init.d/$NAME
  8. USER=vm-user
  9.  
  10. # Read configuration variable file if it is present
  11. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  12.  
  13. # Load the VERBOSE setting and other rcS variables
  14. [ -f /etc/default/rcS ] && . /etc/default/rcS
  15.  
  16. # Define LSB log_* functions.
  17. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  18. . /lib/lsb/init-functions
  19.  
  20. VBPID=`ps -U ${USER} --no-heading -o pid,cmd | grep vboxwebsrv | grep -v ${SCRIPTNAME} | grep -v grep | tail -1 | awk '{ print $1 }'`
  21.  
  22. # | tail -1 | awk '{ print $1 }'`
  23.  
  24. # Function that starts the daemon/service
  25. #
  26. do_start()
  27. {
  28.    if [ "$VBPID" != "" ] && [ "$VBPID" -gt 0 ]; then
  29.       echo $NAME already running with PID $VBPID
  30.    else
  31.       su ${USER} -c 'vboxwebsrv -b --logfile /dev/null >/dev/null'
  32.    fi
  33. }
  34.  
  35.  
  36. #
  37. # Function that stops the daemon/service
  38. #
  39. do_stop()
  40. {
  41.  
  42.    if [ "$VBPID" != "" ] && [ "$VBPID" -gt 0 ]; then
  43.         echo Stopping $NAME ...
  44.         kill $VBPID
  45.    else
  46.         echo $NAME not running
  47.    fi
  48.  
  49. }
  50.  
  51. #
  52. # Display "State" field from showinfo action
  53. #
  54. do_status()
  55. {
  56.    if [ "$VBPID" != "" ] && [ "$VBPID" -gt 0 ]; then
  57.         echo Running with pid $VBPID
  58.    else
  59.         echo $NAME not running
  60.    fi
  61. }
  62.  
  63.  
  64.  
  65.  
  66. case "$1" in
  67.   start)
  68.     [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  69.     do_start
  70.     case "$?" in
  71.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  72.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  73.     esac
  74.     ;;
  75.   stop)
  76.     [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  77.     do_stop
  78.     case "$?" in
  79.         0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  80.         2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  81.     esac
  82.     ;;
  83.   restart|force-reload)
  84.     #
  85.     # If the "reload" option is implemented then remove the
  86.     # 'force-reload' alias
  87.     #
  88.     log_daemon_msg "Restarting $DESC" "$NAME"
  89.     do_stop
  90.     case "$?" in
  91.       0|1)
  92.         do_start
  93.         case "$?" in
  94.             0) log_end_msg 0 ;;
  95.             1) log_end_msg 1 ;; # Old process is still running
  96.             *) log_end_msg 1 ;; # Failed to start
  97.         esac
  98.         ;;
  99.       *)
  100.           # Failed to stop
  101.         log_end_msg 1
  102.         ;;
  103.     esac
  104.     ;;
  105.   status)
  106.     do_status
  107.     ;;
  108.   *)
  109.     echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
  110.     exit 3
  111.     ;;
  112. esac
  113.  
  114. :
RAW Paste Data
Top