VirtualBox

Changeset 44049 in vbox for trunk/src/VBox/Installer


Ignore:
Timestamp:
Dec 6, 2012 11:31:26 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
82516
Message:

Installer/linux: finish init script generator and add a couple of test cases.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Installer/linux/Makefile.kmk

    r43717 r44049  
    1919include $(KBUILD_PATH)/subheader.kmk
    2020
    21 # Include sub-makefile.
     21# Include sub-makefiles.
     22include $(PATH_SUB_CURRENT)/install_service/Makefile.kmk
    2223ifdef VBOX_WITH_TESTCASES
    2324 include $(PATH_SUB_CURRENT)/testcase/Makefile.kmk
  • trunk/src/VBox/Installer/linux/install_service/Makefile.kmk

    r44002 r44049  
    11# $Id$
    22## @file
    3 # Sub-Makefile for the VirtualBox Guest Addition X11 Client.
     3# Sub-Makefile for the Linux installer init file generator.
    44#
    55
     
    3434endif
    3535
     36INSTALLS.linux += linux-install-service-bin
     37linux-install-service-bin_INST =    bin/helpers/
     38linux-install-service-bin_MODE =    a+rx,u+w
     39linux-install-service-bin_SOURCES = \
     40        install_service.sh=>install_service
     41
     42INSTALLS.linux += linux-install-service-nobin
     43linux-install-service-nobin_INST =    bin/helpers/
     44linux-install-service-nobin_MODE =    a+r,u+w
     45linux-install-service-nobin_SOURCES = \
     46        init_template.sh
     47
    3648include $(FILE_KBUILD_SUB_FOOTER)
    3749
  • trunk/src/VBox/Installer/linux/install_service/generate_service_file.cpp

    r44002 r44049  
    8989"      is supported.  This affects escaping of strings substituted.\n"
    9090"\n"
    91 "  --command\n"
     91"  --command <command>\n"
    9292"      The absolute path of the executable file to be started by the service.\n"
    9393"      No form of quoting should be used here.  Substituted for the sequence\n"
     
    9595    RTPrintf(
    9696"\n"
    97 "  --arguments <arguments>\n"
    98 "      The arguments to pass to the executable file when it is started.  ASCII\n"
    99 "      characters 0 to 31, \"\'\" and 127 should be escaped in C string-style and\n"
    100 "      spaces inside words should be preceeded by a back slash.  Some systemd-\n"
    101 "      style \"%%\" sequences may be added at a future time.  Substituted for the\n"
    102 "      sequence \"%%ARGUMENTS%%\" in the template.\n");
    103     RTPrintf(
    104 "\n"
    10597"  --description <description>\n"
    10698"      A short description of the service which can also be used in sentences\n"
    107 "      like \"<description> failed to start.\".  ASCII characters 0 to 31 and 127\n"
    108 "      should not be used.  Substituted for the sequence \"%%DESCRIPTION%%\" in the\n"
    109 "      template.\n"
     99"      like \"<description> failed to start.\", as a single parameter.  ASCII\n"
     100"      characters 0 to 31 and 127 should not be used.  Substituted for the\n"
     101"      sequence \"%%DESCRIPTION%%\" in the template.\n"
    110102"\n"
    111103"Other options:\n"
     104"\n");
     105    RTPrintf(
     106"  --arguments <arguments>\n"
     107"      The arguments to pass to the executable file when it is started, as a\n"
     108"      single parameter.  ASCII characters 0 to 31, \"\'\" and 127 should be escaped\n"
     109"      in C string-style and spaces inside words should be preceeded by a back\n"
     110"      slash.  Some systemd-style \"%%\" sequences may be added at a future time.\n"
     111"      Substituted for the sequence \"%%ARGUMENTS%%\" in the template.\n"
    112112"\n");
    113113    RTPrintf(
  • trunk/src/VBox/Installer/linux/install_service/init_template.sh

    r44002 r44049  
    2323# Short-Description: %DESCRIPTION%
    2424### END INIT INFO
     25
     26## @todo We should really replace the daemon starting, stopping and checking
     27#        code with a tool of our own written in C, which we could always use
     28#        instead of the LSB functions.
    2529
    2630cr="
     
    7175LSB_FUNCTIONS="/lib/lsb/init-functions"
    7276
    73 ## Redhat and Fedora lock directory
    74 LOCK_FOLDER="/var/lock/subsys/"
    75 LOCK_FILE="${LOCK_FOLDER}/%SERVICE_NAME%"
    76 
    7777# Silently exit if the package was uninstalled but not purged.
    78 [ -r %COMMAND% ] || exit 0
     78test -r %COMMAND% || exit 0
    7979
    8080## The function definition at the start of every non-trivial shell script!
     
    9191    exit 0
    9292}
     93
     94## Set the error message.
     95set_error()
     96{
     97    test -z "${error}" && error="${1}"
     98}
     99
     100# Gentoo/OpenRC perculiarity.
     101if test "x${0}" = "x/sbin/rc" || test "x${0}" = "xrc"; then
     102    shift
     103fi
     104
     105# Process arguments.
     106action=""
     107error=""
     108prefix="/var"
     109while test x"${#}" != "x0"; do
     110    case "${1}" in
     111    --lsb-functions)
     112        test x"${#}" = "x1" &&
     113            set_error "${1}: missing argument."
     114        LSB_FUNCTIONS="${2}"
     115        shift 2;;
     116    --prefix)
     117        test x"${#}" = "x1" &&
     118            set_error "${1}: missing argument."
     119        prefix="${2}"
     120        shift 2;;
     121    --help)
     122        cat << EOF
     123Usage:
     124
     125  ${0} {start|stop|restart|status} [<options>]
     126
     127  start|stop|restart|status
     128      Start/stop/restart/report status for the service.
     129
     130Options:
     131
     132  --lsb-functions <script>
     133      Take the standard LSB init functions from <script> instead of from the
     134      normal location, or use our own versions if <script> is an empty string.
     135
     136  --prefix <folder>
     137      Use the folder <folder> for storing variable data instead of "/var".  The
     138      child folder "run" must exist.
     139EOF
     140        exit 0;;
     141    start|stop|restart|force-reload|condrestart|try-restart|reload|status)
     142        test -z "${action}" ||
     143            set_error "More than one action requested."
     144        action="${1}"
     145        shift;;
     146    *)
     147        set_error "Unknown option \"${1}\".  Try \"${0} --help\" for more information."
     148        shift;;
     149    esac
     150done
     151
     152## Set Redhat and Fedora lock directory
     153LOCK_FOLDER="${prefix}/lock/subsys/"
     154LOCK_FILE="${LOCK_FOLDER}/%SERVICE_NAME%"
    93155
    94156# Use LSB functions if available.  Success and failure messages default to just
    95157# "echo" if the LSB functions are not available, so call these functions with
    96158# messages which clearly read as success or failure messages.
    97 [ -n "${LSB_FUNCTIONS}" ] && [ -f "${LSB_FUNCTIONS}" ] &&
     159test -n "${LSB_FUNCTIONS}" && test -f "${LSB_FUNCTIONS}" &&
    98160  . "${LSB_FUNCTIONS}"
    99161
     
    101163    log_success_msg()
    102164    {
    103         echo "${*}"
    104     }
    105 
    106 type log_success_fail >/dev/null 2>&1 ||
    107     log_success_fail()
    108     {
    109         echo "${*}"
     165        cat << EOF
     166${*}
     167EOF
     168    }
     169
     170type log_failure_msg >/dev/null 2>&1 ||
     171    log_failure_msg()
     172    {
     173        cat << EOF
     174${*}
     175EOF
    110176    }
    111177
     
    113179pidfilename()
    114180{
    115     echo "/var/run/${1##*/}.pid"
     181    echo "${prefix}/run/${1##*/}.pid"
    116182}
    117183
     
    119185pidfileofproc()
    120186{
    121     if [ x"${1}" = "x-p" ]; then
     187    if test x"${1}" = "x-p"; then
    122188        echo "${2}"
    123189    else
     
    129195pidsfromfile()
    130196{
    131     read -r pids < "${1}" 2>/dev/null
     197    pids=""
     198    test -r "${1}" &&
     199        read -r pids < "${1}" 2>/dev/null
    132200    for i in $pids; do
    133         [ 1 -le "${i}" ] || return 1
     201        test 1 -le "${i}" || return 1
     202    done
    134203    echo "${pids}"
    135204}
     
    140209    binary="${1}"
    141210    shift
    142     ps -p "${@}" -f 2>/dev/null | grep -q "${binary}"
     211    ps -p "${@}" -f 2>/dev/null | grep "${binary}" >/dev/null
    143212}
    144213
     
    146215    pidofproc()
    147216    {
    148         pidfile="$(pidfileofproc "${@}")"
    149         [ "x${1}" = "x-p" ] && shift 2
    150         pids="$(pidsfromfile "${pidfile}")"
     217        pidfile="`pidfileofproc "${@}"`"
     218        test "x${1}" = "x-p" && shift 2
     219        pids="`pidsfromfile "${pidfile}"`"
    151220        procrunning "${1}" ${pids} && echo "${pids}"
    152221    }
     
    155224    killproc()
    156225    {
    157         pidfile="$(pidfileofproc "${@}")"
    158         [ "x${1}" = "x-p" ] && shift 2
    159         pids="$(pidsfromfile "${pidfile}")"
    160         if [ -n "${2}" ]; then
     226        pidfile="`pidfileofproc "${@}"`"
     227        test "x${1}" = "x-p" && shift 2
     228        pids="`pidsfromfile "${pidfile}"`"
     229        if test -n "${2}"; then
    161230            procrunning "${1}" ${pids} || return 1
    162231            kill "${2}" ${pids}
     
    165234            rm -f "${pidfile}"
    166235            procrunning "${1}" ${pids} || return 0
    167             kill "${pid}"
    168             time=0
    169             while true; do
    170                 sleep 1
    171                 procrunning "${1}" ${pids} || break
    172                 time=$((${time} + 1))
    173                 if [ "${time}" = "${SHUT_DOWN_TIME_OUT}" ]; then
    174                     kill -9 "${pid}"
    175                     break
    176                 fi
     236            kill "${pids}"
     237            # Short busy wait for the process to terminate.
     238            stamp="`times`"
     239            while test x"${stamp}" = x"`times`"; do
     240                procrunning "${1}" ${pids} || return 0
     241            done
     242            # Slow sleeping wait if it is still running.
     243            for high in "" 1 2 3 4 5 6 7 8 9; do
     244                for time in ${high}0 ${high}1 ${high}2 ${high}3 ${high}4 ${high}5 ${high}6 ${high}7 ${high}8 ${high}9; do
     245                    sleep 1
     246                    procrunning "${1}" ${pids} || return 0
     247                    if test "${time}" = "${SHUT_DOWN_TIME_OUT}"; then
     248                        kill -9 "${pid}"
     249                        return 0
     250                    fi
     251                done
    177252            done
    178253            return 0
     
    182257start()
    183258{
    184     [ -d "${LOCK_FOLDER}" ] && touch "${LOCK_FILE}"
    185     [ -n "$(pidofproc %COMMAND%)" ] && exit 0
     259    test -d "${LOCK_FOLDER}" && touch "${LOCK_FILE}"
     260    test -n "`pidofproc %COMMAND%`" && exit 0
    186261    %COMMAND% %ARGUMENTS% >/dev/null 2>&1 &
    187262    pid="$!"
    188     pidfile="$(pidfilename %COMMAND%)"
     263    pidfile="`pidfilename %COMMAND%`"
    189264    echo "${pid}" > "${pidfile}"
    190265    do_success
     
    201276status()
    202277{
    203     [ -n "$(pidofproc %COMMAND%)" ] && exit 0
    204     [ -f "$(pidfilename %COMMAND%)" ] && exit 1
    205     [ -f "${LOCK_FILE}" ] && exit 2
     278    pid="`pidofproc %COMMAND%`"
     279    test -n "${pid}" &&
     280    {
     281        echo "%SERVICE_NAME% running, process ${pid}"
     282        exit 0
     283    }
     284    test -f "`pidfilename %COMMAND%`" &&
     285    {
     286        echo "%SERVICE_NAME% not running but PID-file present."
     287        exit 1
     288    }
     289    test -f "${LOCK_FILE}" &&
     290    {
     291        echo "%SERVICE_NAME% not running but lock file present."
     292        exit 2
     293    }
     294    echo "%SERVICE_NAME% not running."
    206295    exit 3
    207296}
    208297
    209 # Gentoo/OpenRC perculiarity.
    210 if [ "$(which "${0}")" = "/sbin/rc" ]; then
    211     shift
    212 fi
    213 
    214 if [ "${1}" = "--lsb-functions" ]; then
    215     LSB_FUNCTIONS="${2}"
    216     shift 2
    217 fi
    218 
    219 case "${1}" in
     298test -z "${error}" || abort "${error}"
     299
     300case "${action}" in
    220301start)
     302    start;;
     303stop)
     304    stop;;
     305restart|force-reload)
    221306    start
    222     ;;
    223 stop)
    224     stop
    225     ;;
    226 restart|force-reload)
    227     stop
    228     start
    229     ;;
     307    stop;;
    230308condrestart|try-restart)
    231309    status || exit 0
    232310    stop
    233     start
    234     ;;
     311    start;;
    235312reload)
    236313    ;;
    237314status)
    238     status
    239     ;;
    240 *)
    241     echo "Usage: ${0} {start|stop|restart|status}"
    242     exit 1
     315    status;;
    243316esac
  • trunk/src/VBox/Installer/linux/testcase/Makefile.kmk

    r43688 r44049  
    4545tstHeadlessXOrg_SOURCES = tstHeadlessXOrg.sh
    4646
     47INSTALLS += tstInstallInit
     48TESTING += tstInstallInit
     49tstHeadlessXOrg_INST    = $(INST_TESTCASE)
     50tstHeadlessXOrg_MODE    = a+rx,u+w
     51tstHeadlessXOrg_SOURCES = tstInstallInit.sh
     52
    4753include $(FILE_KBUILD_SUB_FOOTER)
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