#!/bin/sh # # VirtualBox generic init script. # # Copyright (C) 2012-2013 Oracle Corporation # # This file is part of VirtualBox Open Source Edition (OSE), as # available from http://www.virtualbox.org. This file is free software; # you can redistribute it and/or modify it under the terms of the GNU # General Public License (GPL) as published by the Free Software # Foundation, in version 2 as it comes in the "COPYING" file of the # VirtualBox OSE distribution. VirtualBox OSE is distributed in the # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind. # ### BEGIN INIT INFO # Required-Start: $local_fs # Should-Start: $syslog # Required-Stop: $local_fs # Should-Stop: $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: %DESCRIPTION% ### END INIT INFO ## @todo We should really replace the daemon starting, stopping and checking # code with a tool of our own written in C, which we could always use # instead of the LSB functions. cr=" " tab=" " IFS=" ${cr}${tab}" 'unset' -f unalias 'unalias' -a unset -f command PATH=/bin:/sbin:/usr/bin:/usr/sbin:$PATH ## A generic service script which can be used, after substituting some place- # holders with service-specific values, to run most services on LSB, System V # or BSD-compatible service management systems. As we control both the service # code and the init script we try to push as much as possible of the logic into # the service and out of the very system-dependent service configuration # scripts and files. See the help text of the "install_service.sh" helper # script for more details. # # Furthermore, to simplify deployment, we will install all init scripts using # this generic template manually during the post install phase or at run time # using LSB functions if they are available (as they should be on most common # modern distributions) or manually placing the file in the appropriate # directory and creating symbolic links on System V or writing to rc.local on # BSD-compatible systems. Systems requiring different treatment will be added # here when we add support for them, but we will try to keep everything as # generic as we can. # # In general, we try to behave as natively as we reasonably can on the most # important target systems we support and to work well enough on as many others # as possible, but in particular without trying to look perfectly native. # # See the inline documentation in the code for generate_service_file for # details of the generation process. ## Time out in seconds when shutting down the service. SHUT_DOWN_TIME_OUT=5 ## If this is set to an empty value then the LSB init functions will not be # used. This is intended for testing the fallback commands. LSB_FUNCTIONS="/lib/lsb/init-functions" # Silently exit if the package was uninstalled but not purged. test -r %COMMAND% || exit 0 ## The function definition at the start of every non-trivial shell script! abort() { log_failure_msg "$*" exit 1 } ## Exit successfully. do_success() { log_success_msg "%DESCRIPTION% successfully started." exit 0 } ## Set the error message. set_error() { test -z "${error}" && error="${1}" } # Gentoo/OpenRC perculiarity. if test "x${0}" = "x/sbin/rc" || test "x${0}" = "xrc"; then shift fi # Process arguments. action="" error="" prefix="/var" while test x"${#}" != "x0"; do case "${1}" in --lsb-functions) test x"${#}" = "x1" && set_error "${1}: missing argument." LSB_FUNCTIONS="${2}" shift 2;; --prefix) test x"${#}" = "x1" && set_error "${1}: missing argument." prefix="${2}" shift 2;; --help) cat << EOF Usage: ${0} {start|stop|restart|status} [] start|stop|restart|status Start/stop/restart/report status for the service. Options: --lsb-functions