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