Interview Prep/Linux/Processes, services and systemd

A script needs to run once at boot after networking, then exit. How do you do it with systemd?

BeginnerScenarioProcesses, services and systemd
Answer

Situation read → A oneshot unit.

What I'd do →

[Unit]
Description=Register node at boot
After=network-online.target
Wants=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/register-node.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Enable it with systemctl enable register-node.

Why → Type=oneshot makes systemd wait for completion; RemainAfterExit keeps it "active" so dependents see it as done.

Interview tip → Prefer this over /etc/rc.local, which many distros no longer run by default.

All Linux questions Roadmap: Linux

More on Processes, services and systemd