Running Duplicati on startup on Freenas / FreeBSD

Unfortunately there’s nothing in that script that stops Duplicati directly, so there’s not much I can point to. FreeBSD (and I’m not sure about FreeNAS, if it’s different) does have good documentation, for example:

Practical rc.d scripting in BSD
rc
rc.subr

Duplicati does not appear to ship a package for FreeNAS or FreeBSD. Are you running somebody’s port?
One view of this is that it’s a porting issue. Another is Duplicati Server should support normal conventions, instead of requiring odd shutdown steps like having to kill the child process instead of the original process. FreeBSD’s rc framework almost certainly is killing the parent. Could you search issues and (if needed) file:

Meanwhile, workarounds might include studying the rc mechanism enough to see what can be overridden, attempting to turn the standard stop into the sort of custom stop that the Synology script got. The BSD rc system does seem to allow more complex rc scripts than the sort of stub you posted, but it’s not clear what limits there might be. In any case, you might want to model the custom code as a one-off of standard code.

Possibly the easiest thing to do is to wrap whatever is finally launching Duplicati with an additional script to make it behave more conventionally, e.g. when it starts it can record its own PID file, and to stop it can use something like a trap command in bash to catch SIGTERM or whatever, and kill the Duplicati child in one of the mentioned ways. Of course, the script must pass supplied arguments through, for example using “$@”.

There’s probably no urgent need to save the PID on disk and exec. You could maybe just let the new script act as the revised duplicati_command (with better signal handling) that hangs around to track the real one. Possibly all of the processes will even land in the same process group (ps can say), making multi-kills easy.

Another possible approach is to see if you can switch from an rc.subr pidfile approach to a procname one, which looks like it has the potential of either finding the child or finding all of the duplicati server processes.

Please also search the forum and GitHub issues to see if any other thoughts come up. I didn’t do that yet…