VirtualBox

Ticket #14733: vboxadd-service.2.sh

File vboxadd-service.2.sh, 2.8 KB (added by Michael Thayer, 9 years ago)

Next test version

Line 
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
28PATH=$PATH:/bin:/sbin:/usr/sbin
29SCRIPTNAME=vboxadd-service.sh
30
31PIDFILE="/var/run/${SCRIPTNAME}"
32
33# Preamble for Gentoo
34if [ "`which $0`" = "/sbin/rc" ]; then
35 shift
36fi
37
38begin()
39{
40 test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
41 logger -t "${SCRIPTNAME}" "${1}."
42}
43
44succ_msg()
45{
46 logger -t "${SCRIPTNAME}" "${1}."
47}
48
49fail_msg()
50{
51 echo "${SCRIPTNAME}: ${1}." >&2
52 logger -t "${SCRIPTNAME}" "${1}."
53}
54
55daemon() {
56 $1 $2 $3
57}
58
59killproc() {
60 lo_binary=`basename "${1}"`
61 pkill "${lo_binary}" || return
62 sleep 1
63 pkill "${lo_binary}" || return
64 sleep 1
65 pkill -9 "${lo_binary}"
66}
67
68if which start-stop-daemon >/dev/null 2>&1; then
69 daemon() {
70 start-stop-daemon --start --exec $1 -- $2 $3
71 }
72
73 killproc() {
74 start-stop-daemon --stop --retry 2 --exec $@
75 }
76fi
77
78binary=/usr/sbin/VBoxService
79
80testbinary() {
81 test -x "$binary" || {
82 echo "Cannot run $binary"
83 exit 1
84 }
85}
86
87vboxaddrunning() {
88 lsmod | grep -q "vboxguest[^_-]"
89}
90
91start() {
92 if ! test -f $PIDFILE; then
93 begin "Starting VirtualBox Guest Addition service" console;
94 vboxaddrunning || {
95 echo "VirtualBox Additions module not loaded!"
96 exit 1
97 }
98 testbinary
99 daemon $binary --pidfile $PIDFILE > /dev/null
100 RETVAL=$?
101 succ_msg "VirtualBox Guest Addition service started"
102 fi
103 return $RETVAL
104}
105
106stop() {
107 if test -f $PIDFILE; then
108 begin "Stopping VirtualBox Guest Addition service" console;
109 killproc $binary
110 fi
111}
112
113restart() {
114 stop && start
115}
116
117status() {
118 echo -n "Checking for VBoxService"
119 if [ -f $PIDFILE ]; then
120 echo " ...running"
121 else
122 echo " ...not running"
123 fi
124}
125
126case "$1" in
127start)
128 start
129 ;;
130stop)
131 stop
132 ;;
133restart)
134 restart
135 ;;
136status)
137 status
138 ;;
139setup)
140 ;;
141cleanup)
142 ;;
143*)
144 echo "Usage: $0 {start|stop|restart|status}"
145 exit 1
146esac
147
148exit $RETVAL

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy