juhovh / shairplay

Apple airplay and raop protocol server
Other
1.35k stars 228 forks source link

Can't connect to ShairPlay when backgrounding it or opening it via init.d #17

Closed DanielSmedegaardBuus closed 6 years ago

DanielSmedegaardBuus commented 10 years ago

Hi :)

I tried the init.d example script posted here (minor mods), and discovered that it'll start and stop shairplay correctly — I can see the process running with the right arguments — but I won't be able to connect to it from my MacBook (It still shows up on the network, though, selecting it just does nothing).

If I stop the service and start shairplay in a shell manually with the exact same arguments, it'll work perfectly.

The same problem arises if I use that same shairplay shell command, but background it with '&'. It'll run, but I won't be able to connect.

I also don't see the usual stdout log, so I'm thinking perhaps there's some bug in shairplay that surfaces when it no longer can write to an interactive terminal?

Cheers, Daniel :)

juhovh commented 10 years ago

Hmm, I can connect to shairplay if it is running in background with '&', but I only tested on Mac OS X... I wonder what is the reason for that. It wouldn't hurt if shairplay could truly daemonize itself though, but I haven't had time for that so far.

DanielSmedegaardBuus commented 10 years ago

Not sure why either.

Backgrounding is fine, so long as the shell that launched shairplay is open (and attached to a stdout of some kind, it seems).

I worked around it by starting it in a screen shell via rc.local. Not pretty, but it works:

# Don't run multiple instances - start just one screen, named "shairplay":
[[ $(screen -list | grep shairplay) == '' ]] &&
    screen -dmS shairplay sh
# Keep shairplay perpetually running. When it crashes, we can just SIGKILL it, and it comes back:
[[ $(ps aux | grep -v grep | grep pts | grep '/usr/bin/shairplay') == '' ]] &&
    screen -S shairplay -p 0 -X stuff "while true; do /usr/bin/shairplay --apname=Airamaplay --ao_devicename=default; sleep 2s; done
"

That trailing quote on a newline isn't a typo — it's a newline so the command is executed inside screen.

juhovh commented 10 years ago

That is quite hackish. :) I should probably try on some different systems and see if I get the same problem.

DanielSmedegaardBuus commented 10 years ago

Hehe :D

Cool! Let me know if I can help :)

cyberhiker commented 9 years ago

I was having similar issues. I've posted my /etc/init.d/shairplay and /etc/default/shairplay here: https://gist.github.com/cyberhiker/9b60b1115e250a597c3f

juhovh commented 6 years ago

Unfortunately these are a bit outdated since everything is systemd now...