VirtualBox

Changeset 98609 in vbox for trunk/src/VBox/Additions/linux


Ignore:
Timestamp:
Feb 16, 2023 4:33:36 PM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
155901
Message:

Additions: Linux: rcvboxadd: Introduce "status-kernel" and "status-user" actions, bugref:10359.

"rcvboxadd status-kernel" is intended to verify if Guest Additions kernel modules are currently
loaded and running versions do match to Guest Additions installation version.

"rcvboxadd status-user" is intended to verify if user-space processes are currently running. At
the moment only checks if VBoxService is running, can be extended later on.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/linux/installer/vboxadd.sh

    r98595 r98609  
    176176}
    177177
     178running_module()
     179{
     180    lsmod | grep -q $1
     181}
     182
    178183# Get version string of currently running kernel module.
    179184running_module_version()
     
    199204
    200205    [ "$expected" = "$(running_module_version "$mod")" ] || return
     206}
     207
     208# A wrapper for check_running_module_version.
     209# Go through the list of Guest Additions' modules and
     210# verify if they are loaded and running version matches
     211# to current installation version. Skip vboxvideo since
     212# it is not loaded for old guests.
     213check_status_kernel()
     214{
     215    for mod in vboxguest vboxsf; do
     216        running_module "$mod" || fail "module $mod not loaded"
     217        check_running_module_version "$mod" || fail "currently loaded module $mod version ($(running_module_version "$mod")) does not match to VirtualBox Guest Additions installation version ($VBOX_VERSION $VBOX_REVISION)"
     218    done
     219}
     220
     221# Checks if systemctl is present and functional (i.e., systemd is the init process).
     222use_systemd()
     223{
     224    systemctl status >/dev/null 2>&1
     225}
     226
     227## Did we install a systemd service?
     228systemd_service_installed()
     229{
     230    ## Name of service to test.
     231    name="${1}"
     232
     233    test -f /lib/systemd/system/"${name}".service ||
     234        test -f /usr/lib/systemd/system/"${name}".service
     235}
     236
     237## Perform an action on a service
     238do_sysvinit_action()
     239{
     240    ## Name of service to start.
     241    name="${1}"
     242    ## The action to perform, normally "start", "stop" or "status".
     243    action="${2}"
     244
     245    if use_systemd -a systemd_service_installed "${name}"; then
     246        systemctl -q ${action} "${name}"
     247    elif test -x "/etc/rc.d/init.d/${name}"; then
     248        "/etc/rc.d/init.d/${name}" "${action}" quiet
     249    elif test -x "/etc/init.d/${name}"; then
     250        "/etc/init.d/${name}" "${action}" quiet
     251    fi
     252}
     253
     254# Check whether user-land processes are running.
     255# Currently only check for VBoxService.
     256check_status_user()
     257{
     258    do_sysvinit_action vboxadd-service status >/dev/null 2>&1
    201259}
    202260
     
    645703}
    646704
    647 
    648705# Returns "1" if module is signed and signature can be verified
    649706# with public key provided in DEB_PUB_KEY. Or empty string otherwise.
     
    889946}
    890947
    891 # Checks if systemctl is present and functional (i.e., systemd is the init process).
    892 use_systemd()
    893 {
    894     systemctl status >/dev/null 2>&1
    895 }
    896 
    897 ## Did we install a systemd service?
    898 systemd_service_installed()
    899 {
    900     ## Name of service to test.
    901     name="${1}"
    902 
    903     test -f /lib/systemd/system/"${name}".service ||
    904         test -f /usr/lib/systemd/system/"${name}".service
    905 }
    906 
    907 ## Perform an action on a service
    908 do_sysvinit_action()
    909 {
    910     ## Name of service to start.
    911     name="${1}"
    912     ## The action to perform, normally "start", "stop" or "status".
    913     action="${2}"
    914 
    915     if use_systemd -a systemd_service_installed "${name}"; then
    916         systemctl -q ${action} "${name}"
    917     elif test -x "/etc/rc.d/init.d/${name}"; then
    918         "/etc/rc.d/init.d/${name}" "${action}" quiet
    919     elif test -x "/etc/init.d/${name}"; then
    920         "/etc/init.d/${name}" "${action}" quiet
    921     fi
    922 }
    923 
    924948# Check if process with this PID is running.
    925949check_pid()
     
    10471071    if [ $? -eq 0 ]; then
    10481072
    1049         # Check if we just loaded modules of correct version. Skip vboxvideo
    1050         # since it's not loaded for very old guests.
    1051         for mod in vboxguest vboxsf; do
    1052             check_running_module_version "$mod" || fail "currently loaded module $mod version ($(running_module_version "$mod")) does not match to VirtualBox Guest Additions installation version ($VBOX_VERSION $VBOX_REVISION)"
    1053         done
     1073        # Check if we just loaded modules of correct version.
     1074        check_status_kernel
     1075
     1076        # Check if user-land processes were restarted as well.
     1077        check_status_user
     1078
    10541079        # Take reported version of running Guest Additions from running vboxguest module (as a paranoia check).
    10551080        info "kernel modules and services $(running_module_version "vboxguest") reloaded"
     
    11191144    dmnstatus
    11201145    ;;
     1146status-kernel)
     1147    check_status_kernel && info "Kernel modules are loaded"
     1148    ;;
     1149status-user)
     1150    check_status_user
     1151    if [ $? -eq 0 ]; then
     1152        info "User-land services are running"
     1153    else
     1154        fail "User-land services are not running"
     1155    fi
     1156    ;;
    11211157*)
    1122     echo "Usage: $0 {start|stop|restart|reload|status|setup|quicksetup|cleanup} [quiet]"
     1158    echo "Usage: $0 {start|stop|restart|reload|status|status-kernel|status-user|setup|quicksetup|cleanup} [quiet]"
    11231159    exit 1
    11241160esac
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