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.
More on Processes, services and systemd
Your team has a Python API that someone starts with `nohup python app.py &`. Make it a proper service running as a non-root user.BeginnerThe service you created must bind to port 443, but it runs as a non-root user. How?BeginnerYou need to change one setting (memory limit) in a vendor-supplied unit file without editing it. How?BeginnerA service depends on a database on the same host and fails at boot because the DB isn't ready. How do you fix the ordering?IntermediateA service keeps crashing and systemd stops restarting it after a few attempts. How do you tune this?IntermediateA long-running app must reload its config without dropping connections. How do you wire this into systemd?Intermediate