It starts OK but does not restart properly, because kill signal returns imediately, but shutdown of the deamon takes longer time and thus start attempt failed to bind on already opened socket # service amavis-p0fanalyzer restart Binding to socket [::1]:2345 failed (using IO::Socket::IP): Address already in use at /usr/local/sbin/p0f-analyzer.pl line 375. p0fanalyzer_stop() should be changed to wait till daemon really die. And should check if daemon is runnig and PID file exists, because second attempt to (re)start p0f emits this error: # service amavis-p0fanalyzer restart cat: /var/run/p0fanalyzer2.pid: No such file or directory usage: kill [-s signal_name] pid ... kill -l [exit_status] kill -signal_name pid ... kill -signal_number pid ... cat: /var/run/p0fanalyzer1.pid: No such file or directory usage: kill [-s signal_name] pid ... kill -l [exit_status] kill -signal_name pid ... kill -signal_number pid ... This error can be fixed by this simple change: p0fanalyzer_stop() { test -s ${amavis_p0fanalyzer_pidfile2} && /bin/kill `cat ${amavis_p0fanalyzer_pidfile2}` && rm ${amavis_p0fanalyzer_pidfile2} test -s ${amavis_p0fanalyzer_pidfile1} && /bin/kill `cat ${amavis_p0fanalyzer_pidfile1}` && rm ${amavis_p0fanalyzer_pidfile1} } I don't know how to handle the first problem with slowly dying daemon. Also I am not sure if there must be the "rm" part in p0fanalyzer_stop() function, because man daemon says that the pid file will be removed. cite: The program is executed in a spawned child process while the daemon waits until it terminates to keep the child_pidfile locked and removes it after the process exits.
Can somebody take a look at this annoying problems? The second problem with trying to kill with empty PID is really easily fixable. The next thing I really would like is to implement "status" command for this rc script. Almost all daemons provide this command to check if daemon is running or not.
Created attachment 172507 [details] check if PID file exists Check if PID file exists and do not use "rm" to remove it - is removed automatically by daemon.
Created attachment 176835 [details] check if PID file exists before use it to kill
A commit references this bug: Author: flo Date: Tue Dec 13 14:52:24 UTC 2016 New revision: 428490 URL: https://svnweb.freebsd.org/changeset/ports/428490 Log: - fix clamd socket file location in default config file [1] - prevent error messages from amavisd-p0fanalyzer rc script [2] - add a patch to fix dkim siging that was broken in 2.11.0 [3] PR: 200036 [1], 209038 [2], 214202 [3] Submitted by: barnerd [1] Miroslav Lachman <000.fbsd@quip.cz> [2] ari@stonepile.fi [3] Changes: head/security/amavisd-new/Makefile head/security/amavisd-new/files/amavis-p0fanalyzer.in head/security/amavisd-new/files/patch-amavisd
Committed. Thanks.