VirtualBox

Changeset 43704 in vbox


Ignore:
Timestamp:
Oct 22, 2012 4:18:03 PM (12 years ago)
Author:
vboxsync
Message:

Installer/linux: added support for pre-requisite test and pre-start command to HeadlessXOrg service script.

Location:
trunk/src/VBox/Installer/linux
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/linux/VBoxHeadlessXOrg.sh

    r43688 r43704  
    4040
    4141## Default configuration file name.
    42 # Don't use vbox.cfg as that is currently automatically created and deleted.
    43 # Don't use /etc/default/virtualbox as that is Debian policy only and not very
    44 # nice.  Let's try to use this in future and phase out the other two.
    45 ## @todo Should we be using /etc/virtualbox instead of /etc/vbox?
    46 CONFIGURATION_FILE=/etc/vbox/vbox.conf
     42# @note This is not very nice - /etc/default is actually Debian-specific.
     43CONFIGURATION_FILE=/etc/default/virtualbox
    4744## The name of this script.
    4845SCRIPT_NAME="$0"
     
    9087
    9188  HEADLESS_X_ORG_LOG_FOLDER
    92     The default log folder.
     89    The folder where log files will be created.
    9390
    9491  HEADLESS_X_ORG_LOG_FILE
    95     The default log file.
     92    The main log file name.
     93
     94  HEADLESS_X_ORG_RUN_FOLDER
     95    The folder to store run-time data in.
     96
     97  HEADLESS_X_ORG_CHECK_PREREQUISITES
     98    Shell command to execute to check whether all dependencies for the X
     99    servers are available - usually a test for a device node.  This will be
     100    repeated at regular intervals until it returns successfully, so a command
     101    which can be executed internally be the shell (like "[") is preferable.
     102
     103  HEADLESS_X_ORG_SERVER_PRE_COMMAND
     104    Command to execute once to perform any set-up needed before starting the
     105    X servers, such as setting up the X server authentication.
    96106
    97107  HEADLESS_X_ORG_SERVER_COMMAND
     
    114124HEADLESS_X_ORG_LOG_FOLDER="/var/log/${SERVICE_NAME}"
    115125HEADLESS_X_ORG_LOG_FILE="${SERVICE_NAME}.log"
    116 HEADLESS_X_ORG_SERVER_COMMAND="Xorg :\${screen} -config \"\${conf_file}\" -logverbose 0 -logfile /dev/null -verbose 7 > \"\${log_file}\" 2>&1"
     126HEADLESS_X_ORG_RUN_FOLDER="/var/run/${SERVICE_NAME}"
     127HEADLESS_X_ORG_CHECK_PREREQUISITES="[ -e /dev/dri/card0 ]"
     128X_AUTH_FILE="${HEADLESS_X_ORG_RUN_FOLDER}/xauth"
     129HEADLESS_X_ORG_SERVER_PRE_COMMAND="echo > \"${X_AUTH_FILE}\"; xauth -f \"${X_AUTH_FILE}\" add :0 . \"\$(dd if=/dev/urandom count=1 bs=16 2>/dev/null | od -An -x)\""
     130HEADLESS_X_ORG_SERVER_COMMAND="Xorg :\${screen} -auth \"${HEADLESS_X_ORG_RUN_FOLDER}/xauth\" -config \"\${conf_file}\" -logverbose 0 -logfile /dev/null -verbose 7 > \"\${log_file}\" 2>&1"
    117131HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE="Xorg.\${screen}.log"
    118132
     
    195209  abort "Failed to create log folder \"${HEADLESS_X_ORG_LOG_FOLDER}\".\n"
    196210}
     211mkdir -p "${HEADLESS_X_ORG_RUN_FOLDER}" 2>/dev/null ||
     212{
     213  banner
     214  abort "Failed to create run folder \"${HEADLESS_X_ORG_RUN_FOLDER}\".\n"
     215}
    197216exec > "${HEADLESS_X_ORG_LOG_FOLDER}/${HEADLESS_X_ORG_LOG_FILE}" 2>&1
    198217
    199218banner
     219
     220# Wait for our dependencies to become available.  The increasing delay is
     221# probably not the cleverest way to do this.
     222DELAY=1
     223while ! eval ${HEADLESS_X_ORG_CHECK_PREREQUISITES}; do
     224  sleep $((${DELAY} / 10 + 1))
     225  DELAY=$((${DELAY} + 1))
     226done
     227
     228# Do any pre-start setup.
     229eval "${HEADLESS_X_ORG_SERVER_PRE_COMMAND}"
    200230
    201231X_SERVER_PIDS=""
  • trunk/src/VBox/Installer/linux/testcase/tstHeadlessXOrg.sh

    r43688 r43704  
    1414#
    1515
    16 [ x"$1" = x"--keep-temp" ] && KEEP_TEMP=true
    17 
    1816## The function definition at the start of every non-trivial shell script!
    1917abort()
     
    3432}
    3533
    36 ## Run a test in which VBoxHeadlessXOrg.sh is expected to complete within a
    37 # certain time and call a function if it does which should check whether the
    38 # test was successful and print status information.  The function takes the
    39 # exit status as its single parameter.
    40 run_expect_exit()
    41 {
    42   CONF_FILE="$1"      ## The configuration file.
     34## Expected a process to complete within a certain time and call a function if
     35# it does which should check whether the test was successful and print status
     36# information.  The function takes the exit status as its single parameter.
     37expect_exit()
     38{
     39  PID="$1"            ## The PID we are waiting for.
    4340  TIME_OUT="$2"       ## The time-out before we terminate the process.
    4441  TEST_FUNCTION="$3"  ## The function to call on exit to check the test result.
    45   ./VBoxHeadlessXOrg.sh -c "${CONF_FILE}" &
    46   PID=$!
     42
    4743  # Give it time to complete.
    4844  { sleep "${TIME_OUT}"; kill "${PID}" 2>/dev/null; } &
     
    5753    ${TEST_FUNCTION} "${STATUS}"
    5854esac
     55}
     56
     57## Create a simple configuration file.  Add items onto the end to override them
     58# on an item-by-item basis.
     59create_basic_configuration_file()
     60{
     61  FILE_NAME="$1"    ## The name of the configuration file to create.
     62  BASE_FOLDER="$2"  ## The basic folder for creating things under.
     63  cat > "${FILE_NAME}" << EOF
     64HEADLESS_X_ORG_CONFIGURATION_FOLDER="${BASE_FOLDER}/xorg"
     65HEADLESS_X_ORG_LOG_FOLDER="${BASE_FOLDER}/log"
     66HEADLESS_X_ORG_LOG_FILE="log"
     67HEADLESS_X_ORG_RUN_FOLDER="${BASE_FOLDER}/run"
     68HEADLESS_X_ORG_CHECK_PREREQUISITES=
     69HEADLESS_X_ORG_SERVER_PRE_COMMAND=
     70HEADLESS_X_ORG_SERVER_COMMAND="echo \\\${screen} \\\${conf_file} \\\${log_file}"
     71HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE="log.\\\${screen}"
     72EOF
     73
    5974}
    6075
     
    7691[ -d "${TEST_FOLDER}" ] || abort "Failed to create a temporary folder\n"
    7792# Clean up.  Small race here, but probably not important.
    78 [ -z "${KEEP_TEMP}" ] &&
    79   trap "rm -r \"${TEST_FOLDER}\" 2>/dev/null" EXIT HUP INT QUIT ABRT TERM
     93trap "rm -r \"${TEST_FOLDER}\" 2>/dev/null" EXIT HUP INT QUIT ABRT TERM
    8094# Server configuration folder.
    8195XORG_FOLDER="${TEST_FOLDER}/xorg"
    82 mkdir "${XORG_FOLDER}"
    83 
    84 # Set up our basic configuration file.
    85 cat > "${TEST_FOLDER}/conf" << EOF
    86 HEADLESS_X_ORG_CONFIGURATION_FOLDER="${XORG_FOLDER}"
    87 HEADLESS_X_ORG_LOG_FOLDER="${TEST_FOLDER}/log"
    88 HEADLESS_X_ORG_LOG_FILE="log"
    89 HEADLESS_X_ORG_SERVER_COMMAND="echo \\\${screen} \\\${conf_file} \\\${log_file}"
    90 HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE="log.\\\${screen}"
    91 EOF
     96mkdir -p "${XORG_FOLDER}"
    9297
    9398# Simple start-up test.
    9499print_line "simple start-up test"
    95 touch "${XORG_FOLDER}/xorg.conf.2"
    96 touch "${XORG_FOLDER}/xorg.conf.4"
     100create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"
     101touch "${XORG_FOLDER}/xorg.conf.2"
     102touch "${XORG_FOLDER}/xorg.conf.4"
     103
    97104test_simple_start_up()
    98105{
     
    113120  esac
    114121}
    115 run_expect_exit "${TEST_FOLDER}/conf" 5 test_simple_start_up
     122
     123./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &
     124PID=$!
     125expect_exit "${PID}" 5 test_simple_start_up
    116126rm "${XORG_FOLDER}"/xorg.conf.*
    117127
    118128# No configuration files.
    119129print_line "no configuration files"
     130
    120131test_should_fail()
    121132{
     
    129140  esac
    130141}
    131 run_expect_exit "${TEST_FOLDER}/conf" 5 test_should_fail
     142
     143./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &
     144PID=$!
     145expect_exit "${PID}" 5 test_should_fail
    132146
    133147# Bad configuration files.
     
    136150touch "${XORG_FOLDER}/xorg.conf.4"
    137151touch "${XORG_FOLDER}/xorg.conf.other"
    138 run_expect_exit "${TEST_FOLDER}/conf" 5 test_should_fail
     152./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &
     153PID=$!
     154expect_exit "${PID}" 5 test_should_fail
    139155rm "${XORG_FOLDER}/"xorg.conf.*
    140156
    141157# Set up a configuration file for a long-running command.
    142 cat > "${TEST_FOLDER}/conf" << EOF
    143 HEADLESS_X_ORG_CONFIGURATION_FOLDER="${XORG_FOLDER}"
    144 HEADLESS_X_ORG_LOG_FOLDER="${TEST_FOLDER}/log"
    145 HEADLESS_X_ORG_LOG_FILE="log"
     158create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"
     159cat >> "${TEST_FOLDER}/conf" << EOF
    146160HEADLESS_X_ORG_SERVER_COMMAND="echo $$ > ${TEST_FOLDER}/pid.\\\${screen}; cat"
    147 HEADLESS_X_ORG_SERVER_LOG_FILE_TEMPLATE="log.\\\${screen}"
    148161EOF
    149162
     
    173186rm "${XORG_FOLDER}/"xorg.conf.*
    174187rm -f "${TEST_FOLDER}/pid.1" "${TEST_FOLDER}/pid.5"
     188
     189# Set up a configuration file with a pre-requisite.
     190create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"
     191cat >> "${TEST_FOLDER}/conf" << EOF
     192HEADLESS_X_ORG_CHECK_PREREQUISITES="[ -e \\"${TEST_FOLDER}/run/prereq\\" ]"
     193EOF
     194
     195# Pre-requisite test.
     196print_line "configuration file with pre-requisite (sleeps)"
     197touch "${XORG_FOLDER}/xorg.conf.2"
     198touch "${XORG_FOLDER}/xorg.conf.4"
     199FAILURE=""
     200./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &
     201PID="$!"
     202sleep 1
     203ps -p "${PID}" > /dev/null 2>&1 || FAILURE="\nFAILED to wait for pre-requisite.\n"
     204touch "${TEST_FOLDER}/run/prereq"
     205if [ -z "${FAILURE}" ]; then
     206  expect_exit "${PID}" 10 test_simple_start_up
     207else
     208  printf "${FAILURE}"
     209fi
     210rm -r "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}/run"
     211
     212# Set up our pre-command test configuration file.
     213create_basic_configuration_file "${TEST_FOLDER}/conf" "${TEST_FOLDER}"
     214cat >> "${TEST_FOLDER}/conf" << EOF
     215HEADLESS_X_ORG_SERVER_PRE_COMMAND="touch \"${TEST_FOLDER}/run/pre\""
     216EOF
     217
     218# Pre-command test.
     219print_line "pre-command test"
     220touch "${XORG_FOLDER}/xorg.conf.2"
     221touch "${XORG_FOLDER}/xorg.conf.4"
     222
     223test_pre_command()
     224{
     225  STATUS="$1"
     226  case "${STATUS}" in
     227  0)
     228    LOG_FOLDER="${TEST_FOLDER}/log"
     229    LOG="${LOG_FOLDER}/log"
     230    if [ -e "${TEST_FOLDER}/run/pre" ]; then
     231      printf "SUCCESS.\n"
     232    else
     233      printf "\nFAILED: pre-command not executed.\n"
     234    fi
     235    ;;
     236  *)
     237    printf "\nFAILED: exit status ${STATUS}.\n"
     238  esac
     239}
     240
     241rm -f "${TEST_FOLDER}/run/pre"
     242./VBoxHeadlessXOrg.sh -c "${TEST_FOLDER}/conf" &
     243PID=$!
     244expect_exit "${PID}" 5 test_pre_command
     245rm -f "${XORG_FOLDER}"/xorg.conf.* "${TEST_FOLDER}/run/pre"
Note: See TracChangeset for help on using the changeset viewer.

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