I had lately a very unpleasant experience when I restarted an Asterisk instance after recompiling it.
As usual, I entered ‘service asterisk start’ on my console and quickly got a prompt back asking me for the next command to enter.
Then I type ‘rasterisk’ and got a scary ‘Could not connect to …’ reply.
I retried several times this ‘rasterisk’ command and constantly got the same error reply.
The reason why I couldn’t connect to Asterisk console was simply that Asterisk failed to start.
The reason why Asterisk failed to start is not important here as what matters for me is why would ‘service asterisk start’ apparently succeeds in the foreground when Asterisk fails to start in the background.
Ideally, I would prefer to use a command that takes a bit longer to run but would also alert me when something goes wrong before Asterisk considers itself to be ready.
Thinking back about, I’m realizing I use routinely this /usr/sbin/service (on Debian host) without knowing much about its origin, strengths or weaknesses.
Is there a better way to (re-)start Asterisk while being notified of any fatal error keeping it to reach the “Asterisk ready” stage ?
This current ‘service asterisk start; sleep 10; rasterisk’ process is not so bad interactively but when you need to script , something more atomic, that either fails or succeeds, may be better.
This is one of many reasons why systemd was created: service startup can be a complex thing, and many cases a robust mechanism is needed where the daemon can notify the service manager that it has successfully reached running status.
If you look at the Debian package for Asterisk, for example, it includes a suitable service definition in /usr/lib/systemd/system/asterisk.service, which contains the lines
The Debian Asterisk package has been built to call the systemd notification routine (“Type=notify” tells systemd it will do this) so that it can reliably report successful startup.
To me, a properly installed asterisk.service file is missing, right ?
Does it explain why a start failure was not reported when entering ‘service asterisk start’ or is it required to use ‘systemctl’ to get full reporting of such errors ?
Comparing this with other Asterisk instance, I see an asterisk.service file is missing on this specific Asterisk instance.
I copied such asterisk.service file from another box and I’ll restart Asterisk if this new asterisk.service which has a type=notify statement in its Service section brings the atomicity I’m looking for.