davmac314 / dinit

Service monitoring / "init" system
Apache License 2.0
582 stars 45 forks source link

Retrying scripts? #308

Closed IngwiePhoenix closed 5 months ago

IngwiePhoenix commented 5 months ago

Hello there!

So I was logged into my TV today because I wanted to check my kernel version due to the recent exploits going around, especially this week, and find out just which one it ran, out of curiosity, if it could be helpful in jailbreaking others of the same firmware version or alike. But, while I was there, I looked at my dinit, and I saw this:

# dinitctl list
[[+]     ] boot
[     {X}] rclone-mount-nas (exit status: 1)
[{+}     ] prep-rclone-mount-nas
[     {X}] rclone-serve-ftp
[     {X}] mount-usb (signal: 15)
[{+}     ] run-mount-usb
[{+}     ] prep-mount-usb
[     {X}] syncthing

This was as expected; mounting the USB drive did not work as intended, possibly because of a timing from when in the init chain the dinit service starts (WebOS inits with systemd first but launches Luna, which launches other services, of which one is the Homebrew Launcher, which in return does a run-parts on a directory of which one is my dinit "service"). So chances are, sometimes, when dinit starts, the mounting script might fail because it runs too early.

For reference, here are the units:

root@LGwebOSTV:~/dinit.d# cat prep-mount-usb
type = scripted
command = /bin/mkdir -p /tmp/usb/sda/sda1
root@LGwebOSTV:~/dinit.d# cat run-mount-usb
type = scripted
command = /bin/mount /dev/sda1 /tmp/usb/sda/sda1
working-dir = /home/root
depends-on = prep-mount-usb
root@LGwebOSTV:~/dinit.d# cat mount-usb
type = process
command = /bin/sh -c "watch -t -n 0.5 -e mountpoint -q /tmp/usb/sda/sda1 < /dev/null"
depends-on = run-mount-usb

Syncthing and the rclone FTP server rely on the USB stick being recognized, so naturally they failed to start - no surprises there. The NAS didn't mount because I forgot to change the IP, oops.

Now, when this mis-timing happens, all it would take is to just re-run the chain from the start again, so that Syncthing and rclone can launch.

What would be the best way to implement a "retry" here?

Kind regards, Ingwie

PS.: That super long watch-command was an absolute brainfart but the best I could come up with to monitor if it was still mounted or not - and if not, cause the dependees to exit too, if they hadn't already.