0

I am currently running shairport-sync on a raspberry pi zero running raspbian lite. Everything works well, but I am choosing to use a soundcard for auxillary input as well.

I currently have these scripts to run at the beginning before a device connects to shairport and after shairport ends playback.

the script run when a device connects is as follows:shairportstart.sh

!/bin/bash
/bin/ps -ef | /bin/grep are | /bin/grep -v /bin/grep | /usr/bin/awk '{print $2}'| /usr/bin/xargs /usr/bin/sudo /bin/kill
sleep 5s
if [ $(date +%H) -ge "18" -o $(date +%H) -le "7" ]; then
    amixer set Speaker 100%
else
    amixer -c 1 set Speaker 100%
fi
/home/pi/shScripts/shairportfade.sh&

exit 0

then the script that is being run after shairport ends is as follows:shairportend.sh

#!/bin/sh
amixer set Speaker 70%
arecord -D plughw:1 -f dat | aplay -D plughw:1 -f dat&
exit 0

I have tried changing the shebang from #!/bin/sh to #!/bin/bash but neither of them work to kill the PID, but they still change the amixer level.

from the terminal when I run

/bin/ps -ef | /bin/grep are | /bin/grep -v /bin/grep | /usr/bin/awk '{print $2}'| /usr/bin/xargs /usr/bin/sudo /bin/kill

the PID signal is terminated and shairport is able to begin playing the music from the device connected to it. Even when I run the script from the terminal it terminates properly, but it does not do so otherwise.

Is there something I am missing or not doing properly? Any help is appreciated.

I have tried searching multiple topics related to killing the PID and none of them work. I have tried kill -9, kill all, but none seem to work.

I have raised an issue on shairport-sync github page, but I was told it was a possible difference between runtime environments, I have tried searching on that subject as well but came up with nothing.

  • I take it the process not die with sudo kill [pid]? – edesilets Jan 23 '17 at 3:06
  • It does within the terminal, but does not when run in a script – Brett Reinhard Jan 23 '17 at 3:08
  • Sorry, about above premature question. Have you enabled debugging in your bash script? #!/bin/bash -x -v to help you find where it's getting caught up? Permissions may be another issue you could be running into. – edesilets Jan 23 '17 at 3:11
  • No worries, I didn't even think of using the shebang as a way of debugging I will try that possibly tomorrow to see what is happening. I don't know that will help as shairport runs the script behind the scenes. Does your method log the output somewhere that I can go to check later. I have also posted my answer as what fixed the issue. I believe it is a permissions issue but I believe the script doesn't have enough permission to kill the given PIDS – Brett Reinhard Jan 23 '17 at 3:14
0

Ok I have solved the issue. When shairport-sync is enabled with systemctl and enabled as suggested in the readme.md, a script is unable to kill the process due to the need for sudo. Since systemd is run early in the boot process, it loads shairport-sync before /etc/sudoers is loaded. Then since systemd runs in a consistent environment it runs the process without any sudo rules. That being said, each time sudo is needed it will require a password, which is the error that is occuring and not allowing for the kill command to execute.

There are a few work arounds to solve this issue.

The first solution is running sudo systemctl disable shairport-sync. Then add /home/pi/shairport-sync/shairport-sync& to the end of your /etc/rc.local file.

The next solution is to change sudo permissions via sudo visudo. From there you can add shairport-sync ALL=(ALL) NOPASSWD:ALL anywhere in the file, I chose to add it to the end of the file.

The last solution and possibly the simplest, is change your kill line from

/bin/ps -ef | /bin/grep are | /bin/grep -v /bin/grep | /usr/bin/awk '{print $2}'| /usr/bin/xargs /usr/bin/sudo /bin/kill

to

/usr/bin/echo "yourpasswordhere" | /usr/bin/sudo /bin/pkill arecord

EDIT:

While this is not completely related, this installation automatically sets up shairport-sync and allows for this line input with minor configuration changes: https://github.com/BaReinhard/Raspberry-Pi-Audio-Receiver-Install-Car-Install

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.