VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/vboxautostart-service.sh@ 78218

Last change on this file since 78218 was 76553, checked in by vboxsync, 6 years ago

scm --update-copyright-year

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1#!/bin/sh
2# $Id: vboxautostart-service.sh 76553 2019-01-01 01:45:53Z vboxsync $
3## @file
4# VirtualBox autostart service init script.
5#
6
7#
8# Copyright (C) 2012-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# chkconfig: 345 35 65
20# description: VirtualBox autostart service
21#
22### BEGIN INIT INFO
23# Provides: vboxautostart-service
24# Required-Start: vboxdrv
25# Required-Stop: vboxdrv
26# Default-Start: 2 3 4 5
27# Default-Stop: 0 1 6
28# Description: VirtualBox autostart service
29### END INIT INFO
30
31PATH=$PATH:/bin:/sbin:/usr/sbin
32SCRIPTNAME=vboxautostart-service.sh
33
34[ -f /etc/debian_release -a -f /lib/lsb/init-functions ] || NOLSB=yes
35[ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
36
37if [ -n "$INSTALL_DIR" ]; then
38 binary="$INSTALL_DIR/VBoxAutostart"
39else
40 binary="/usr/lib/virtualbox/VBoxAutostart"
41fi
42
43# silently exit if the package was uninstalled but not purged,
44# applies to Debian packages only (but shouldn't hurt elsewhere)
45[ ! -f /etc/debian_release -o -x $binary ] || exit 0
46
47[ -r /etc/default/virtualbox ] && . /etc/default/virtualbox
48
49# Preamble for Gentoo
50if [ "`which $0`" = "/sbin/rc" ]; then
51 shift
52fi
53
54begin_msg()
55{
56 test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
57 logger -t "${SCRIPTNAME}" "${1}."
58}
59
60succ_msg()
61{
62 logger -t "${SCRIPTNAME}" "${1}."
63}
64
65fail_msg()
66{
67 echo "${SCRIPTNAME}: failed: ${1}." >&2
68 logger -t "${SCRIPTNAME}" "failed: ${1}."
69}
70
71start_daemon() {
72 usr="$1"
73 shift
74 su - $usr -c "$*"
75}
76
77if which start-stop-daemon >/dev/null 2>&1; then
78 start_daemon() {
79 usr="$1"
80 shift
81 bin="$1"
82 shift
83 start-stop-daemon --chuid $usr --start --exec $bin -- $@
84 }
85fi
86
87vboxdrvrunning() {
88 lsmod | grep -q "vboxdrv[^_-]"
89}
90
91start() {
92 [ -z "$VBOXAUTOSTART_DB" ] && exit 0
93 [ -z "$VBOXAUTOSTART_CONFIG" ] && exit 0
94 begin_msg "Starting VirtualBox VMs configured for autostart" console;
95 vboxdrvrunning || {
96 fail_msg "VirtualBox kernel module not loaded!"
97 exit 0
98 }
99 PARAMS="--background --start --config $VBOXAUTOSTART_CONFIG"
100
101 # prevent inheriting this setting to VBoxSVC
102 unset VBOX_RELEASE_LOG_DEST
103
104 for user in `ls $VBOXAUTOSTART_DB/*.start`
105 do
106 start_daemon `basename $user | sed -ne "s/\(.*\).start/\1/p"` $binary $PARAMS > /dev/null 2>&1
107 done
108
109 return $RETVAL
110}
111
112stop() {
113 [ -z "$VBOXAUTOSTART_DB" ] && exit 0
114 [ -z "$VBOXAUTOSTART_CONFIG" ] && exit 0
115
116 PARAMS="--stop --config $VBOXAUTOSTART_CONFIG"
117
118 # prevent inheriting this setting to VBoxSVC
119 unset VBOX_RELEASE_LOG_DEST
120
121 for user in `ls $VBOXAUTOSTART_DB/*.stop`
122 do
123 start_daemon `basename $user | sed -ne "s/\(.*\).stop/\1/p"` $binary $PARAMS > /dev/null 2>&1
124 done
125
126 return $RETVAL
127}
128
129case "$1" in
130start)
131 start
132 ;;
133stop)
134 stop
135 ;;
136*)
137 echo "Usage: $0 {start|stop}"
138 exit 1
139esac
140
141exit $RETVAL
Note: See TracBrowser for help on using the repository browser.

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