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