Olivier
2017-Apr-20 10:02 UTC
[asterisk-users] Backport of Stretch's asterisk.service file into Jessie: successful start not detected by systemd
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: [Unit] Description=Asterisk PBX Documentation=man:asterisk(8) Wants=network-online.target After=network-online.target [Service] Type=notify ExecStart=/usr/sbin/asterisk -g -f -U asterisk ExecReload=/usr/sbin/asterisk -rx 'core reload' Restart=no RestartSec=1 WorkingDirectory=/var/lib/asterisk [Install] WantedBy=multi-user.target Please, note that this file has the same content as file /lib/systemd/system/asterisk.service in Debian Stretch expect for line Restart=on-failure I changed to Restart=no, for the moment. 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. If I'm not mistaken: - lastest "Asterisk Ready" line is visible in /var/log/asterisk/full but invisible in Systemd journal, - things work as if Systemd was not notified of Asterisk successful start and than decided to stop Asterisk, - man page [1] mentions support of type=notify in Debian Jessie - on Stretch, I used asterisk 13.14.0 while I used asterisk 13.15.0, so I supposed this issue doesn't come from Asterisk itself but the way I configured my system. Systemd versions are: Jessie: systemd 215 +PAM +AUDIT +SELINUX +IMA +SYSVINIT +LIBCRYPTSETUP +GCRYPT +ACL +XZ -SECCOMP -APPARMOR Stretch: systemd 232 +PAM +AUDIT +SELINUX +IMA +APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN My questions are: 1. Is it possible to use systemd's Restart=on-failure option to automaticaly restart Asterisk, given Jessie systemd version ? 2. If positive, how ? 3. If negative, which option would you recommend (Monit ? ) ? Best regards [1] https://manpages.debian.org/jessie/systemd/systemd.service.5.en.html -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20170420/d41e6bc6/attachment.html>
Tzafrir Cohen
2017-Apr-20 10:48 UTC
[asterisk-users] Backport of Stretch's asterisk.service file into Jessie: successful start not detected by systemd
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