| 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_msg()
|
|---|
| 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}: failed: ${1}." >&2
|
|---|
| 52 | logger -t "${SCRIPTNAME}" "failed: ${1}."
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | killproc() {
|
|---|
| 56 | kp_binary="${1##*/}"
|
|---|
| 57 | pkill "${kp_binary}" || return 0
|
|---|
| 58 | sleep 1
|
|---|
| 59 | pkill "${kp_binary}" || return 0
|
|---|
| 60 | sleep 1
|
|---|
| 61 | pkill -9 "${kp_binary}"
|
|---|
| 62 | return 0
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | binary=/usr/sbin/VBoxService
|
|---|
| 66 |
|
|---|
| 67 | testbinary() {
|
|---|
| 68 | test -x "$binary" || {
|
|---|
| 69 | echo "Cannot run $binary"
|
|---|
| 70 | exit 1
|
|---|
| 71 | }
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | vboxaddrunning() {
|
|---|
| 75 | lsmod | grep -q "vboxguest[^_-]"
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | start() {
|
|---|
| 79 | if ! test -f $PIDFILE; then
|
|---|
| 80 | begin_msg "Starting VirtualBox Guest Addition service" console;
|
|---|
| 81 | vboxaddrunning || {
|
|---|
| 82 | echo "VirtualBox Additions module not loaded!"
|
|---|
| 83 | exit 1
|
|---|
| 84 | }
|
|---|
| 85 | testbinary
|
|---|
| 86 | $binary --pidfile $PIDFILE > /dev/null || \
|
|---|
| 87 | { fail_msg "VirtualBox Guest Addition service failed to start"; return 1; }
|
|---|
| 88 | # Otherwise assume a successful return means success.
|
|---|
| 89 | succ_msg "VirtualBox Guest Addition service started"
|
|---|
| 90 | fi
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | stop() {
|
|---|
| 94 | if test -f $PIDFILE; then
|
|---|
| 95 | begin_msg "Stopping VirtualBox Guest Addition service" console;
|
|---|
| 96 | killproc $binary
|
|---|
| 97 | fi
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | restart() {
|
|---|
| 101 | stop && start
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | status() {
|
|---|
| 105 | echo -n "Checking for VBoxService"
|
|---|
| 106 | if [ -f $PIDFILE ]; then
|
|---|
| 107 | echo " ...running"
|
|---|
| 108 | else
|
|---|
| 109 | echo " ...not running"
|
|---|
| 110 | fi
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | case "$1" in
|
|---|
| 114 | start)
|
|---|
| 115 | start
|
|---|
| 116 | ;;
|
|---|
| 117 | stop)
|
|---|
| 118 | stop
|
|---|
| 119 | ;;
|
|---|
| 120 | restart)
|
|---|
| 121 | restart
|
|---|
| 122 | ;;
|
|---|
| 123 | status)
|
|---|
| 124 | status
|
|---|
| 125 | ;;
|
|---|
| 126 | setup)
|
|---|
| 127 | ;;
|
|---|
| 128 | cleanup)
|
|---|
| 129 | ;;
|
|---|
| 130 | *)
|
|---|
| 131 | echo "Usage: $0 {start|stop|restart|status}"
|
|---|
| 132 | exit 1
|
|---|
| 133 | esac
|
|---|
| 134 |
|
|---|
| 135 | exit $RETVAL
|
|---|