When I run asterisk from systemctl, scripts using applications are not executed for example:
[Unit]
Description=Asterisk PBX and telephony daemon.
After=network.target
#include these if asterisk need to bind to a specific IP (other than 0.0.0.0)
#Wants=network-online.target
#After=network-online.target network.target
[Service]
Type=simple
Environment=HOME=/var/lib/asterisk
#if systemd do not provide hostname and you need to use ${ENV(HOSTNAME)}
#Environment=HOSTNAME=%H
WorkingDirectory=/var/lib/asterisk
User=asterisk
Group=asterisk
ExecStart=/usr/sbin/asterisk -mqfg -C /etc/asterisk/asterisk.conf
ExecReload=/usr/sbin/asterisk -rx 'core reload'
#if /var/run is a tmpfs, this will create /var/run/asterisk on start
#RuntimeDirectory=asterisk
#Nice=0
#UMask=0002
LimitCORE=infinity
#LimitNOFILE=
Restart=always
RestartSec=4
# Prevent duplication of logs with color codes to /var/log/messages
StandardOutput=null
PrivateTmp=true
[Install]
WantedBy=multi-user.target
This permission is very bad practice. You should give it no more than rwxr_xr_x, and it is best practice for non-set user scripts to be owned by root, with group root, so that they cannot be changed by a compromised application running on the working account.
As to the original problem, I suspect you are using incomplete file names and sysctl isn’t setting up a complete environment, in particular PATH.
If you have a #! line which doesn’t have a full path name, you will need the correct PATH variable. Similarly for other file names that are looked up in a list of directories from the environment.
Also, had did you find out the PATH in Asterisk environment?
What do you get from the shell command:
cat /proc/<insert the PID of the main asterisk process here>/environ
I don’t have asterisk on this machine, so I’ll use BOINC as a proxy:
That’s basically not surprising, given what you’ve already said, and the failure is probably happening before any user code is executed, so the log file can’t be used.
root@asterisk:/var/lib/asterisk# cat my.log
[Errno 2] No such file or directory: '/tmp/t.wav'
root@asterisk:/var/lib/asterisk# ls /tmp/t.wav
/tmp/t.wav