1 | #!/bin/sh
|
---|
2 | ## @file
|
---|
3 | # VirtualBox Test Execution Service Init Script for NATted setups.
|
---|
4 | #
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox base platform packages, as
|
---|
10 | # available from https://www.virtualbox.org.
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or
|
---|
13 | # modify it under the terms of the GNU General Public License
|
---|
14 | # as published by the Free Software Foundation, in version 3 of the
|
---|
15 | # License.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful, but
|
---|
18 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | # General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | #
|
---|
25 | # The contents of this file may alternatively be used under the terms
|
---|
26 | # of the Common Development and Distribution License Version 1.0
|
---|
27 | # (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | # in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | # CDDL are applicable instead of those of the GPL.
|
---|
30 | #
|
---|
31 | # You may elect to license modified versions of this file under the
|
---|
32 | # terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | #
|
---|
34 | # SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | #
|
---|
36 |
|
---|
37 | # chkconfig: 35 35 65
|
---|
38 | # description: VirtualBox Test Execution Service
|
---|
39 | #
|
---|
40 | ### BEGIN INIT INFO
|
---|
41 | # Provides: vboxtxs
|
---|
42 | # Required-Start: $network
|
---|
43 | # Required-Stop:
|
---|
44 | # Default-Start: 2 3 4 5
|
---|
45 | # Default-Stop: 0 1 6
|
---|
46 | # Description: VirtualBox Test Execution Service
|
---|
47 | ### END INIT INFO
|
---|
48 |
|
---|
49 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
50 | SCRIPTNAME=vboxtxs-nat.sh
|
---|
51 |
|
---|
52 | CDROM_PATH=/media/cdrom
|
---|
53 | SCRATCH_PATH=/tmp/vboxtxs-scratch
|
---|
54 |
|
---|
55 | PIDFILE="/var/run/vboxtxs"
|
---|
56 |
|
---|
57 | # Preamble for Gentoo
|
---|
58 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
59 | shift
|
---|
60 | fi
|
---|
61 |
|
---|
62 | begin_msg()
|
---|
63 | {
|
---|
64 | test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
|
---|
65 | logger -t "${SCRIPTNAME}" "${1}."
|
---|
66 | }
|
---|
67 |
|
---|
68 | succ_msg()
|
---|
69 | {
|
---|
70 | logger -t "${SCRIPTNAME}" "${1}."
|
---|
71 | }
|
---|
72 |
|
---|
73 | fail_msg()
|
---|
74 | {
|
---|
75 | echo "${SCRIPTNAME}: failed: ${1}." >&2
|
---|
76 | logger -t "${SCRIPTNAME}" "failed: ${1}."
|
---|
77 | }
|
---|
78 |
|
---|
79 | killproc() {
|
---|
80 | kp_binary="${1##*/}"
|
---|
81 | pkill "${kp_binary}" || return 0
|
---|
82 | sleep 1
|
---|
83 | pkill "${kp_binary}" || return 0
|
---|
84 | sleep 1
|
---|
85 | pkill -9 "${kp_binary}"
|
---|
86 | return 0
|
---|
87 | }
|
---|
88 |
|
---|
89 | case "`uname -m`" in
|
---|
90 | AMD64|amd64|X86_64|x86_64)
|
---|
91 | binary=/opt/validationkit/linux/amd64/TestExecService
|
---|
92 | ;;
|
---|
93 |
|
---|
94 | i386|x86|i486|i586|i686|i787)
|
---|
95 | binary=/opt/validationkit/linux/x86/TestExecService
|
---|
96 | ;;
|
---|
97 |
|
---|
98 | *)
|
---|
99 | binary=/opt/validationkit/linux/x86/TestExecService
|
---|
100 | ;;
|
---|
101 | esac
|
---|
102 |
|
---|
103 | fixAndTestBinary() {
|
---|
104 | chmod a+x "$binary" 2> /dev/null > /dev/null
|
---|
105 | test -x "$binary" || {
|
---|
106 | echo "Cannot run $binary"
|
---|
107 | exit 1
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | start() {
|
---|
112 | if ! test -f $PIDFILE; then
|
---|
113 | begin_msg "Starting VirtualBox Test Execution Service" console
|
---|
114 | fixAndTestBinary
|
---|
115 | mount /dev/cdrom "${CDROM_PATH}" 2> /dev/null > /dev/null
|
---|
116 | $binary --auto-upgrade --scratch="${SCRATCH_PATH}" --cdrom="${CDROM_PATH}" \
|
---|
117 | --no-display-output --tcp-connect 10.0.2.2 > /dev/null
|
---|
118 | RETVAL=$?
|
---|
119 | test $RETVAL -eq 0 && sleep 2 && echo `pidof TestExecService` > $PIDFILE
|
---|
120 | if ! test -s "${PIDFILE}"; then
|
---|
121 | RETVAL=5
|
---|
122 | fi
|
---|
123 | if test $RETVAL -eq 0; then
|
---|
124 | succ_msg "VirtualBox Test Execution service started"
|
---|
125 | else
|
---|
126 | fail_msg "VirtualBox Test Execution service failed to start"
|
---|
127 | fi
|
---|
128 | fi
|
---|
129 | return $RETVAL
|
---|
130 | }
|
---|
131 |
|
---|
132 | stop() {
|
---|
133 | if test -f $PIDFILE; then
|
---|
134 | begin_msg "Stopping VirtualBox Test Execution Service" console
|
---|
135 | killproc $binary
|
---|
136 | fi
|
---|
137 | }
|
---|
138 |
|
---|
139 | restart() {
|
---|
140 | stop && start
|
---|
141 | }
|
---|
142 |
|
---|
143 | status() {
|
---|
144 | echo -n "Checking for vboxtxs"
|
---|
145 | if [ -f $PIDFILE ]; then
|
---|
146 | echo " ...running"
|
---|
147 | else
|
---|
148 | echo " ...not running"
|
---|
149 | fi
|
---|
150 | }
|
---|
151 |
|
---|
152 | case "$1" in
|
---|
153 | start)
|
---|
154 | start
|
---|
155 | ;;
|
---|
156 | stop)
|
---|
157 | stop
|
---|
158 | ;;
|
---|
159 | restart)
|
---|
160 | restart
|
---|
161 | ;;
|
---|
162 | status)
|
---|
163 | status
|
---|
164 | ;;
|
---|
165 | setup)
|
---|
166 | ;;
|
---|
167 | cleanup)
|
---|
168 | ;;
|
---|
169 | *)
|
---|
170 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
171 | exit 1
|
---|
172 | esac
|
---|
173 |
|
---|
174 | exit $RETVAL
|
---|