Changeset 44063 in vbox
- Timestamp:
- Dec 7, 2012 2:58:52 PM (12 years ago)
- Location:
- trunk/src/VBox/Installer/linux
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/linux/Makefile.kmk
r44050 r44063 67 67 linux-bin_MODE = a+rx,u+w 68 68 linux-bin_SOURCES = \ 69 VBoxHeadlessXOrg.sh \69 scripts/VBoxHeadlessXOrg.sh=>scripts/VBoxHeadlessXOrg.sh \ 70 70 VBoxSysInfo.sh \ 71 71 VBoxCreateUSBNode.sh \ -
trunk/src/VBox/Installer/linux/scripts/VBoxHeadlessXOrg.sh
r44047 r44063 45 45 ## The name of this script. 46 46 SCRIPT_NAME="$0" 47 ## Command line we were called with.48 SCRIPT_COMMAND_LINE="$0 $@"49 47 ## The service name. 50 48 SERVICE_NAME="vboxheadlessxorg" 49 ## The service description. 50 SERVICE_DESCRIPTION="Headless rendering service" 51 51 ## Signals and conditions which may be used to terminate the service. 52 52 EXIT_SIGNALS="EXIT HUP INT QUIT ABRT TERM" 53 ## The default run-time data folder. 54 DEFAULT_RUN_FOLDER="/var/run/${SERVICE_NAME}/" 53 55 ## The default X server configuration directory. 54 DEFAULT_CONFIGURATION_FOLDER="/etc/vbox/headlessxorg.conf.d" 56 DEFAULT_CONFIGURATION_FOLDER="${DEFAULT_RUN_FOLDER}/xorg.conf.d/" 57 ## The extra data key used to provide the list of available X server displays. 58 EXTRA_DATA_KEY_DISPLAYS="HeadlessXServer/Displays" 59 ## The extra data key used to specify the X server authority file. 60 EXTRA_DATA_KEY_AUTH="HeadlessXServer/AuthFile" 55 61 56 62 ## Print usage information for the service script. … … 65 71 66 72 Start one or several X servers in the background for use with headless 67 rendering. We only support X.Org Server at the moment. Starting the X servers 68 is managed by dropping one or more files xorg.conf.<n> into a configuration 69 directory, by default ${DEFAULT_CONFIGURATION_FOLDER}, but this can be overridden 70 in the configuration file (see below). We will attempt to start an X server 71 process for each configuration file using display number <n>. 73 rendering. We only support X.Org Server at the moment. On service start-up available graphics devices are detected and an X server configuration file is 74 generated for each. We attempt to start an X server process for each 75 configuration file. The process is configurable by setting values in a file as 76 described below. 72 77 73 78 Options: 74 79 75 80 -c|--conf-file) Specify an alternative locations for the configuration 76 file. The default location is "${CONFIGURATION_FILE}". 81 file. The default location is: 82 "${CONFIGURATION_FILE}" 77 83 78 84 --help|--usage Print this text. … … 85 91 86 92 HEADLESS_X_ORG_CONFIGURATION_FOLDER 87 The folder where the configuration files for the X servers are to be found.93 The folder where the X server configuration files are to be created. 88 94 89 95 HEADLESS_X_ORG_LOG_FOLDER 90 The folder where log files will be created.96 The folder where log files will be saved. 91 97 92 98 HEADLESS_X_ORG_LOG_FILE … … 96 102 The folder to store run-time data in. 97 103 98 HEADLESS_X_ORG_CHECK_PREREQUISITES 99 Shell command to execute to check whether all dependencies for the X 100 servers are available - usually a test for a device node. This will be 101 repeated at regular intervals until it returns successfully, so a command 102 which can be executed internally be the shell (like "[") is preferable. 103 The default command waits until the udev event queue has settled. 104 HEADLESS_X_ORG_WAIT_FOR_PREREQUISITES 105 Command to execute to wait until all dependencies for the X servers are 106 available. The default command waits until the udev event queue has 107 settled. The command may return failure to signal that it has given up. 104 108 105 109 HEADLESS_X_ORG_USERS … … 110 114 \${HEADLESS_X_ORG_SERVER_POST_COMMAND}), and not by the service itself. 111 115 116 HEADLESS_X_ORG_FIRST_DISPLAY 117 The first display number which will be used for a started X server. The 118 others will use the following numbers. 119 112 120 HEADLESS_X_ORG_SERVER_PRE_COMMAND 113 121 Command to execute once to perform any set-up needed before starting the 114 122 X servers, such as setting up the X server authentication. The default 115 123 command creates an authority file for each of the users in the list 116 \${HEADLESS_X_ORG_USERS}. 124 \${HEADLESS_X_ORG_USERS} and generates server configuration files for all 125 detected graphics cards. 117 126 118 127 HEADLESS_X_ORG_SERVER_COMMAND … … 122 131 123 132 HEADLESS_X_ORG_SERVER_POST_COMMAND 124 Command to execute once the X servers have been successfully started. By 125 default this stores the service configuration information to VirtualBox 126 extra data for each of the users in the list \${HEADLESS_X_ORG_USERS}. 127 It will be passed a single parameter which is a space-separated list of the 128 X server screen numbers. 133 Command to execute once the X servers have been successfully started. It 134 will be passed a single parameter which is a space-separated list of the 135 X server screen numbers. By default this stores the service configuration 136 information to VirtualBox extra data for each of the users in the list 137 from the variable HEADLESS_X_ORG_USERS: the list of displays is set to the 138 key "${EXTRA_DATA_KEY_DISPLAYS}" and the path of the authority file to 139 "${EXTRA_DATA_KEY_AUTH}". 129 140 EOF 130 141 } … … 135 146 HEADLESS_X_ORG_LOG_FILE="${SERVICE_NAME}.log" 136 147 HEADLESS_X_ORG_RUN_FOLDER="/var/run/${SERVICE_NAME}" 137 HEADLESS_X_ORG_ CHECK_PREREQUISITES="udevadm settle || ! udevadm -V"148 HEADLESS_X_ORG_WAIT_FOR_PREREQUISITES="udevadm settle" # Fails if no udevadm. 138 149 HEADLESS_X_ORG_USERS="" 150 HEADLESS_X_ORG_FIRST_DISPLAY=10 139 151 140 152 X_AUTH_FILE="${HEADLESS_X_ORG_RUN_FOLDER}/xauth" 141 153 default_pre_command() 142 154 { 155 # Create and duplicate the authority file. 143 156 echo > "${X_AUTH_FILE}" 144 157 key="$(dd if=/dev/urandom count=1 bs=16 2>/dev/null | od -An -x)" … … 148 161 chown "${i}" "${X_AUTH_FILE}.${i}" 149 162 done 163 # Create the xorg.conf files. 164 mkdir -p "${HEADLESS_X_ORG_CONFIGURATION_FOLDER}" || return 1 165 display="${HEADLESS_X_ORG_FIRST_DISPLAY}" 166 for i in /sys/bus/pci/devices/*; do 167 read class < "${i}/class" 168 case ${class} in *03????) 169 address="${i##*/}" 170 address="${address%%:*}${address#*:}" 171 address="PCI:${address%%.*}:${address#*.}" 172 cat > "${HEADLESS_X_ORG_CONFIGURATION_FOLDER}/xorg.conf.${display}" << EOF 173 Section "Screen" 174 Identifier "Screen${display}" 175 EndSection 176 Section "ServerLayout" 177 Identifier "Layout${display}" 178 Screen "Screen${display}" 179 Option "AllowMouseOpenFail" "true" 180 Option "AutoAddDevices" "false" 181 Option "AutoAddGPU" "false" 182 Option "AutoEnableDevices" "false" 183 Option "IsolateDevice" "${address}" 184 EndSection 185 EOF 186 display=`expr ${display} + 1` 187 esac 188 done 150 189 } 151 190 HEADLESS_X_ORG_SERVER_PRE_COMMAND="default_pre_command" … … 165 204 # screens=$1 166 205 for i in ${HEADLESS_X_ORG_USERS}; do 167 su ${i} -c "VBoxManage setextradata global HeadlessXServer/Screens\"${1}\""168 su ${i} -c "VBoxManage setextradata global HeadlessXServer/AuthFile\"${HEADLESS_X_ORG_RUN_FOLDER}/xauth\""206 su ${i} -c "VBoxManage setextradata global ${EXTRA_DATA_KEY_DISPLAYS} \"${1}\"" 207 su ${i} -c "VBoxManage setextradata global ${EXTRA_DATA_KEY_AUTH} \"${HEADLESS_X_ORG_RUN_FOLDER}/xauth\"" 169 208 done 170 209 } … … 201 240 202 241 # Get the directory where the script is located. 203 VBOX_FOLDER="$(dirname "${SCRIPT_NAME}")" 204 VBOX_FOLDER=$(cd "${VBOX_FOLDER}" && pwd) 205 [ -d "${VBOX_FOLDER}" ] || 206 abort "Failed to change to directory ${VBOX_FOLDER}.\n" 207 # And change to the root directory so we don't hold any other open. 208 cd / 209 210 [ -r "${VBOX_FOLDER}/scripts/generated.sh" ] || 211 abort "${LOG_FILE}" "Failed to find installation information in ${VBOX_FOLDER}.\n" 212 . "${VBOX_FOLDER}/scripts/generated.sh" 242 SCRIPT_FOLDER=$(dirname "${SCRIPT_NAME}")"/" 243 [ -r "${SCRIPT_FOLDER}generated.sh" ] || 244 abort "${LOG_FILE}" "Failed to find installation information.\n" 245 . "${SCRIPT_FOLDER}generated.sh" 213 246 214 247 # Parse our arguments. 248 do_install="" 215 249 while [ "$#" -gt 0 ]; do 216 250 case $1 in … … 239 273 [ -r "${CONFIGURATION_FILE}" ] && . "${CONFIGURATION_FILE}" 240 274 275 # Change to the root directory so we don't hold any other open. 276 cd / 277 241 278 # If something fails here we will catch it when we create the directory. 242 279 [ -e "${HEADLESS_X_ORG_LOG_FOLDER}" ] && … … 258 295 banner 259 296 260 # Wait for our dependencies to become available. The increasing delay is 261 # probably not the cleverest way to do this. 262 DELAY=1 263 while ! eval ${HEADLESS_X_ORG_CHECK_PREREQUISITES}; do 264 sleep $((${DELAY} / 10 + 1)) 265 DELAY=$((${DELAY} + 1)) 266 done 297 # Wait for our dependencies to become available. 298 if [ -n "${HEADLESS_X_ORG_WAIT_FOR_PREREQUISITES}" ]; then 299 "${HEADLESS_X_ORG_WAIT_FOR_PREREQUISITES}" || 300 abort "Service prerequisites not available.\n" 301 fi 267 302 268 303 # Do any pre-start setup. 269 eval "${HEADLESS_X_ORG_SERVER_PRE_COMMAND}" 304 if [ -n "${HEADLESS_X_ORG_SERVER_PRE_COMMAND}" ]; then 305 "${HEADLESS_X_ORG_SERVER_PRE_COMMAND}" || 306 abort "Pre-requisite failed.\n" 307 fi 270 308 271 309 X_SERVER_PIDS="" … … 282 320 abort "Badly formed file name \"${conf_file}\".\n" 283 321 log_file="${HEADLESS_X_ORG_LOG_FOLDER}/Xorg.${screen}.log" 284 eval "${HEADLESS_X_ORG_SERVER_COMMAND} \"\${screen}\" \"\${conf_file}\" \"\${log_file}\"" "&"322 "${HEADLESS_X_ORG_SERVER_COMMAND}" "${screen}" "${conf_file}" "${log_file}" & 285 323 X_SERVER_PIDS="${X_SERVER_PIDS}${space}$!" 286 324 X_SERVER_SCREENS="${X_SERVER_SCREENS}${space}${screen}" … … 289 327 290 328 # Do any post-start work. 291 eval "${HEADLESS_X_ORG_SERVER_POST_COMMAND} \"${X_SERVER_SCREENS}\"" 329 if [ -n "${HEADLESS_X_ORG_SERVER_POST_COMMAND}" ]; then 330 "${HEADLESS_X_ORG_SERVER_POST_COMMAND}" "${X_SERVER_SCREENS}" || 331 abort "Post-command failed.\n" 332 fi 292 333 293 334 wait -
trunk/src/VBox/Installer/linux/testcase/tstHeadlessXOrg.sh
r43832 r44063 58 58 ## Create a simple configuration file. Add items onto the end to override them 59 59 # on an item-by-item basis. 60 create_basic_configuration_file() 61 { 62 FILE_NAME="$1" ## The name of the configuration file to create. 63 BASE_FOLDER="$2" ## The basic folder for creating things under. 60 create_basic_configuration() 61 { 62 TEST_FOLDER="${1}" 63 FILE_NAME="${TEST_FOLDER}conf" ## The name of the configuration file to create. 64 BASE_FOLDER="${TEST_FOLDER}" 65 XORG_FOLDER="${TEST_FOLDER}/xorg" 66 mkdir -p "${XORG_FOLDER}" 64 67 cat > "${FILE_NAME}" << EOF 65 68 HEADLESS_X_ORG_CONFIGURATION_FOLDER="${BASE_FOLDER}/xorg" … … 67 70 HEADLESS_X_ORG_LOG_FILE="log" 68 71 HEADLESS_X_ORG_RUN_FOLDER="${BASE_FOLDER}/run" 69 HEADLESS_X_ORG_ CHECK_PREREQUISITES=72 HEADLESS_X_ORG_WAIT_FOR_PREREQUISITES="true" 70 73 HEADLESS_X_ORG_SERVER_PRE_COMMAND= 71 74 HEADLESS_X_ORG_SERVER_COMMAND="echo" … … 88 91 TEST_NAME_FULL="${OUR_FOLDER}/$(basename "$0")" 89 92 90 # We use this to test a long-running process91 [ x"$1" = "x--test-sleep" ] &&92 while true; do true; done93 94 93 # Create a temporary directory for configuration and logging. 95 for i in 0 1 2 3 4 5 6 7 8 9; do 96 TEST_FOLDER="/tmp/${TEST_NAME} ${i}" # Space in the name to test quoting. 97 mkdir -m 0700 "${TEST_FOLDER}" 2>/dev/null && break 98 done 99 [ -d "${TEST_FOLDER}" ] || abort "Failed to create a temporary folder\n" 100 # Clean up. Small race here, but probably not important. 101 trap "rm -r \"${TEST_FOLDER}\" 2>/dev/null" EXIT HUP INT QUIT ABRT TERM 102 # Server configuration folder. 103 XORG_FOLDER="${TEST_FOLDER}/xorg" 104 mkdir -p "${XORG_FOLDER}" 94 TEST_FOLDER_BASE="/tmp/${TEST_NAME} 99/" # Space in the name to test quoting. 95 { 96 rm -rf "${TEST_FOLDER_BASE}" 2>/dev/null && 97 mkdir -m 0700 "${TEST_FOLDER_BASE}" 2>/dev/null 98 } || abort "Could not create test folder.\n" 105 99 106 100 ############################################################################### … … 108 102 ############################################################################### 109 103 print_line "simple start-up test" 110 create_basic_configuration _file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"104 create_basic_configuration "${TEST_FOLDER_BASE}simple_start-up_test/" 111 105 touch "${XORG_FOLDER}/xorg.conf.2" 112 106 touch "${XORG_FOLDER}/xorg.conf.4" … … 131 125 } 132 126 133 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &127 scripts/VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}conf" & 134 128 PID=$! 135 129 expect_exit "${PID}" 5 test_simple_start_up 136 rm "${XORG_FOLDER}"/xorg.conf.*137 130 138 131 ############################################################################### 139 132 # No configuration files. # 140 133 ############################################################################### 134 create_basic_configuration "${TEST_FOLDER_BASE}no_configuration_files/" 141 135 print_line "no configuration files" 142 136 … … 153 147 } 154 148 155 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &149 scripts/VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}conf" & 156 150 PID=$! 157 151 expect_exit "${PID}" 5 test_should_fail … … 161 155 ############################################################################### 162 156 print_line "bad configuration files" 157 create_basic_configuration "${TEST_FOLDER_BASE}bad_configuration_files/" 163 158 touch "${XORG_FOLDER}/xorg.conf.2" 164 159 touch "${XORG_FOLDER}/xorg.conf.4" 165 160 touch "${XORG_FOLDER}/xorg.conf.other" 166 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &161 scripts/VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}conf" & 167 162 PID=$! 168 163 expect_exit "${PID}" 5 test_should_fail 169 rm "${XORG_FOLDER}/"xorg.conf.*170 164 171 165 ############################################################################### … … 174 168 175 169 # Set up a configuration file for a long-running command. 176 create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}" 177 cat >> "${TEST_FOLDER}/conf" << EOF 178 HEADLESS_X_ORG_SERVER_COMMAND="\"${TEST_NAME_FULL}\" --test-sleep" 179 EOF 180 181 print_line "long running server command (sleeps)" 182 touch "${XORG_FOLDER}/xorg.conf.1" 170 create_basic_configuration "${TEST_FOLDER_BASE}long-running_command/" 171 cat >> "${TEST_FOLDER}conf" << EOF 172 HEADLESS_X_ORG_SERVER_COMMAND="${TEST_FOLDER}command.sh" 173 EOF 174 175 cat > "${TEST_FOLDER}command.sh" << EOF 176 #!/bin/sh 177 touch "${TEST_FOLDER}stopped" 178 touch "${TEST_FOLDER}started" 179 trap "touch \\"${TEST_FOLDER}stopped\\"; exit" TERM 180 rm "${TEST_FOLDER}stopped" 181 while true; do :; done 182 EOF 183 chmod a+x "${TEST_FOLDER}command.sh" 184 185 print_line "long running server command" 183 186 touch "${XORG_FOLDER}/xorg.conf.5" 184 187 FAILURE="" 185 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &188 scripts/VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}conf" & 186 189 PID="$!" 187 STARTED="" 188 for i in 1 2 3 4 5; do 189 sleep 1 # Make sure it runs for at least one second. 190 if ps -a -f | grep "${TEST_NAME}.*1" | grep -q -v grep && 191 ps -a -f | grep "${TEST_NAME}.*5" | grep -q -v grep; then 192 STARTED="true" 193 break 194 fi 195 done 196 [ -n "${STARTED}" ] || FAILURE="\nFAILED to start servers.\n" 190 while [ ! -f "${TEST_FOLDER}started" ]; do :; done 191 while [ -f "${TEST_FOLDER}stopped" ]; do :; done 197 192 [ -n "${PID}" ] && kill "${PID}" 2>/dev/null 198 STOPPED="" 199 if [ -z "${FAILURE}" ]; then 200 for i in 1 2 3 4 5; do 201 if ! ps -a -f | grep "${TEST_NAME}.*1" | grep -q -v grep && 202 ! ps -a -f | grep "${TEST_NAME}.*5" | grep -q -v grep; then 203 STOPPED="true" 204 break; 205 fi 206 sleep 1 207 done 208 [ -n "${STOPPED}" ] || 209 FAILURE="\nFAILED to stop servers.\n" # To terminate or not to terminate? 193 while [ ! -f "${TEST_FOLDER}stopped" ]; do :; done 194 printf "SUCCESS.\n" 195 196 ############################################################################### 197 # Pre-requisite test. # 198 ############################################################################### 199 200 # Set up a configuration file with a pre-requisite. 201 create_basic_configuration "${TEST_FOLDER_BASE}pre-requisite/" 202 cat >> "${TEST_FOLDER}conf" << EOF 203 HEADLESS_X_ORG_WAIT_FOR_PREREQUISITES="false" 204 EOF 205 206 print_line "configuration file with failed pre-requisite" 207 touch "${XORG_FOLDER}/xorg.conf.2" 208 touch "${XORG_FOLDER}/xorg.conf.4" 209 if scripts/VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}conf"; then 210 echo "\nFAILED to stop for failed pre-requisite.\n" 211 else 212 echo "SUCCESS" 210 213 fi 211 if [ -n "${FAILURE}" ]; then212 printf "${FAILURE}"213 else214 printf "SUCCESS.\n"215 fi216 rm "${XORG_FOLDER}/"xorg.conf.*217 218 ###############################################################################219 # Pre-requisite test. #220 ###############################################################################221 222 # Set up a configuration file with a pre-requisite.223 create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"224 cat >> "${TEST_FOLDER}/conf" << EOF225 HEADLESS_X_ORG_CHECK_PREREQUISITES="[ -e \\"${TEST_FOLDER}/run/prereq\\" ]"226 EOF227 228 print_line "configuration file with pre-requisite (sleeps)"229 touch "${XORG_FOLDER}/xorg.conf.2"230 touch "${XORG_FOLDER}/xorg.conf.4"231 FAILURE=""232 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &233 PID="$!"234 sleep 1235 ps -p "${PID}" > /dev/null 2>&1 || FAILURE="\nFAILED to wait for pre-requisite.\n"236 touch "${TEST_FOLDER}/run/prereq"237 if [ -z "${FAILURE}" ]; then238 expect_exit "${PID}" 10 test_simple_start_up239 else240 printf "${FAILURE}"241 fi242 rm -r "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}/run"243 214 244 215 ############################################################################### … … 247 218 248 219 # Set up our pre-command test configuration file. 249 create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}" 250 251 cat >> "${TEST_FOLDER}/conf" << EOF 220 create_basic_configuration "${TEST_FOLDER_BASE}pre-command/" 221 222 cat >> "${TEST_FOLDER}conf" << EOF 223 test_pre_command_server_pre_command() 224 { 225 touch "${TEST_FOLDER}/run/pre" 226 } 252 227 test_pre_command_server_command() 253 228 { 254 229 cp "${TEST_FOLDER}/run/pre" "${TEST_FOLDER}/run/pre2" 255 230 } 256 HEADLESS_X_ORG_SERVER_PRE_COMMAND="t ouch \"${TEST_FOLDER}/run/pre\""231 HEADLESS_X_ORG_SERVER_PRE_COMMAND="test_pre_command_server_pre_command" 257 232 HEADLESS_X_ORG_SERVER_COMMAND="test_pre_command_server_command" 258 233 EOF … … 280 255 281 256 rm -f "${TEST_FOLDER}/run/pre" 282 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &257 scripts/VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}conf" & 283 258 PID=$! 284 259 expect_exit "${PID}" 5 test_pre_command 285 rm -f "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}"/run/pre*286 260 287 261 ############################################################################### … … 290 264 291 265 # Set up our post-command test configuration file. 292 create_basic_configuration _file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"293 cat >> "${TEST_FOLDER} /conf" << EOF266 create_basic_configuration "${TEST_FOLDER_BASE}post-command/" 267 cat >> "${TEST_FOLDER}conf" << EOF 294 268 test_post_command_post_command() 295 269 { … … 322 296 323 297 rm -f "${TEST_FOLDER}/run/post" 324 ./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &298 scripts/VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}conf" & 325 299 PID=$! 326 300 expect_exit "${PID}" 5 test_post_command 327 rm -f "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}/run/post"
Note:
See TracChangeset
for help on using the changeset viewer.