[asterisk-users] Backport of Stretch's asterisk.service file into Jessie: successful start not detected by systemd

Tzafrir Cohen tzafrir.cohen at xorcom.com
Thu Apr 20 05:48:38 CDT 2017


On Thu, Apr 20, 2017 at 12:02:36PM +0200, Olivier wrote:
> Hello,
> 
> I've been tasked to enable automatic Asterisk restart on failure on a
> Jessie platform (running latest Asterisk 13.15.0).
> 
> I build a dedicated Jessie VM on which I installed Asterisk from source.
> I configured a couple of files in /etc/asterisk directory.
> I positively checedk that with simple config, Asterisk could sucessively
> start using an /etc/init.d/asterisk file and sysv-systemd compatibility
> tools.
> 
> Then I copied a /etc/systemd/system/asterisk.service file with the
> following content:

[snip]

> [Service]
> Type=notify

[snip]

> After creating above asterisk.service file, running "systemctl
> daemon-reload" and "systemctl start asterisk", I could observe:
> - asterisk is starting OK,
> - asterisk prints to its log file a line such as:
> [Apr 20 11:23:22] VERBOSE[770] asterisk.c: Asterisk Ready.
> 
> but, at the same time, I got:
> april 20 11:23:22 jessievm asterisk[770]: [Apr 20 11:23:22] NOTICE[770]:
> app_queue.c:9095 reload_queues: No call queueing config fil
> april 20 11:24:48 jessievm systemd[1]: asterisk.service start operation
> timed out. Terminating.
> april 20 11:24:48 jessievm asterisk[770]:
> april 20 11:24:48 jessievm systemd[1]: Failed to start Asterisk PBX.

'Type=notify' means that the service is only considered ready once is
notifies systemd so through a special socket, using sd_notify(3). You
told systemd that Asterisk will notify it when ready, but Asterisk never
did. Thus systemd decided that service has failed.

Make sure you have libsystemd-dev installed. Alternatively, remove that
line (to keep the default Type=simple).

When built with systemd support, asterisk updates systemd about its
status using sd_notify(). This means that it is only considered as
started when it has loaded all the modules. This can make startup
ordering simpler.

BTW: if anybody wants, you can use sd_notify to set the status (as shown
in 'systemctl status asterisk.service') to an arbitrary string.
Basically just use ast_sd_notify() anywhere in the code. It becomes a
no-op if there's no systemd support.

-- 
               Tzafrir Cohen
+972-50-7952406           mailto:tzafrir.cohen at xorcom.com
http://www.xorcom.com



More information about the asterisk-users mailing list