Asterisk 18.1 Problems with systemd

First off I’m new to Asterisk 18 and new to systemd.
I have years working with older Asterisk versions (up to 16) and WITHOUT systemd
This is my first attempt in a couple of years to try newer stuff.
And naturally it feels buggy and like “nothing works”.
:slight_smile:

I am simply trying to get a fresh out of the box build of Asterisk 18.1 to start and stop with systemd.

Asterisk starts and stops just fine at the command prompt without systemd.

However if I try a “sysctl start asterisk”
It just hangs and I never get the command prompt back.

Asterisk itself appears to start and run + proecess a local test SIP call however asterisk -r does not work
I Get: Unable to connect to remote asterisk (does /var/run/asterisk/asterisk.ctl exist?)

Looking at /lib/systemd/system/asterisk.service

[Unit]
Description=Asterisk PBX and telephony daemon.
After=network.target

[Service]
Type=notify
Environment=HOME=/var/lib/asterisk
WorkingDirectory=/var/lib/asterisk
User=asterisk
Group=asterisk
ExecStart=/usr/sbin/asterisk -mqf -C /etc/asterisk/asterisk.conf
ExecReload=/usr/sbin/asterisk -rx ‘core reload’

What is created by asterisk build and install has “Type=Notify”

If I change this to “Type=simple”

In now works as in I can start and stop it.

I do not know the different between “Notify” and “simple”

And I do not know why the Asterisk build and install set it to “Notify”
And what I have broken or what I lose by changing it to “simple”

Or how to fix it when et to “Notify”

Trying to find clear cut information about systemd and how to manage it is amazingly difficult to impossible for something that is supposed to be so great and wonderful.

Any help or pointers around this would be absolutely awesome.

As well as ANY information that is useful for somebody new jumping into systemd.
It would be nice could get myself a clue as to how to manage it and actually troubleshoot it when things
are not magically working.
Anything I have found so far has been far more confusing than helpful.

My problem seems to be centered around Asterisk not starting initially as root.
And in my opinion a general lack of documentation or emphasis on things like this
making it harder to track down understand and fix.
The only emphasis That I could see about anywhere is to not run asterisk as root.
Which pretty much breaks things.
Please see the last developer comment in this post:

LINK

Pretty much still getting nowhere with this.
Starting up as root now I can sorta start and stop asterisk
However systemd still seems to thing it’s not running and constantly starts and stops it every minute.
systemctl status asterisk
● asterisk.service - Asterisk PBX and telephony daemon.
Loaded: loaded (/usr/lib/systemd/system/asterisk.service; enabled; vendor preset: disabled)
Active: activating (start) since Mon 2020-11-30 17:05:09 EST; 41s ago
Main PID: 8868 (asterisk)
Tasks: 72 (limit: 49447)
Memory: 33.9M
CGroup: /system.slice/asterisk.service
└─8868 /usr/sbin/asterisk -mqf -C /etc/asterisk/asterisk.conf

Nov 30 17:05:09 localhost.localdomain systemd[1]: Starting Asterisk PBX and telephony daemon…

Pretty frustrating.

Nov 30 16:57:16 localhost systemd[1]: Starting Asterisk PBX and telephony daemon…
Nov 30 16:58:47 localhost systemd[1]: asterisk.service: Start operation timed out. Terminating.
Nov 30 16:58:47 localhost systemd[1]: asterisk.service: Failed with result ‘timeout’.
Nov 30 16:58:47 localhost systemd[1]: Failed to start Asterisk PBX and telephony daemon…
Nov 30 16:58:51 localhost systemd[1]: asterisk.service: Service RestartSec=4s expired, scheduling restart.
Nov 30 16:58:51 localhost systemd[1]: asterisk.service: Scheduled restart job, restart counter is at 68.
Nov 30 16:58:51 localhost systemd[1]: Stopped Asterisk PBX and telephony daemon…
Nov 30 16:58:51 localhost systemd[1]: Starting Asterisk PBX and telephony daemon…
Nov 30 17:00:21 localhost systemd[1]: asterisk.service: Start operation timed out. Terminating.
Nov 30 17:00:21 localhost systemd[1]: asterisk.service: Failed with result ‘timeout’.
Nov 30 17:00:21 localhost systemd[1]: Failed to start Asterisk PBX and telephony daemon…
Nov 30 17:00:25 localhost systemd[1]: asterisk.service: Service RestartSec=4s expired, scheduling restart.
Nov 30 17:00:25 localhost systemd[1]: asterisk.service: Scheduled restart job, restart counter is at 69.
Nov 30 17:00:25 localhost systemd[1]: Stopped Asterisk PBX and telephony daemon…
Nov 30 17:00:25 localhost systemd[1]: Starting Asterisk PBX and telephony daemon…
Nov 30 17:01:56 localhost systemd[1]: asterisk.service: Start operation timed out. Terminating.
Nov 30 17:01:56 localhost systemd[1]: asterisk.service: Failed with result ‘timeout’.
Nov 30 17:01:56 localhost systemd[1]: Failed to start Asterisk PBX and telephony daemon…
Nov 30 17:02:00 localhost systemd[1]: asterisk.service: Service RestartSec=4s expired, scheduling restart.
Nov 30 17:02:00 localhost systemd[1]: asterisk.service: Scheduled restart job, restart counter is at 70.
Nov 30 17:02:00 localhost systemd[1]: Stopped Asterisk PBX and telephony daemon…
Nov 30 17:02:00 localhost systemd[1]: Starting Asterisk PBX and telephony daemon…
Nov 30 17:03:30 localhost systemd[1]: asterisk.service: Start operation timed out. Terminating.
Nov 30 17:03:30 localhost systemd[1]: asterisk.service: Failed with result ‘timeout’.
Nov 30 17:03:30 localhost systemd[1]: Failed to start Asterisk PBX and telephony daemon…
Nov 30 17:03:34 localhost systemd[1]: asterisk.service: Service RestartSec=4s expired, scheduling restart.
Nov 30 17:03:34 localhost systemd[1]: asterisk.service: Scheduled restart job, restart counter is at 71.
Nov 30 17:03:34 localhost systemd[1]: Stopped Asterisk PBX and telephony daemon…
Nov 30 17:03:34 localhost systemd[1]: Starting Asterisk PBX and telephony daemon…
Nov 30 17:05:05 localhost systemd[1]: asterisk.service: Start operation timed out. Terminating.
Nov 30 17:05:05 localhost systemd[1]: asterisk.service: Failed with result ‘timeout’.
Nov 30 17:05:05 localhost systemd[1]: Failed to start Asterisk PBX and telephony daemon…
Nov 30 17:05:09 localhost systemd[1]: asterisk.service: Service RestartSec=4s expired, scheduling restart.
Nov 30 17:05:09 localhost systemd[1]: asterisk.service: Scheduled restart job, restart counter is at 72.
Nov 30 17:05:09 localhost systemd[1]: Stopped Asterisk PBX and telephony daemon…
Nov 30 17:05:09 localhost systemd[1]: Starting Asterisk PBX and telephony daemon…
Nov 30 17:06:39 localhost systemd[1]: asterisk.service: Start operation timed out. Terminating.
Nov 30 17:06:39 localhost systemd[1]: asterisk.service: Failed with result ‘timeout’.
Nov 30 17:06:39 localhost systemd[1]: Failed to start Asterisk PBX and telephony daemon…
Nov 30 17:06:43 localhost systemd[1]: asterisk.service: Service RestartSec=4s expired, scheduling restart.
Nov 30 17:06:43 localhost systemd[1]: asterisk.service: Scheduled restart job, restart counter is at 73.
Nov 30 17:06:43 localhost systemd[1]: Stopped Asterisk PBX and telephony daemon…
Nov 30 17:06:43 localhost systemd[1]: Starting Asterisk PBX and telephony daemon…

