Welcome! Log In Create A New Profile


[Help Request] Running Scripts from an Application

Posted by cdlenfert 
[Help Request] Running Scripts from an Application
February 04, 2020 03:36PM
Shairport-sync is a service/app that acts as an audio receiver and allows Apple devices to Airplay (stream) audio over wifi. I wrote a how-to on this forum on getting it set up on a Pogoplug. It runs at startup and is always available for streaming. It also allows you to run scripts when audio is initially streamed to it, as well as when audio stops being streamed to it. The scripts (detailed below) are intended to stop and start a process that captures audio from the microphone (input) on a USB sound card, and play it through the headphone (output) jack. These scripts work properly when run as the root user, but fail to run via Shairport-sync.

I used a guide as a reference for the setup I’m attempting below: https://www.hifiberry.com/docs/projects/airplay-player-with-line-input/ (there are some notes at the bottom about not using sudo in the scripts. I’m not doing this, but I didn’t install Shairport-sync by compiling manually as the tut did.) I also don't have sudo on my Pogoplug

Note from the developer of Shairport-sync about how it runs in a "weird environment" (but this note was for Debian Wheezy OS and I'm on Stretch).

The scripts:
Located in /root (root user folder … maybe this is the issue)

shairportstart.sh - stop the mic > headphone process
/usr/bin/pkill arecord&
exit 0

shairportend.sh - start the mic > headphone process
/usr/bin/arecord -D plughw:CARD=Set -f dat | /usr/bin/aplay -D plughw:CARD=Set -f dat&
exit 0

Shairport-sync Configuration:
Located at /etc/shairport-sync.conf
Relevant section for scripts:
// Advanced parameters for controlling how a Shairport Sync runs
sessioncontrol = 
	run_this_before_play_begins = "/root/shScripts/shairportstart.sh"; // make sure the application has executable permission. If it's a script, include the #!... stuff on the first line
	run_this_after_play_ends = "/root/shScripts/shairportend.sh"; // make sure the application has executable permission. It it's a script, include the #!... stuff on the first line
	wait_for_completion = "yes"; // set to "yes" to get Shairport Sync to wait until the "run_this..." applications have terminated before continuing
//	allow_session_interruption = "no"; // set to "yes" to allow another device to interrupt Shairport Sync while it's playing from an existing audio source
//	session_timeout = 120; // wait for this number of seconds after a source disappears before terminating the session and becoming available again.

Permissions of Scripts directory:
root@pogoplugpro:~/shScripts# ls -la
total 24
drwxrwxrwx 2 root           root           4096 Jan 19 22:01 .
drwx------ 6 root           root           4096 Jan 19 22:10 ..
-rwxrwxrwx 1 shairport-sync shairport-sync  104 Dec 29 13:56 shairportend.sh
-rwxrwxrwx 1 root           root            118 Dec 29 13:57 shairportfade.sh
-rwxrwxrwx 1 shairport-sync shairport-sync   41 Dec 29 14:24 shairportstart.sh
-rwxrwxrwx 1 shairport-sync shairport-sync  166 Jan 19 22:01 shairporttest.sh

User info:
root@pogoplugpro:~/shScripts# getent passwd
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
avahi:x:103:104:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
systemd-timesync:x:107:109:systemd Time Synchronization,,,:/run/systemd:/bin/false
systemd-network:x:108:110:systemd Network Management,,,:/run/systemd/netif:/bin/false
systemd-resolve:x:109:111:systemd Resolver,,,:/run/systemd/resolve:/bin/false
systemd-bus-proxy:x:110:112:systemd Bus Proxy,,,:/run/systemd:/bin/false

I added /bin/bash as the shell for the shairport-sync user in a troubleshooting attempt that didn’t work. I believe it was previously /usr/sbin/nologin

Some ideas I've had more recently.
  • move scripts into a different location ... but where?
  • add the commands in the script directly to the config file ... not sure if they are too complex

Thanks if you've read this far! Double thanks if you have any ideas where I went awry.
Re: [Help Request] Running Scripts from an Application
February 04, 2020 04:54PM
Put it somewhere else, such as /usr/local/bin.

Generally, to execute a script the user needs some access to the entire path from / to where the script is, since that user won't have any access to /root this won't work. Rather than modify /root I'd suggest moving the scripts.
Re: [Help Request] Running Scripts from an Application
February 04, 2020 08:53PM
1000001101000 Thank you! You hit the nail on the head. I moved it to the /usr/local/bin/ directory and changed the owner to shairport-sync and everything works!

Do you know a good way to check if a user has access to the full path of a script? I'd like to have a better grasp of permissions in general, but a piece of knowledge at a time is better than none :)
Re: [Help Request] Running Scripts from an Application
February 04, 2020 11:10PM
I imagine there are a lot of good tutorials out there for learning about permissions, I don’t have a particular one to recommend. It’s important to learn but also difficult to keep straight sometimes.

Amusingly, the website for the class where I first learned about Unix permissions ~20 years ago is still online. It gives a pretty good overview of file permissions though not this specific issue:

Your Email:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.