VirtualBox

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


Ignore:
Timestamp:
Jul 8, 2015 9:01:47 AM (10 years ago)
Author:
vboxsync
Message:

Installers/linux: support systemd.

File:
1 edited

Legend:

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

    r56842 r56850  
    185185}
    186186
     187## Creates a systemd wrapper in /lib for an LSB init script
     188systemd_wrap_init_script()
     189{
     190    self="systemd_wrap_init_script"
     191    ## The init script to be installed.  The file may be copied or referenced.
     192    script="$(readlink -f -- "${1}")"
     193    ## Name for the service.
     194    name="$2"
     195    test -x "$script" && test ! "$name" = "" || \
     196        { log "$self: invalid arguments" && return 1; }
     197    test -d /usr/lib/systemd/system && unit_path=/usr/lib/systemd/system
     198    test -d /lib/systemd/system && unit_path=/lib/systemd/system
     199    test -n "${unit_path}" || \
     200        { log "$self: systemd unit path not found" && return 1; }
     201    description=`sed -n 's/# *Description: *\(.*\)/\1/p' "${script}"`
     202    required=`sed -n 's/# *Required-Start: *\(.*\)/\1/p' "${script}"`
     203    runlevels=`sed -n 's/# *Default-Start: *\(.*\)/\1/p' "${script}"`
     204    before=`for i in ${runlevels}; do printf "runlevel${i}.target "; done`
     205    after=`for i in ${required}; do printf "${i}.service "; done`
     206    cat > "${unit_path}/${name}.service" << EOF
     207[Unit]
     208SourcePath=${script}
     209Description=${description}
     210Before=${before}shutdown.target
     211After=${after}
     212Conflicts=shutdown.target
     213
     214[Service]
     215Type=forking
     216Restart=no
     217TimeoutSec=5min
     218IgnoreSIGPIPE=no
     219KillMode=process
     220GuessMainPID=no
     221RemainAfterExit=yes
     222ExecStart=${script} start
     223ExecStop=${script} stop
     224EOF
     225}
     226
    187227## Installs a file containing a shell script as an init script
    188228install_init_script()
     
    195235    test -x "$script" && test ! "$name" = "" || \
    196236        { log "$self: invalid arguments" && return 1; }
     237    test -d /lib/systemd/system || test -d /usr/lib/systemd/system && systemd_wrap_init_script "$script" "$name"
    197238    if test -d /etc/rc.d/init.d
    198239    then
     
    203244        cp "$script" "/etc/init.d/$name" 2> /dev/null
    204245        chmod 755 "/etc/init.d/$name" 2> /dev/null
    205     else
    206         log "${self}: error: unknown init type"
    207         return 1
    208246    fi
    209247    return 0
     
    218256    test ! "$name" = "" || \
    219257        { log "$self: missing argument" && return 1; }
     258    rm -f /lib/systemd/system/"$name".service /usr/lib/systemd/system/"$name".service
    220259    if test -d /etc/rc.d/init.d
    221260    then
     
    224263    then
    225264        rm -f "/etc/init.d/$name" > /dev/null 2>&1
    226     else
    227         log "${self}: error: unknown init type"
    228         return 1
    229265    fi
    230266    return 0
     
    241277    test ! -z "${name}" && test ! -z "${action}" || \
    242278        { log "${self}: missing argument" && return 1; }
    243     if test -x "/etc/rc.d/init.d/${name}"
    244     then
    245         script="/etc/rc.d/init.d/${name}"
    246     elif test -x "/etc/init.d/${name}"
    247     then
    248         script="/etc/init.d/${name}"
    249     else
    250         log "${self}: error: unknown init type or unknown service ${name}"
    251         return 1
    252     fi
    253     if test -x "`which service 2>/dev/null`"
     279    if test -x "`which systemctl 2>/dev/null`"
     280    then
     281        systemctl ${action} "${name}"
     282    elif test -x "`which service 2>/dev/null`"
    254283    then
    255284        service "${name}" ${action}
     
    257286    then
    258287        invoke-rc.d "${name}" ${action}
    259     else
    260         "${script}" "${action}"
     288    elif test -x "/etc/rc.d/init.d/${name}"
     289    then
     290        "/etc/rc.d/init.d/${name}" "${action}"
     291    elif test -x "/etc/init.d/${name}"
     292    then
     293        "/etc/init.d/${name}" "${action}"
    261294    fi
    262295}
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