So now I am back to it works fine if I Type=notify to “simple” instead of notify.
What is the difference and why is it not working if set to “notify” like seems to be the
default configuration after a build and install?

Is there any knowledge or help available on this?
Seems like I am just typing to myself out here.
Thanks,

I think you need to compile Asterisk with the systemd libraries in order to use Type=notify ?

Can you check the output of:

ldd /usr/sbin/asterisk | grep systemd

Not sure why I never saw this reply.
But, no output.
Sounds like I need to hangup re-compile and try my call again.

It was a week late reply, no worries. :cowboy_hat_face:

Download of systemd development headers, reconfigure of asterisk source tree, then remake, yes that should probably fix it.

Another option: if you want something more like traditional UNIX, then check out Type=forking instead of Type=simple or Type=notify. IMO for well-behaved, forkable daemons like Asterisk, this is the most minimally systemd-invasive approach on modern Linux distros where you’ve got less choice amongst init systems than in the past.

Here is one example of Type=forking that recently grew some wings on a test system…

[Unit]
Description=a Penguin PBX Solutions new-school cool forking systemd service for Debian 9 with Exim 4 and Asterisk 18
Documentation=man:asterisk(8)
After=network.target

[Service]

# systemd.service settings
ExecReload=/usr/sbin/asterisk -rx "core reload"
# Starts as asterisk - see User and Group lines. Preferred ExecStart method.
ExecStart=/usr/sbin/asterisk -vvvgtTF -M 200 -C /etc/asterisk/asterisk.conf
# Test if QoS works - look for DSCP EF bits in your test SIP RTP stream captures.
# If you do not see such bits, then use ExecStart with + prefix to start as root (but run as asterisk.)
#ExecStart=+/usr/sbin/asterisk -U asterisk -G asterisk -vvvgtTF -M 200 -C /etc/asterisk/asterisk.conf
ExecStop=/usr/sbin/asterisk -rx "core stop now"
# These mailer lines will fail with SUCCESS (- prefix) if mime-construct is not installed.
ExecStartPost=-/usr/bin/mime-construct --to asterisk@localhost --subject "PBX is starting" --string "Maybe make test calls."
ExecStopPost=-/usr/bin/mime-construct --to asterisk@localhost --subject "PBX is stopping" --string "Hopefully that is okay."
PIDFile=/var/run/asterisk/asterisk.pid
Restart=on-failure
RestartSec=10
Type=forking

# systemd.exec settings
Environment=HOME=/var/lib/asterisk
Group=asterisk
LimitCORE=infinity
LimitNOFILE=65536
Nice=-20
# Enabling NoNewPrivileges will probably break QoS.
#NoNewPrivileges=true
PrivateTmp=true
# If this is a box where you read mail - you need /home/user/.forward processing:
ProtectHome=read-only
# If this is not a box where you read mail eg. most production systems:
#ProtectHome=true
ProtectSystem=strict
# These paths are needed for local mail reading setups eg. testing.
ReadWritePaths=/var/lib/asterisk /var/spool/asterisk /var/log/asterisk /var/mail /var/spool/exim4 /var/log/exim4
# These paths are okay for non-local mail reading setups eg. production.
#ReadWritePaths=/var/lib/asterisk /var/spool/asterisk /var/log/asterisk
RuntimeDirectory=asterisk
SyslogIdentifier=asterisk
User=asterisk
WorkingDirectory=/var/lib/asterisk

[Install]
WantedBy=multi-user.target

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.