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