-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvboxautostart.init
executable file
·115 lines (93 loc) · 2.25 KB
/
vboxautostart.init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh
#
# VirtualBox autostart service init script.
#
# chkconfig: 35 35 65
# description: VirtualBox autostart service
# processname: VBoxAutostart
# config: /etc/vbox/autostart.cfg
#
# Source function library
. /etc/rc.d/init.d/functions
VBOXAUTOSTART_DB=/etc/vbox/autostart
VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg
VBOXAUTOSTART=@INSTALL_DIR@/VBoxAutostart
# Get service config - may override defaults
[ -f /etc/sysconfig/virtualbox ] && . /etc/sysconfig/virtualbox
start_daemon() {
local user="$1"
shift
show "VMs for user '%s'" "$user"
daemon --user $user "$@"
}
start() {
# Check if the service is already running?
if [ -f /var/lock/subsys/vboxautostart ]; then
msg_already_running "VirtualBox Autostart"
return
fi
[ -z "$VBOXAUTOSTART_DB" ] && exit 0
[ -z "$VBOXAUTOSTART_CONFIG" ] && exit 0
msg_starting "VirtualBox VMs configured for autostart"; busy; echo
local file user PARAMS="--background --start --config $VBOXAUTOSTART_CONFIG"
# prevent inheriting this setting to VBoxSVC
unset VBOX_RELEASE_LOG_DEST
for file in $VBOXAUTOSTART_DB/*.start; do
test -f "$file" || continue
user=${file##*/}; user=${user%.start}
start_daemon $user $VBOXAUTOSTART $PARAMS
done
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/vboxautostart
}
stop() {
if [ ! -f /var/lock/subsys/vboxautostart ]; then
msg_not_running "VirtualBox Autostart"
return
fi
[ -z "$VBOXAUTOSTART_DB" ] && exit 0
[ -z "$VBOXAUTOSTART_CONFIG" ] && exit 0
# Stop daemons.
msg_stopping "VirtualBox Autostart"; busy; echo
local file user PARAMS="--stop --config $VBOXAUTOSTART_CONFIG"
# prevent inheriting this setting to VBoxSVC
unset VBOX_RELEASE_LOG_DEST
for file in $VBOXAUTOSTART_DB/*.stop; do
test -f "$file" || continue
user=${file##*/}; user=${user%.stop}
start_daemon $user $VBOXAUTOSTART $PARAMS
done
rm -f /var/lock/subsys/vboxautostart
}
condrestart() {
if [ ! -f /var/lock/subsys/vboxautostart ]; then
msg_not_running "VirtualBox Autostart"
RETVAL=$1
return
fi
stop
start
}
RETVAL=0
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
try-restart)
condrestart 0
;;
force-reload)
condrestart 7
;;
*)
msg_usage "$0 {start|stop|restart|try-restart|force-reload}"
exit 3
esac
exit $RETVAL