Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run_once: execute /boot/run_once when booting #40

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions debian/raspberrypi-sys-mods.run_once.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This unit is heavily inspired by Ned McClain's ideas found in https://github.com/nmcclain/raspberian-firstboot
[Unit]
Description=run_once initialization
After=network.target

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per nmcclain/raspberian-firstboot#13 ...

Update After=network.target to include apt-daily.service and apt-daily-upgrade.service

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable

How does this behave on a system without network connectivity?

Copy link
Contributor

@MichaIng MichaIng Jun 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EDIT: Lol, now I see the comment was more about the unattended upgrade services 😄. I wonder if they have any effect since those services are not "enabled" to be started by systemd at boot, but they are started by their respective systemd timers. As such, AFAIK they cannot be used for boot ordering at all, but I have not tested it.


network.target is a passive unit, hence it has no meaning unless a network stack/provider gives it one (sorts itself Before=network.target). In case of Raspbian/Debian (Raspberry Pi OS), this is most of all the networking.service from the ifupdown package, which brings up the loopback interface and other manually configured auto <iface> interfaces. Theoretically it's as well the ifup@<iface>.service's, which are created for allow-hotplug <iface> interfaces, but since this unit is of Type=simple, they don't need to finish but only need to start (hence do not delay the target to be reached, even if e.g. DHCP or wpa_supplicant hangs or fails).

dhcpcd does NOT have any effect on this target, which is strange and somehow a problem since Raspberry Pi OS uses it for network configuration by default 🤔.

So if no network is configured, the target is reached once the loopback interface is available. If a network is configured, it depends on the network stack, but the way Raspberry Pi OS is configured, no additional delay happens.

Btw, network.target is not intended to indicate that the device is online. For this, network-online.target is intended. Since it is an active target, it needs to be pulled it:

Wants=network-online.target
After=network-online.target

But currently (with the current network stacks) it has not the intended meaning but is reached simply immediately after network.target.

More info: https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/

  • But it has to be taken care since there is quite some discrepancy between the intended meaning by systemd and the actual meaning on the system, which depends on network stack and consumer services.
  • The effective meaning can be best seen with:
    systemctl show -p Before,After network.target network-online.target

Before=rc-local.service

ConditionFileNotEmpty=/boot/run_once
ConditionFileIsExecutable=/boot/run_once
ConditionPathIsReadWrite=/boot

[Service]
ExecStart=/boot/run_once
ExecStartPost=/bin/mv /boot/run_once /boot/run_once.${INVOCATION_ID}
Type=oneshot
RemainAfterExit=no

[Install]
WantedBy=multi-user.target
3 changes: 3 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,22 @@ include /usr/share/dpkg/default.mk
override_dh_installinit:
dh_installinit --name=rpi-display-backlight --no-stop-on-upgrade --no-start
dh_installinit --name=sshswitch
dh_installinit --name=run_once
dh_installinit --name=apply_noobs_os_config --no-stop-on-upgrade --no-start
dh_installinit --name=regenerate_ssh_host_keys --no-stop-on-upgrade --no-start
dh_installinit --name=wifi-country --no-stop-on-upgrade --no-start

override_dh_systemd_enable:
dh_systemd_enable --name=rpi-display-backlight
dh_systemd_enable --name=sshswitch
dh_systemd_enable --name=run_once
dh_systemd_enable --name=apply_noobs_os_config --no-enable
dh_systemd_enable --name=regenerate_ssh_host_keys --no-enable
dh_systemd_enable --name=wifi-country

override_dh_systemd_start:
dh_systemd_start --name=sshswitch --no-start
dh_systemd_start --name=run_once --no-start
dh_systemd_start --name=apply_noobs_os_config --no-start
dh_systemd_start --name=regenerate_ssh_host_keys --no-start
dh_systemd_start --name=wifi-country --no-start