webmin / webmin

Powerful and flexible web-based server management control panel
http://www.webmin.com/
BSD 3-Clause "New" or "Revised" License
4.17k stars 631 forks source link

Cannot set `dbus` service to startup at boot time #2227

Closed shoulders closed 1 month ago

shoulders commented 1 month ago
SYSTEM INFORMATION
OS type and version Ubuntu Linux 22.04.4
Webmin version 2.111
Usermin version 2.010
Virtualmin version 7.20.1  
Theme version 21.10
Package updates All installed packages are up to date

the background

I was messing about trying to fix an the following issue with dbus

https://forum.virtualmin.com/t/resolvectl-sd-bus-open-system-no-such-file-or-directory/128058

the issue

I cannot use Webmin to re-enable the dbus service at startup

steps to reproduce

So you can see I cannot enable the service to start at boot with this method.

I also tried

I also tried editing dbus and then selecting Start at boot time which also had no effect

image

workaround

I opened up the terminal (in root mode) and ran

sudo systemctl enable dbus

This worked I now have my dbus back to start at boot

root@server:~# sudo systemctl enable dbus
Synchronizing state of dbus.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable dbus
The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the [Install] section, and DefaultInstance= for template
units). This means they are not meant to be enabled using systemctl.

Possible reasons for having this kind of units are:
• A unit may be statically enabled by being symlinked from another unit's
  .wants/ or .requires/ directory.
• A unit's purpose may be to act as a helper for some other unit which has
  a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
  D-Bus, udev, scripted systemctl call, ...).
• In case of template units, the unit is meant to be enabled with some
  instance name specified.
root@server:~# 

image

Proposed solution

Fix the commands that webmin is issuing to set a service to boot at startup

additional

I have not tried this on any other service becasue I don't know what is safe to stop and start

jcameron commented 1 month ago

That's funny, because Webmin already runs systemctl enable dbus to enable an action at boot time.

If go check Webmin -> Webmin Actions Log, what commands does it show are being run when you enable it in the Bootup and Shutdown module?

shoulders commented 1 month ago

That's funny, because Webmin already runs systemctl enable dbus to enable an action at boot time.

Mine on my dev site was not running for some reason. The startup on boot might be broken rather than it being a dbus thing.

jcameron commented 1 month ago

Does the file /etc/init.d/dbus exist on your system? That may be confusing webmin into thinking it's an old-style non-systemd service..

shoulders commented 1 month ago

on my dev site (the one that fails)

/etc/init.d/dbus exists, and content below

``` bash #!/bin/sh ### BEGIN INIT INFO # Provides: dbus # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: # Short-Description: D-Bus systemwide message bus # Description: D-Bus is a simple interprocess messaging system, used # for sending messages between applications. ### END INIT INFO # -*- coding: utf-8 -*- # Debian init.d script for D-BUS # Copyright © 2003 Colin Walters # Copyright © 2005 Sjoerd Simons set -e DAEMON=/usr/bin/dbus-daemon UUIDGEN=/usr/bin/dbus-uuidgen UUIDGEN_OPTS=--ensure NAME=dbus DAEMONUSER=messagebus PIDDIR=/var/run/dbus PIDFILE=$PIDDIR/pid DESC="system message bus" test -x $DAEMON || exit 0 . /lib/lsb/init-functions # Source defaults file; edit that file to configure this script. PARAMS="" if [ -e /etc/default/dbus ]; then . /etc/default/dbus fi create_machineid() { # Create machine-id file if [ -x $UUIDGEN ]; then $UUIDGEN $UUIDGEN_OPTS fi } start_it_up() { if [ ! -d $PIDDIR ]; then mkdir -p $PIDDIR chown $DAEMONUSER $PIDDIR chgrp $DAEMONUSER $PIDDIR fi if ! mountpoint -q /proc/ ; then log_failure_msg "Can't start $DESC - /proc is not mounted" return fi if [ -e $PIDFILE ]; then if $0 status > /dev/null ; then log_success_msg "$DESC already started; not starting." return else log_success_msg "Removing stale PID file $PIDFILE." rm -f $PIDFILE fi fi create_machineid # Force libnss-systemd to avoid trying to communicate via D-Bus, which # is never going to work well from within dbus-daemon. systemd # special-cases this internally, but we might need to do the same when # booting with sysvinit if libnss-systemd is still installed. # (Workaround for #940971) export SYSTEMD_NSS_BYPASS_BUS=1 log_daemon_msg "Starting $DESC" "$NAME" start-stop-daemon --start --quiet --pidfile $PIDFILE \ --exec $DAEMON -- --system $PARAMS log_end_msg $? } shut_it_down() { log_daemon_msg "Stopping $DESC" "$NAME" start-stop-daemon --stop --retry 5 --quiet --oknodo --pidfile $PIDFILE \ --user $DAEMONUSER # We no longer include these arguments so that start-stop-daemon # can do its job even given that we may have been upgraded. # We rely on the pidfile being sanely managed # --exec $DAEMON -- --system $PARAMS log_end_msg $? rm -f $PIDFILE } reload_it() { create_machineid log_action_begin_msg "Reloading $DESC config" dbus-send --print-reply --system --type=method_call \ --dest=org.freedesktop.DBus \ / org.freedesktop.DBus.ReloadConfig > /dev/null # hopefully this is enough time for dbus to reload it's config file. log_action_end_msg $? } case "$1" in start) start_it_up ;; stop) shut_it_down ;; reload|force-reload) reload_it ;; restart) shut_it_down start_it_up ;; status) status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $? ;; *) echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload|status}" >&2 exit 2 ;; esac ```

