Quantcast
Channel: Linux Device Hacking
Viewing all articles
Browse latest Browse all 3247

[Help Request] Running Scripts from an Application (3 replies)

$
0
0
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
#!/bin/sh
/usr/bin/pkill arecord&
exit 0


shairportend.sh - start the mic > headphone process
#!/bin/sh
/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
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
sshd:x:101:65534::/var/run/sshd:/usr/sbin/nologin
messagebus:x:102:103::/var/run/dbus:/bin/false
avahi:x:103:104:Avahi mDNS daemon,,,:/var/run/avahi-daemon:/bin/false
ntp:x:104:106::/home/ntp:/bin/false
statd:x:105:65534::/var/lib/nfs:/bin/false
uuidd:x:100:101::/run/uuidd:/bin/false
_apt:x:106:65534::/nonexistent:/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
shairport-sync:x:111:113::/run/shairport-sync:/bin/bash
motion:x:112:114::/var/lib/motion:/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.

Viewing all articles
Browse latest Browse all 3247

Trending Articles