| 1 | #!/bin/sh
|
|---|
| 2 | #
|
|---|
| 3 | # Linux Additions Guest Additions service daemon init script.
|
|---|
| 4 | #
|
|---|
| 5 | # Copyright (C) 2006-2012 Oracle Corporation
|
|---|
| 6 | #
|
|---|
| 7 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
|---|
| 8 | # available from http://www.virtualbox.org. This file is free software;
|
|---|
| 9 | # you can redistribute it and/or modify it under the terms of the GNU
|
|---|
| 10 | # General Public License (GPL) as published by the Free Software
|
|---|
| 11 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
|---|
| 12 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
|---|
| 13 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
|---|
| 14 | #
|
|---|
| 15 |
|
|---|
| 16 | # chkconfig: 345 35 65
|
|---|
| 17 | # description: VirtualBox Additions service
|
|---|
| 18 | #
|
|---|
| 19 | ### BEGIN INIT INFO
|
|---|
| 20 | # Provides: vboxadd-service
|
|---|
| 21 | # Required-Start: vboxadd
|
|---|
| 22 | # Required-Stop: vboxadd
|
|---|
| 23 | # Default-Start: 2 3 4 5
|
|---|
| 24 | # Default-Stop: 0 1 6
|
|---|
| 25 | # Description: VirtualBox Additions Service
|
|---|
| 26 | ### END INIT INFO
|
|---|
| 27 |
|
|---|
| 28 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
|---|
| 29 | SCRIPTNAME=vboxadd-service.sh
|
|---|
| 30 |
|
|---|
| 31 | PIDFILE="/var/run/${SCRIPTNAME}"
|
|---|
| 32 |
|
|---|
| 33 | # Preamble for Gentoo
|
|---|
| 34 | if [ "`which $0`" = "/sbin/rc" ]; then
|
|---|
| 35 | shift
|
|---|
| 36 | fi
|
|---|
| 37 |
|
|---|
| 38 | begin()
|
|---|
| 39 | {
|
|---|
| 40 | test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
|
|---|
| 41 | logger -t "${SCRIPTNAME}" "${1}."
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | succ_msg()
|
|---|
| 45 | {
|
|---|
| 46 | logger -t "${SCRIPTNAME}" "${1}."
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
| 49 | fail_msg()
|
|---|
| 50 | {
|
|---|
| 51 | echo "${SCRIPTNAME}: ${1}." >&2
|
|---|
| 52 | logger -t "${SCRIPTNAME}" "${1}."
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | daemon() {
|
|---|
| 56 | $1 $2 $3
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | killproc() {
|
|---|
| 60 | pkill "${1}" || return
|
|---|
| 61 | sleep 1
|
|---|
| 62 | pkill "${1}" || return
|
|---|
| 63 | sleep 1
|
|---|
| 64 | pkill -9 "${1}"
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | if which start-stop-daemon >/dev/null 2>&1; then
|
|---|
| 68 | daemon() {
|
|---|
| 69 | start-stop-daemon --start --exec $1 -- $2 $3
|
|---|
| 70 | }
|
|---|
| 71 |
|
|---|
| 72 | killproc() {
|
|---|
| 73 | start-stop-daemon --stop --retry 2 --exec $@
|
|---|
| 74 | }
|
|---|
| 75 | fi
|
|---|
| 76 |
|
|---|
| 77 | binary=/usr/sbin/VBoxService
|
|---|
| 78 |
|
|---|
| 79 | testbinary() {
|
|---|
| 80 | test -x "$binary" || {
|
|---|
| 81 | echo "Cannot run $binary"
|
|---|
| 82 | exit 1
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | vboxaddrunning() {
|
|---|
| 87 | lsmod | grep -q "vboxguest[^_-]"
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | start() {
|
|---|
| 91 | if ! test -f $PIDFILE; then
|
|---|
| 92 | begin "Starting VirtualBox Guest Addition service" console;
|
|---|
| 93 | vboxaddrunning || {
|
|---|
| 94 | echo "VirtualBox Additions module not loaded!"
|
|---|
| 95 | exit 1
|
|---|
| 96 | }
|
|---|
| 97 | testbinary
|
|---|
| 98 | daemon $binary --pidfile $PIDFILE > /dev/null
|
|---|
| 99 | RETVAL=$?
|
|---|
| 100 | succ_msg "VirtualBox Guest Addition service started"
|
|---|
| 101 | fi
|
|---|
| 102 | return $RETVAL
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | stop() {
|
|---|
| 106 | if test -f $PIDFILE; then
|
|---|
| 107 | begin "Stopping VirtualBox Guest Addition service" console;
|
|---|
| 108 | killproc $binary
|
|---|
| 109 | fi
|
|---|
| 110 | }
|
|---|
| 111 |
|
|---|
| 112 | restart() {
|
|---|
| 113 | stop && start
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | status() {
|
|---|
| 117 | echo -n "Checking for VBoxService"
|
|---|
| 118 | if [ -f $PIDFILE ]; then
|
|---|
| 119 | echo " ...running"
|
|---|
| 120 | else
|
|---|
| 121 | echo " ...not running"
|
|---|
| 122 | fi
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | case "$1" in
|
|---|
| 126 | start)
|
|---|
| 127 | start
|
|---|
| 128 | ;;
|
|---|
| 129 | stop)
|
|---|
| 130 | stop
|
|---|
| 131 | ;;
|
|---|
| 132 | restart)
|
|---|
| 133 | restart
|
|---|
| 134 | ;;
|
|---|
| 135 | status)
|
|---|
| 136 | status
|
|---|
| 137 | ;;
|
|---|
| 138 | setup)
|
|---|
| 139 | ;;
|
|---|
| 140 | cleanup)
|
|---|
| 141 | ;;
|
|---|
| 142 | *)
|
|---|
| 143 | echo "Usage: $0 {start|stop|restart|status}"
|
|---|
| 144 | exit 1
|
|---|
| 145 | esac
|
|---|
| 146 |
|
|---|
| 147 | exit $RETVAL
|
|---|