service management and upgrades

From: <marco+freebsd_at_crowdsec.net>
Date: Fri, 21 Jan 2022 09:03:59 UTC
Hello!

I have a doubt about service management in the context of my ports.

We develop a couple of daemons, we can call them agent and bouncer.
They work in cooperation and the pkg-message explains how to enable and run
them
(sysrc <name>_enable="YES"; service <name> start).

My question is: in case of package removal, do I need to stop the services
myself?
I suppose yes, so I have put a "service <name> stop" in pkg-deinstall.in,
otherwise the daemons keep running after their executable and configuration
files are removed.

The problem comes with package upgrades - as far as I know I have no way to
tell a deinstall from an upgrade, so I cannot restart the dead service in
the new post-install function.
This means every time a package is upgraded, its application has to be
restarted by the user (and if the agent goes down, soon the bouncer will go
down too).

If the above is correct I can live with that, even if it requires manual
intervention.

But now a third player comes to the field: I have an OPNsense plugin that
uses the above two services. It depends on them at installation time, and
it takes care of enabling and starting/stopping them. So far so good.

What happens if the agent or the bouncer are upgraded and therefore stopped?
The OPNsense plugin has no way to know that they are down and must be
restarted.

The only solution I found (but not applied yet) is putting this on the
pkg-install of the agent and bouncer: "service <name> enabled && service
<name> start".
I have found nothing of the sort in the port repository, the post-install
is usually for configuration and does not run services.

What am I missing or doing wrong?

Thank you for your time and suggestions.