VirtualBox

Ignore:
Timestamp:
Jan 29, 2013 7:33:05 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
83421
Message:

Installer/linux: add support for stop and status commands to the service file generator and simplify the code.

File:
1 edited

Legend:

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

    r44119 r44437  
    6868}
    6969
     70# Create a trivial test command in temporary directory $1 with name $2.
     71test_oneshot()
     72{
     73    cat > "${1}/${2}" << EOF
     74#!/bin/sh
     75if test "\${1}" = start; then
     76    touch "${1}/started"
     77else
     78    rm "${1}/started"
     79fi
     80exit 0
     81EOF
     82chmod u+x "${1}/${2}"
     83}
     84
    7085# Test some dodgy input values against generate_service_file.
     86# Make sure there is a substitution pattern at the end too.
    7187print_line "generation of shell script from template."
    72 input='TEST1%DESCRIPTION%%%%SERVICE_NAME% TST2 TEST  %ARGUMENTS%%COMMAND%'
     88input='TEST1%DESCRIPTION%%%%SERVICE_NAME%%STOP_COMMAND% TST2 TEST  %ARGUMENTS%%COMMAND%'
    7389out=`echo "${input}" |
    7490    helpers/generate_service_file --command '/usr/bin
     
    8298world'\'
    8399case "${out}" in ${expected})
    84 echo "SUCCESS";;
     100echo "SUCCESS (1)";;
     101*)
     102cat << EOF
     103FAILED: expected
     104${expected}
     105but got
     106${out}
     107EOF
     108esac
     109input='TEST%HAVE_STOP_COMMAND%%SERVICE_NAME%%STOP_COMMAND% TST2
     110 TEST  %COMMAND%'
     111out=`echo "${input}" |
     112    helpers/generate_service_file --command '/usr/bin/hello' --format shell --description ''`
     113expected='TEST TEST  '\''/usr/bin/hello'\'''
     114case "${out}" in ${expected})
     115echo "SUCCESS (2)";;
     116*)
     117cat << EOF
     118FAILED: expected
     119${expected}
     120but got
     121${out}
     122EOF
     123esac
     124input='TEST%HAVE_STOP_COMMAND%%SERVICE_NAME%%STOP_COMMAND% %STOP_ARGUMENTS% TST2
     125 TEST  %COMMAND%'
     126out=`echo "${input}" |
     127    helpers/generate_service_file --command '/usr/bin/hello' --format shell --description '' --stop-command /usr/bin/stop --stop-arguments hello`
     128expected='TESThello'\''/usr/bin/stop'\'' '\''hello'\'' TST2
     129 TEST  '\''/usr/bin/hello'\'''
     130case "${out}" in ${expected})
     131echo "SUCCESS (3)";;
    85132*)
    86133cat << EOF
     
    115162test_service "${tmpdir}" "service"
    116163# And install it.
    117 scripts/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --enable ||
     164scripts/install_service  --prefix "${tmpdir}" --enable -- --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" ||
    118165    fail_msg "\"scripts/install_service\" failed."
    119166# Check that the main service file was created as specified.
     
    159206fi
    160207
     208# Test an one shot init script installation.
     209print_line "installing a one shot init script."
     210failed=""
     211# Create a simulated init system layout.
     212tmpdir="${tmpbase}0"
     213create_simulated_init_tree "${tmpdir}"
     214# Create the command binary.
     215test_oneshot "${tmpdir}" "command"
     216# And install the script.
     217scripts/install_service --prefix "${tmpdir}" --enable -- --command "${tmpdir}/command" --arguments "start" --description "My description" --stop-command "${tmpdir}/command" --stop-arguments "stop" --one-shot ||
     218    fail_msg "\"scripts/install_service\" failed."
     219# Sanity test.
     220test -f "${tmpdir}/started" &&
     221    fail_msg "\"${tmpdir}/started\" already exists!"
     222# Try to start the service using the symbolic links which should have been
     223# created.
     224if "${tmpdir}/rc3.d/S20command" --prefix "${tmpdir}" --lsb-functions "" start >/dev/null 2>&1; then
     225    test -f "${tmpdir}/started" ||
     226        fail_msg "\"${tmpdir}/rc3.d/S20command\" did not start correctly."
     227else
     228    fail_msg "could not start \"${tmpdir}/rc3.d/S20command\"."
     229fi
     230# Try to stop the service using the symbolic links which should have been
     231# created.
     232if "${tmpdir}/rc.d/rc6.d/K80command" --prefix "${tmpdir}" --lsb-functions "" stop >/dev/null 2>&1; then
     233    test -f "${tmpdir}/started" &&
     234        echo "\"${tmpdir}/rc.d/rc6.d/K80command\" did not stop correctly."
     235else
     236    fail_msg "could not stop \"${tmpdir}/rc.d/rc6.d/K80command\"."
     237fi
     238# Final summary.
     239if test -n "${failed}"; then
     240    echo "${failed}"
     241else
     242    echo SUCCESS
     243fi
     244
    161245# Test an init script removal.
    162246print_line "removing an init script."
     
    168252test_service "${tmpdir}" "service"
    169253# Install it.
    170 scripts/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --enable ||
     254scripts/install_service --prefix "${tmpdir}" --enable -- --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" ||
    171255    fail_msg "\"scripts/install_service\" failed."
    172256# And remove it again.
    173 scripts/install_service --command "${tmpdir}/service" --prefix "${tmpdir}" --remove ||
     257scripts/install_service --prefix "${tmpdir}" --remove -- --command "${tmpdir}/service" ||
    174258    fail_msg "\"scripts/install_service\" failed."
    175259# After uninstallation this should be the only file left in the init tree.
     
    193277test_service "${tmpdir}" "service"
    194278# Install it.
    195 scripts/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --enable ||
     279scripts/install_service --prefix "${tmpdir}" --enable -- --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" ||
    196280    fail_msg "\"scripts/install_service\" failed."
    197281# Install it disabled without forcing.
    198 scripts/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --disable ||
     282scripts/install_service --prefix "${tmpdir}" --disable -- --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" ||
    199283    fail_msg "\"scripts/install_service\" failed."
    200284test "x`find "${tmpdir}"/rc*.d "${tmpdir}/runlevel" -type l | wc -l`" = "x15" ||
     
    216300test_service "${tmpdir}" "service"
    217301# Install it.
    218 scripts/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --disable ||
     302scripts/install_service --prefix "${tmpdir}" --disable -- --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" ||
    219303    fail_msg "\"scripts/install_service\" failed."
    220304# Install it disabled without forcing.
    221 scripts/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --enable ||
     305scripts/install_service --prefix "${tmpdir}" --enable -- --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" ||
    222306    fail_msg "\"scripts/install_service\" failed."
    223307test "x`find "${tmpdir}"/rc*.d "${tmpdir}/runlevel" -type l`" = "x" ||
     
    239323test_service "${tmpdir}" "service"
    240324# Install it.
    241 scripts/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --enable ||
     325scripts/install_service --prefix "${tmpdir}" --enable -- --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" ||
    242326    fail_msg "\"scripts/install_service\" failed."
    243327# Install it disabled without forcing.
    244 scripts/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --force-disable ||
     328scripts/install_service --prefix "${tmpdir}" --force-disable -- --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" ||
    245329    fail_msg "\"scripts/install_service\" failed."
    246330test "x`find "${tmpdir}"/rc*.d "${tmpdir}/runlevel" -type l`" = "x" ||
     
    262346test_service "${tmpdir}" "service"
    263347# Install it.
    264 scripts/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --disable ||
     348scripts/install_service --prefix "${tmpdir}" --disable -- --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" ||
    265349    fail_msg "\"scripts/install_service\" failed."
    266350# Install it disabled without forcing.
    267 scripts/install_service --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" --prefix "${tmpdir}" --force-enable ||
     351scripts/install_service --prefix "${tmpdir}" --force-enable -- --command "${tmpdir}/service" --arguments "test of my\ arguments" --description "My description" ||
    268352    fail_msg "\"scripts/install_service\" failed."
    269353test "x`find "${tmpdir}"/rc*.d "${tmpdir}/runlevel" -type l | wc -l`" = "x15" ||
Note: See TracChangeset for help on using the changeset viewer.

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