on my live site (this is fine, well it has never failed but I have never tried enabled/disable with it)

/etc/init.d/dbus exists, and content below

``` bash #!/bin/sh ### BEGIN INIT INFO # Provides: dbus # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: # Short-Description: D-Bus systemwide message bus # Description: D-Bus is a simple interprocess messaging system, used # for sending messages between applications. ### END INIT INFO # -*- coding: utf-8 -*- # Debian init.d script for D-BUS # Copyright © 2003 Colin Walters # Copyright © 2005 Sjoerd Simons set -e DAEMON=/usr/bin/dbus-daemon UUIDGEN=/usr/bin/dbus-uuidgen UUIDGEN_OPTS=--ensure NAME=dbus DAEMONUSER=messagebus PIDDIR=/var/run/dbus PIDFILE=$PIDDIR/pid DESC="system message bus" test -x $DAEMON || exit 0 . /lib/lsb/init-functions # Source defaults file; edit that file to configure this script. PARAMS="" if [ -e /etc/default/dbus ]; then . /etc/default/dbus fi create_machineid() { # Create machine-id file if [ -x $UUIDGEN ]; then $UUIDGEN $UUIDGEN_OPTS fi } start_it_up() { if [ ! -d $PIDDIR ]; then mkdir -p $PIDDIR chown $DAEMONUSER $PIDDIR chgrp $DAEMONUSER $PIDDIR fi if ! mountpoint -q /proc/ ; then log_failure_msg "Can't start $DESC - /proc is not mounted" return fi if [ -e $PIDFILE ]; then if $0 status > /dev/null ; then log_success_msg "$DESC already started; not starting." return else log_success_msg "Removing stale PID file $PIDFILE." rm -f $PIDFILE fi fi create_machineid # Force libnss-systemd to avoid trying to communicate via D-Bus, which # is never going to work well from within dbus-daemon. systemd # special-cases this internally, but we might need to do the same when # booting with sysvinit if libnss-systemd is still installed. # (Workaround for #940971) export SYSTEMD_NSS_BYPASS_BUS=1 log_daemon_msg "Starting $DESC" "$NAME" start-stop-daemon --start --quiet --pidfile $PIDFILE \ --exec $DAEMON -- --system $PARAMS log_end_msg $? } shut_it_down() { log_daemon_msg "Stopping $DESC" "$NAME" start-stop-daemon --stop --retry 5 --quiet --oknodo --pidfile $PIDFILE \ --user $DAEMONUSER # We no longer include these arguments so that start-stop-daemon # can do its job even given that we may have been upgraded. # We rely on the pidfile being sanely managed # --exec $DAEMON -- --system $PARAMS log_end_msg $? rm -f $PIDFILE } reload_it() { create_machineid log_action_begin_msg "Reloading $DESC config" dbus-send --print-reply --system --type=method_call \ --dest=org.freedesktop.DBus \ / org.freedesktop.DBus.ReloadConfig > /dev/null # hopefully this is enough time for dbus to reload it's config file. log_action_end_msg $? } case "$1" in start) start_it_up ;; stop) shut_it_down ;; reload|force-reload) reload_it ;; restart) shut_it_down start_it_up ;; status) status_of_proc -p $PIDFILE $DAEMON $NAME && exit 0 || exit $? ;; *) echo "Usage: /etc/init.d/$NAME {start|stop|reload|restart|force-reload|status}" >&2 exit 2 ;; esac ```

my thoughts

jcameron commented 1 month ago

Ok I dug into this some more - turns out that Webmin was showing both the dbus init.d script, and the dbus.service systemd action, even though they are the same thing! This will be fixed properly in the next release ..