Avery Payne:
I have been giving the "one shot" question considerable thought.  I
have a
number of scripts that require this kind of behavior, so it's of great
interest to me.  The current methods that I have encountered are:

+ use a pause(1) command that simply sleeps forever on a subset of
signals,
then terminates; this effectively holds the script
+ as per discussion elsewhere on the mailing list, have the script send a
signal to itself to make it go to sleep (untested)

nosh has a built-in pause(1) command, created for this very purpose. It is used in run scripts created by convert-systemd-units if a systemd service unit has Type=oneshot and RemainAfterExit=false. However, nosh has a third option that you haven't listed.

If a systemd service unit has RemainAfterExit=true, irrespective of type, then instead convert-systemd-units makes use of the "run_on_empty" mechanism in service-manager(1), where a file named "remain" in the service/ directory causes the service manager not to automatically leave the RUNNING state when the daemon process exits. One sees this with the pre-supplied standard targets, which are in the running state but have no process ID:

JdeBP %systemctl status {basic,local-fs,multi-user,normal,server,sysinit,workstation,virtualbox}.target sshd.service
    /etc/system-manager/targets/basic: running 3d 4h 55m 12s ago
    /etc/system-manager/targets/local-fs: running 3d 4h 55m 17s ago
    /etc/system-manager/targets/multi-user: running 3d 4h 55m 11s ago
    /etc/system-manager/targets/normal: running 3d 4h 55m 11s ago
    /etc/system-manager/targets/server: running 3d 4h 55m 11s ago
    /etc/system-manager/targets/sysinit: running 3d 4h 55m 19s ago
    /etc/system-manager/targets/workstation: running 3d 4h 55m 11s ago
    /etc/system-manager/targets/virtualbox: running 3d 4h 55m 10s ago
    /var/sv/sshd: running (pid 220) 3d 4h 55m 49s ago
    JdeBP %

Reply via email to