fritzcollectd icon indicating copy to clipboard operation
fritzcollectd copied to clipboard

collectd startup too early, network error

Open Bensge opened this issue 3 years ago • 1 comments

When my Raspberry PI 4 boots up, during the collectdstartup, the fritzcolltectd plugin chokes on the network because it doesn't appear to be connected yet. When I restart collectd manually, it works great. Is this problem known and are there any solutions to delay the startup until the network is ready?

Cheers, Benno

● collectd.service - Statistics collection and monitoring daemon
   Loaded: loaded (/lib/systemd/system/collectd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-12-17 08:47:08 CET; 7h ago
     Docs: man:collectd(1)
           man:collectd.conf(5)
           https://collectd.org
  Process: 475 ExecStartPre=/usr/sbin/collectd -t (code=exited, status=0/SUCCESS)
 Main PID: 484 (collectd)
    Tasks: 11 (limit: 3861)
   CGroup: /system.slice/collectd.service
           └─484 /usr/sbin/collectd

Dez 17 08:46:48 raspi4 collectd[484]: plugin_load: plugin "network" successfully loaded.
Dez 17 08:47:07 raspi4 collectd[484]: Systemd detected, trying to signal readyness.
Dez 17 08:47:08 raspi4 systemd[1]: Started Statistics collection and monitoring daemon.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Dez 17 08:47:13 raspi4 collectd[484]: Unhandled python exception in init callback: IOError: fritzcollectd: Failed to connect to 192.168.178.1
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Dez 17 08:47:13 raspi4 collectd[484]: Initialization complete, entering read-loop.

Bensge avatar Dec 17 '20 15:12 Bensge

You can restart the collectd service 5 minutes after the server had started booted. Assuming the network is up by then...

# @doc https://wiki.archlinux.org/index.php/Systemd/Timers
# Config
MYFILE=/etc/systemd/system/mjd-restart-collectd-after-lan-connected.timer
cat << 'THETEXTBLOCK' > ${MYFILE}
    # A timer which will trigger ONCE, {x} minutes after the machine was booted.
    [Unit]
    Description=(timer)mjd-restart-collectd-after-lan-connected
    [Timer]
    OnBootSec=5min
    [Install]
    WantedBy=timers.target
THETEXTBLOCK
cat ${MYFILE}
ll  ${MYFILE}
MYFILE=/etc/systemd/system/mjd-restart-collectd-after-lan-connected.service
cat << 'THETEXTBLOCK' > ${MYFILE}
    # The .service file does not require an [Install] section as it is controlled by the related timer unit.
    [Unit]
    Description=mjd-restart-collectd-after-lan-connected
    [Service]
    Type=oneshot
    ExecStart=/bin/sh -ec "systemctl restart collectd; systemctl status collectd"
THETEXTBLOCK
cat ${MYFILE}
ll  ${MYFILE}
# ENABLE AT BOOT
MYUNIT=mjd-restart-collectd-after-lan-connected
MYSERVICE=${MYUNIT}.service
MYTIMER=${MYUNIT}.timer
systemctl enable ${MYTIMER};
systemctl status ${MYTIMER};

pantaluna avatar Jul 15 '23 13:07 pantaluna