1 | #!/bin/sh
|
---|
2 | # $Id: vboxadd-service.sh 98103 2023-01-17 14:15:46Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # Linux Additions Guest Additions service daemon init script.
|
---|
5 | #
|
---|
6 |
|
---|
7 | #
|
---|
8 | # Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
9 | #
|
---|
10 | # This file is part of VirtualBox base platform packages, as
|
---|
11 | # available from https://www.virtualbox.org.
|
---|
12 | #
|
---|
13 | # This program is free software; you can redistribute it and/or
|
---|
14 | # modify it under the terms of the GNU General Public License
|
---|
15 | # as published by the Free Software Foundation, in version 3 of the
|
---|
16 | # License.
|
---|
17 | #
|
---|
18 | # This program is distributed in the hope that it will be useful, but
|
---|
19 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | # General Public License for more details.
|
---|
22 | #
|
---|
23 | # You should have received a copy of the GNU General Public License
|
---|
24 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 | #
|
---|
26 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
27 | #
|
---|
28 |
|
---|
29 | # X-Conflicts-With is our own invention, which we use when converting to
|
---|
30 | # a systemd unit.
|
---|
31 |
|
---|
32 | # chkconfig: 345 35 65
|
---|
33 | # description: VirtualBox Additions service
|
---|
34 | #
|
---|
35 | ### BEGIN INIT INFO
|
---|
36 | # Provides: vboxadd-service
|
---|
37 | # Required-Start: vboxadd
|
---|
38 | # Required-Stop: vboxadd
|
---|
39 | # Default-Start: 2 3 4 5
|
---|
40 | # Default-Stop: 0 1 6
|
---|
41 | # X-Conflicts-With: systemd-timesyncd.service
|
---|
42 | # Description: VirtualBox Additions Service
|
---|
43 | ### END INIT INFO
|
---|
44 |
|
---|
45 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
46 | SCRIPTNAME=vboxadd-service.sh
|
---|
47 |
|
---|
48 | PIDFILE="/var/run/${SCRIPTNAME}"
|
---|
49 |
|
---|
50 | # Preamble for Gentoo
|
---|
51 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
52 | shift
|
---|
53 | fi
|
---|
54 |
|
---|
55 | begin()
|
---|
56 | {
|
---|
57 | test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
|
---|
58 | logger -t "${SCRIPTNAME}" "${1}."
|
---|
59 | }
|
---|
60 |
|
---|
61 | succ_msg()
|
---|
62 | {
|
---|
63 | logger -t "${SCRIPTNAME}" "${1}."
|
---|
64 | }
|
---|
65 |
|
---|
66 | fail_msg()
|
---|
67 | {
|
---|
68 | echo "${SCRIPTNAME}: ${1}." >&2
|
---|
69 | logger -t "${SCRIPTNAME}" "${1}."
|
---|
70 | }
|
---|
71 |
|
---|
72 | daemon() {
|
---|
73 | $1 $2 $3
|
---|
74 | }
|
---|
75 |
|
---|
76 | killproc() {
|
---|
77 | killall $1
|
---|
78 | rm -f $PIDFILE
|
---|
79 | }
|
---|
80 |
|
---|
81 | if which start-stop-daemon >/dev/null 2>&1; then
|
---|
82 | daemon() {
|
---|
83 | start-stop-daemon --start --exec $1 -- $2 $3
|
---|
84 | }
|
---|
85 |
|
---|
86 | killproc() {
|
---|
87 | start-stop-daemon --stop --retry 2 --exec $@
|
---|
88 | }
|
---|
89 | fi
|
---|
90 |
|
---|
91 | binary=/usr/sbin/VBoxService
|
---|
92 |
|
---|
93 | testbinary() {
|
---|
94 | test -x "$binary" || {
|
---|
95 | echo "Cannot run $binary"
|
---|
96 | exit 1
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | vboxaddrunning() {
|
---|
101 | lsmod | grep -q "vboxguest[^_-]"
|
---|
102 | }
|
---|
103 |
|
---|
104 | start() {
|
---|
105 | if ! test -f $PIDFILE; then
|
---|
106 | begin "Starting VirtualBox Guest Addition service" console;
|
---|
107 | vboxaddrunning || {
|
---|
108 | echo "VirtualBox Additions module not loaded!"
|
---|
109 | exit 1
|
---|
110 | }
|
---|
111 | testbinary
|
---|
112 | daemon $binary --pidfile $PIDFILE > /dev/null
|
---|
113 | RETVAL=$?
|
---|
114 | succ_msg "VirtualBox Guest Addition service started"
|
---|
115 | fi
|
---|
116 | return $RETVAL
|
---|
117 | }
|
---|
118 |
|
---|
119 | stop() {
|
---|
120 | if test -f $PIDFILE; then
|
---|
121 | begin "Stopping VirtualBox Guest Addition service" console;
|
---|
122 | killproc $binary
|
---|
123 | RETVAL=$?
|
---|
124 | if ! pidof VBoxService > /dev/null 2>&1; then
|
---|
125 | rm -f $PIDFILE
|
---|
126 | succ_msg "VirtualBox Guest Addition service stopped"
|
---|
127 | else
|
---|
128 | fail_msg "VirtualBox Guest Addition service failed to stop"
|
---|
129 | fi
|
---|
130 | fi
|
---|
131 | return $RETVAL
|
---|
132 | }
|
---|
133 |
|
---|
134 | restart() {
|
---|
135 | stop && start
|
---|
136 | }
|
---|
137 |
|
---|
138 | status() {
|
---|
139 | echo -n "Checking for VBoxService"
|
---|
140 | if [ -f $PIDFILE ]; then
|
---|
141 | echo " ...running"
|
---|
142 | else
|
---|
143 | echo " ...not running"
|
---|
144 | fi
|
---|
145 | }
|
---|
146 |
|
---|
147 | case "$1" in
|
---|
148 | start)
|
---|
149 | start
|
---|
150 | ;;
|
---|
151 | stop)
|
---|
152 | stop
|
---|
153 | ;;
|
---|
154 | restart)
|
---|
155 | restart
|
---|
156 | ;;
|
---|
157 | status)
|
---|
158 | status
|
---|
159 | ;;
|
---|
160 | setup)
|
---|
161 | ;;
|
---|
162 | cleanup)
|
---|
163 | ;;
|
---|
164 | *)
|
---|
165 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
166 | exit 1
|
---|
167 | esac
|
---|
168 |
|
---|
169 | exit $RETVAL
|
---|