I'm using s6 (http://skarnet.org/software/s6/) in order to supervise processes.
I have this working well for hundreds of processes across dozens of docker instances and servers. I have a new problem on an otherwise stable system.
I set up a service for ClamAV and in /etc/services.d/clamv/run I start the process with:
exec s6-setuidgid clamav /opt/clamd
It starts up, but clam has a long startup cycle and after about one minute 20 seconds (presumably when it completes loading the database) S6 starts another instance of clam. I can see them with ps:
2286 clamav 0:00 /opt/clamd
5091 clamav 0:58 /opt/clamd
After that has completed loading, the second instance tries to use the socket and triggers an error:
Socket file /run/clamav/clamd.sock is in use by another process
Interestingly, using ps aux - the TIME colum for the first process increases to 1:18 and then returns to zero - and the second instance then counts up in the same way.
If I leave it running, when the second process has completed startup, s6 appears to attempt to start another - though curiously, no additional processes appear using ps aux.
I have confirmed that clam only creates the sock and pid files after the long startup.
Obvious question - how do I fix this so that s6 does not start a second instance at the end of the long startup.