I am curious as to what this difference is between programs that are; started with systemd when enabled through systemctl, vs those started by means of /etc/rc.local or through the CLI.
For example, I was recently using shairport-sync for the raspberry pi. Initially, I set shairport-sync to start by means of sudo systemctl enabled shairport-sync.
Later down the road I used a functionality within shairport-sync to run scripts prior and post to devices connecting.
To my surprise, the scripts when executed by shairport-sync did not kill arecord or aplay
However, when I would run the script via terminal the script executed and killed arecord and aplay.
To further confuse myself, I killed shairport-sync and started it via terminal to see the output of what was happening. When I did so the scripts functioned as I expected when the device connected and killed arecord and aplay. So, as a fix I disabled shairport-sync in sysmtectl and set it to run in /etc/rc.local as a quick fix. After a reboot it functioned as I expected.
This leads me to believe that there is some difference between a program run as apart of systemd and a program that runs when started via /etc/rc.local or the CLI.
Why does this happen? Is this because of different run levels? Some dark magic?
The script that is run when a device connects to shairport-sync is as follows: shairportstart.sh
#!/bin/sh
/usr/bin/sudo /bin/pkill arecord
if [ $(date +%H) -ge "18" -o $(date +%H) -le "7" ]; then
/usr/bin/amixer set Speaker 40%
else
/usr/bin/amixer set Speaker 100%
fi
/home/pi/shScripts/shairportfade.sh&
exit 0
Here is the fade script: shairportfade.sh
#!/bin/sh
/usr/bin/amixer set Speaker 30-
for (( i=0; i<30; i++))
do
/usr/bin/amixer set Speaker 1+
done
exit 0
The script that is run when a device disconnects to shairport-sync is as follows: shairportend.sh
#!/bin/sh
/usr/bin/amixer set Speaker 70%
/usr/bin/arecord -D plughw:1 -f dat | /usr/bin/aplay -D plughw:1 -f dat&
exit 0
I found the following error in the /var/log/syslog only when shairport-sync was initially run as apart of systemd. When shairport-sync was run from the CLI or /etc/rc.local there were no errors present.
Jan 24 00:38:45 raspberrypi shairport-sync[617]: sudo: no tty present and no askpass program specified
Please note, that the only difference is how shairport-sync is initially started, when devices connect or disconnect shairport-sync continues to run.
ps ... awk ... grep ...stuff might be replaced by a simplerpkill/home/pi/shScripts/shairportfade.sh?rc.local