Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
uudruid74 wrote: > > > It will give you output about what the current device is. Turning off > the DAC should tell you the audio device is no longer available. > Restore the DAC and it should detect it and restart squeezelite. Let me > know what output it gives you. Hello, I'm asking this here, although I'm not sure what I'm currently experiencing correlates with this lovely component. I feel this precise pattern has already happened several times. This is what happened: - 1 week ago I played music in my stereo - Then, for a complete week I didn't use my stereo - After the week had passed, I decieded I would play some music - pCP is always on (I don't switch my RPI off) - I switched on my amp (which has an integrated DAC) - Music did not come through - I tried playing songs off Tidal and off Spotify. Nothing came through. - Fumbled a bit around in LMS. Nothing happened. - Went to pCP admin interface and restarted pCP manually. - Music started to play Since I didn't have my PC with me, and did not SSH into pCP and run the command above. I'm wondering what steps I should do next time this happens, to ensure I provide the right evidences to troubleshoot the problem. While drafting this message, I decided to give a go to the command you provided above and this is the output that I see: Code: tc@pCP:~$ sudo ./usbconnectd Starting usbconnectd Invalid OUTPUT device selected Existing output device is no longer available cat: can't open '/proc/asound/Headphones/usbid': No such file or directory cat: can't open '/proc/asound/Headphones/stream0': No such file or directory New output device is bcm2835_headpho - bcm2835 Headphones Stopping squeezelite wget: error getting response No Audio Device found cat: can't open '/proc/asound/Headphones/usbid': No such file or directory New output device is USB-Audio - CA CXA61 2.0 New USB Output Detected Stopping squeezelite wget: error getting response Starting squeezelite Stopping Squeezelite... start-stop-daemon: warning: killing process 8597: No such process Starting Squeezelite... Existing output device is no longer available cat: can't open '/proc/asound/Headphones/usbid': No such file or directory cat: can't open '/proc/asound/Headphones/stream0': No such file or directory New output device is bcm2835_headpho - bcm2835 Headphones Stopping squeezelite No Audio Device found cat: can't open '/proc/asound/Headphones/usbid': No such file or directory New output device is USB-Audio - CA CXA61 2.0 New USB Output Detected Stopping squeezelite Starting squeezelite Existing output device is no longer available cat: can't open '/proc/asound/Headphones/usbid': No such file or directory cat: can't open '/proc/asound/Headphones/stream0': No such file or directory New output device is bcm2835_headpho - bcm2835 Headphones Stopping squeezelite No Audio Device found ^C./usbconnectd: line 258: can't open /tmp/usbconnectd.fifo: Interrupted system call The output above was generated by turning off and on my DAC 2 times. Again, many many thanks for your help and support!! kitus's Profile: http://forums.slimdevices.com/member.php?userid=73121 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Greg Erskine wrote: > I have noted this. > > Unfortunately it is not as simple as one expects. If we include the code > we then become responsible for it, and there are also copyright > obligations. Understood. Thanks for clarifying this. kitus's Profile: http://forums.slimdevices.com/member.php?userid=73121 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
kitus wrote: > Hello uudruid74! I can confirm this works like a charm. I'm now a happy > camper. Thank you!!! > > To my opinion, this should be part of pCP core. Does anybody know how i > one can officially propose this? I have noted this. Unfortunately it is not as simple as one expects. If we include the code we then become responsible for it, and there are also copyright obligations. I think the best solution is to add a page to the piCorePlayer Documentation with a simple install procedure/script once we have uudruid74 permission. Greg Erskine's Profile: http://forums.slimdevices.com/member.php?userid=7403 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
uudruid74 wrote: > Did you reboot the system so that it starts usbconnectd? > > If no ... > Restart the system from the web interface > > If yes .. > Ssh into the system to a command prompt. See what it says when you type > this ... > > sudo killall usbconnectd > > If it says "no process killed" then it was never started and not > running. Check path, filename, and execute permission. > > If it kills it, it will print nothing. That let's us know its starting > it okay. Now that it isn't running, run it ... > > sudo ./usbconnectd > > It will give you output about what the current device is. Turning off > the DAC should tell you the audio device is no longer available. > Restore the DAC and it should detect it and restart squeezelite. Let me > know what output it gives you. Hello uudruid74! I can confirm this works like a charm. I'm now a happy camper. Thank you!!! kitus's Profile: http://forums.slimdevices.com/member.php?userid=73121 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
uudruid74 wrote: > Did you reboot the system so that it starts usbconnectd? > > If no ... > Restart the system from the web interface > > If yes .. > Ssh into the system to a command prompt. See what it says when you type > this ... > > sudo killall usbconnectd > > If it says "no process killed" then it was never started and not > running. Check path, filename, and execute permission. > > If it kills it, it will print nothing. That let's us know its starting > it okay. Now that it isn't running, run it ... > > sudo ./usbconnectd > > It will give you output about what the current device is. Turning off > the DAC should tell you the audio device is no longer available. > Restore the DAC and it should detect it and restart squeezelite. Let me > know what output it gives you. No, I did not reboot it. My bad. Later today I will give this a try and report back. Many thanks again for your support and detailed instructions! kitus's Profile: http://forums.slimdevices.com/member.php?userid=73121 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
kitus wrote: > Thanks for the detailed instructions! I've already added it as User > Command #1 on the Tweaks tab. > > This is what I've done: > > > - I powered off my DAC - pCP did not notice it. Squeezelite still appeared as green on the > main page. - I then restarted Squeezelite (section Main piCorePlayer functions - Restart) - I powered on my DAC and turned it on too > > > > > at this stage I would have expected for usbconnectd to take over and > ensure pCP noticed the change, and reconfigured pCP accordingly. > > Is there anything I'm missing? > > thanks!! Did you reboot the system so that it starts usbconnectd? If no ... Restart the system from the web interface If yes .. Ssh into the system to a command prompt. See what it says when you type this ... sudo killall usbconnectd If it says "no process killed" then it was never started and not running. Check path, filename, and execute permission. If it kills it, it will print nothing. That let's us know its starting it okay. Now that it isn't running, run it ... sudo ./usbconnectd It will give you output about what the current device is. Turning off the DAC should tell you the audio device is no longer available. Restore the DAC and it should detect it and restart squeezelite. Let me know what output it gives you. uudruid74's Profile: http://forums.slimdevices.com/member.php?userid=72371 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
uudruid74 wrote: > Open the web interface for picoreplayer (not LMS). Go to the Tweaks > tab. You'll see where it says "User Commands" at the bottom. > > You want the full name and path here. For example, if in the default > user's home directory, it's ... > > /home/tc/usbconnectd > > If you aren't sure if it's executable, ssh in as the tc user (this will > be OS dependant). Then run this ... > > chmod +x usbconnectd Thanks for the detailed instructions! I've already added it as User Command #1 on the Tweaks tab. This is what I've done: - I powered off my DAC - pCP did not notice it. Squeezelite still appeared as green on the main page. - I then restarted Squeezelite (section Main piCorePlayer functions - Restart) - I powered on my DAC and turned it on too at this stage I would have expected for usbconnectd to take over and ensure pCP noticed the change, and reconfigured pCP accordingly. Is there anything I'm missing? thanks!! kitus's Profile: http://forums.slimdevices.com/member.php?userid=73121 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
kitus wrote: > Would you mind pointing me to that post? I've searched for it across > several pages, and I didn't find it. Once I manage to get it working, > I'm happy to update your GitHub repo landing page with detailed > instructions, if you allow me to. Open the web interface for picoreplayer (not LMS). Go to the Tweaks tab. You'll see where it says "User Commands" at the bottom. You want the full name and path here. For example, if in the default user's home directory, it's ... /home/tc/usbconnectd If you aren't sure if it's executable, ssh in as the tc user (this will be OS dependant). Then run this ... chmod +x usbconnectd uudruid74's Profile: http://forums.slimdevices.com/member.php?userid=72371 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
uudruid74 wrote: > > Add it as your command to run at startup (there is a post about all that > a few back). Would you mind pointing me to that post? I've searched for it across several pages, and I didn't find it. Once I manage to get it working, I'm happy to update your GitHub repo landing page with detailed instructions, if you allow me to. kitus's Profile: http://forums.slimdevices.com/member.php?userid=73121 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Man in a van wrote: > @uudruid74 > > Just for info > > VirusTotal flags both links as having malicious content :( > > ronnie Added GITHUB link which solve that. uudruid74's Profile: http://forums.slimdevices.com/member.php?userid=72371 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Man in a van wrote: > Well I'm just a civilian who happens to be strolling by. :rolleyes: > > I find there is, actually, a lot of humour I don't understand, and > hence, do not find funny :confused: > > It must be an age thing and being a computer numpty :confused: > > But thanks for the assurances :) > > ronnie LOL. I didn't mean "funny" as humorous, but in a "peculiar" sense. Only the "predictive/AI" thinks there is something wrong but all the empirical checks are clean. That tells me the AI is more artificial than it is intelligent! uudruid74's Profile: http://forums.slimdevices.com/member.php?userid=72371 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
uudruid74 wrote: > Just ran it from their website to see what you are talking about. > > Hastebin is a widely used site similar to pastebin. It has no malicious > code and VirusTotal doesn't flag it at all. Its just a paste of the > code "hastebin > The eddon.systems link is only flagged by Bfore.AI PreCrime module of > VirusTotal. It attempts to detect what domains might contain malicious > code in the future based on the domain. They are trying hard to sell > their service and its bullshit. The eddon.systems domain is mine (not > used in forever) and I used to work in cyber security. There is > nothing to worry about from either link. If someone wants me to post > 300 lines here I can, or shoot me your email and I can email it, *but > seriously, don't you find it funny that NONE of the other modules > detected anything and only the "predictive" one flagged it?* Well I'm just a civilian who happens to be strolling by. :rolleyes: I find there is, actually, a lot of humour I don't understand, and hence, do not find funny :confused: It must be an age thing and being a computer numpty :confused: But thanks for the assurances :) ronnie Man in a van's Profile: http://forums.slimdevices.com/member.php?userid=43627 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Man in a van wrote: > @uudruid74 > > Just for info > > VirusTotal flags both links as having malicious content :( > > ronnie Just ran it from their website to see what you are talking about. Hastebin is a widely used site similar to pastebin. It has no malicious code and VirusTotal doesn't flag it at all. Its just a paste of the code "hastebin http://forums.slimdevices.com/member.php?userid=72371 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
@uudruid74 Just for info VirusTotal flags both links as having malicious content :( ronnie Man in a van's Profile: http://forums.slimdevices.com/member.php?userid=43627 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
sbp wrote: > For me the ranges is saved correctly if I add 44100-768000 in the max > sample rate box in the UI and press The save button. > Then checking the Squeezelite command string 'more>' > (http://192.168.0.216/cgi-bin/squeezelite.cgi?#) I have the correct > string -o hw:CARD=sndrpihifiberry -a 80:4::1: -r 44100-768000 The config file is correct. I believe its start-stop-daemon from busybox stripping dashes and commas. Here is my "metasolution" to the pluggable USB problem. It will work with the -C 5 and all the above. It is a single file (but nearly 300 lines). It suddenly started working using that method, but I was nearly done with this. There is a switch to completely kill squeezelite as I was doing before. I can now plug in a second DAC (such as with headphones) into my Pi and the song is paused on the main DAC and starts playing on the new one. Pull the new one out and it starts back on the old one. When the DAC goes off it stays paused. Moving the stream from one DAC to another restarts the playlist, but doesn't if you just turn it off. Shouldn't be any remote code execution exploits but dug too deep on the security. You can blacklist an audio device(s) so it doesn't get selected when you disconnect your DAC (use the short names not the full names, but it does show the full name in the log output). Also fills in MAX_RATES in the config file and keeps it updated. I was going to do bit depth options too but there was some question on the outputs (32b LE wasn't on the list, only BE - typo?) and I figured most people leave that blank anyway. It could be easily added though to just update the config as devices are inserted. 'View on Pastebin' (https://hastebin.com/nexufateho) 'Download It' (http://eddon.systems/Directory.php/Download/PCP) Anyone wanting to dig in to shell scripting should check it out for ideas. I kept it pretty basic since I'm not familiar with busybox ash and normally use zsh or bash. uudruid74's Profile: http://forums.slimdevices.com/member.php?userid=72371 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
sbp wrote: > For me the ranges is saved correctly if I add 44100-768000 in the max > sample rate box in the UI and press The save button. > Then checking the Squeezelite command string 'more>' > (http://192.168.0.216/cgi-bin/squeezelite.cgi?#) I have the correct > string -o hw:CARD=sndrpihifiberry -a 80:4::1: -r 44100-768000 Its converting the dash to a space for me. Either way, the -C option isnt working for me with -r 768000. Does it really need a range for -C to work? That seems like a needless requirement. I'm thinking a more robust solution would be to have udev wait for a remove event of the current audio device and shut down squeezelite. If there is a valid audio device left, switch the config to it (maybe with a blacklist) and configure the device for squeezelite and restart it. Udev should also wait for insertion of ANY audio device, and upon insertion configure the new device for squeezelite and restart it. The security issue above would also be fixed by sending only "add" or "remove" to the atnowd script (likely renamed), which would be modified to switch over the two valid commands and act accordingly, modifying udev and other config files as needed without additional scripts. I might code this up this weekend (but coding is a pain right now since I broke my hand). If I get it coded up, this would make USB devices plug-n-play and hot pluggable as they should be. The only issue would be that shutting down squeezelite makes it forget its position in the playlist - maybe someone else can fix that? The script would run at boot before squeezelite to auto-configure the USB device at boot (not changing settings if the currently configured device exists), write the udev config, and then block on the fifo for changes from udev. Thoughts? uudruid74's Profile: http://forums.slimdevices.com/member.php?userid=72371 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
For me the ranges is saved correctly if I add 44100-768000 in the max sample rate box in the UI and press The save button. Then checking the Squeezelite command string 'more>' (http://192.168.0.216/cgi-bin/squeezelite.cgi?#) I have the correct string -o hw:CARD=sndrpihifiberry -a 80:4::1: -r 44100-768000 piCorePlayer a small player for the Raspberry Pi in RAM. Homepage: 'https://www.picoreplayer.org' (https://www.picoreplayer.org/) *Please 'donate' (https://www.paypal.com/cgi-bin/webscr?cmd=_donations=U7JHY5WYHCNRU=GB_code=USD=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted) if you like piCorePlayer* sbp's Profile: http://forums.slimdevices.com/member.php?userid=37237 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
uudruid74 wrote: > > I am running the following version. How to update? > > Code: > > Squeezelite v1.9.9-1391-pCP, Copyright 2012-2015 Adrian Smith, 2015-2021 Ralph Irving. See -t for license terms> > > > At the main page in pCP you use the update button to start the > update process for squeezelite. piCorePlayer a small player for the Raspberry Pi in RAM. Homepage: 'https://www.picoreplayer.org' (https://www.picoreplayer.org/) *Please 'donate' (https://www.paypal.com/cgi-bin/webscr?cmd=_donations=U7JHY5WYHCNRU=GB_code=USD=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted) if you like piCorePlayer* sbp's Profile: http://forums.slimdevices.com/member.php?userid=37237 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
ralphy wrote: > I introduced a regression at r1109 that was 'fixed in 1.9.9r1392' > (https://github.com/ralph-irving/squeezelite/commit/3fbf7ea5288fad99e76800ee566771bbbce49299) > that caused squeezelite to exit instead of waiting for the audio device > to appear. > > See 'issue 153' (https://github.com/ralph-irving/squeezelite/issues/153) > for the details. > > However, you must supply both the -C and -r options on the command line > as well as the *hw: device* with -o to enable it. > > You can get the supported samples rate of your DAC to use in the -r > option from alsacap. > > > Code: > > $ alsacap > *** Scanning for playback devices *** > > Card 2, ID `*CODEC*', name `USB Audio CODEC' > Device 0, ID `USB Audio', name `USB Audio', 1 subdevices (1 available) > 1..2 channels, sampling rate *32000..48000* Hz > Sample formats: S8, U8, S16_LE > Buffer size range from 64 to 1048576 > Period size range from 32 to 524288 > Subdevice 0, name `subdevice #0' > > > > > > So for example for my UCA-202 I use -r32000-48000 along with -C 5 > > > Code: > > squeezelite -o hw:CARD=CODEC -r 32000-48000 -C 5 > > The UI removes the dash in the -r option so I get "44100 768000" instead of "44100 768000" (in both the -r setting and trying to add it as an extra option). Squeezelite never stops after 5 seconds (or later). Turning on the DAC doesn't bring back my music. I tried again just putting in 768000 rather than the range. This method simply doesn't work for me. I'll have to add back my hack above to get it working correctly. I am running the current version Code: Squeezelite v1.9.9-1391-pCP, Copyright 2012-2015 Adrian Smith, 2015-2021 Ralph Irving. See -t for license terms uudruid74's Profile: http://forums.slimdevices.com/member.php?userid=72371 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
I introduced a regression at r1109 that was 'fixed in 1.9.9r1392' (https://github.com/ralph-irving/squeezelite/commit/3fbf7ea5288fad99e76800ee566771bbbce49299) that caused squeezelite to exit instead of waiting for the audio device to appear. See 'issue 153' (https://github.com/ralph-irving/squeezelite/issues/153) for the details. However, you must supply both the -C and -r options on the command line as well as the *hw: device* with -o to enable it. You can get the supported samples rate of your DAC to use in the -r option from alsacap. Code: $ alsacap *** Scanning for playback devices *** Card 2, ID `*CODEC*', name `USB Audio CODEC' Device 0, ID `USB Audio', name `USB Audio', 1 subdevices (1 available) 1..2 channels, sampling rate *32000..48000* Hz Sample formats: S8, U8, S16_LE Buffer size range from 64 to 1048576 Period size range from 32 to 524288 Subdevice 0, name `subdevice #0' So for example for my UCA-202 I use -r32000-48000 along with -C 5 Code: squeezelite -o hw:CARD=CODEC -r 32000-48000 -C 5 Ralphy *1*-Touch, *5*-Classics, *3*-Booms, *2*-UE Radio 'Squeezebox client builds' (https://sourceforge.net/projects/lmsclients/files/) 'donations' (https://www.paypal.com/cgi-bin/webscr?cmd=_donations=LL5P6365KQEXN=CA_name=Squeezebox%20client%20builds_code=USD=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted) always appreciated. ralphy's Profile: http://forums.slimdevices.com/member.php?userid=3484 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
slartibartfast wrote: > Someone else had a similar issue. Their posts start here. > https://forums.slimdevices.com/showthread.php?p=1012890 > Yeah. The difference, as I noted above, is that my version doesn't bypass the start-stop-daemon (or need to deal with the udev environment at all), doesnt get anything "out-of-sync", works for whatever devices you hook into udev (and doesn't need to look into pcp config files to find your audio device), and does no polling that would prevent the Pi from sleeping into a low power mode! I could write a script to generate the udev rules file if you like. It could then be called by the web interface whenever selecting a USB audio device to set up everything if you want to include this as part of the standard install. I have 3 audio devices I could test with. uudruid74's Profile: http://forums.slimdevices.com/member.php?userid=72371 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
uudruid74 wrote: > Yes, that was from this thread. The script isn't the issue, but I > wouldn't mind seeing the latest version (I'm NOT searching through 30 > pages!), but I doubt it would help > > > > Tried, but thats not the issue. Without sudo it just runs as whatever > permissions "udev" has left it and we need MORE permissions, not less. > > My issue is that I route my DAC through a tube preamp and then into my > AVR. I "turn on" my squeezebox by selecting the input on the AVR. The > AVR switches to the jivelite interface on the TC screen and uses its > trigger out to turn on the DAC and tube preamp. I have a remote with a > USB dongle that can operate the UI (as well as use my phone, tablet, > etc). I don't turn off the Pi because it doesn't use much power and I > don't want to wait for a long boot process. The DAC isn't used for > other media since non-music content is surround sound and I use the DACs > in the AVR so its strictly for music. > > Apparently, udevd drops some permission that squeezelite needs to start. > I believe it could be a real-time priority permission. Either an > upgrade to udev caused this drop or an upgrade to squeezelite caused it > to request it, so running a script from udev will fail. The busy waits > I've seen posted here using "sleep" is just a bad idea. You are causing > a context switch every second and polling for an event that the system > can notify you of. That is the whole point of udev! > > Here is my solution: > > /HOME/TC/ATNOWD> Code: > > > #!/bin/sh > > FIFO="/tmp/atnowd.fifo" > echo "Starting atnowd" > > rm -f $FIFO 2>/dev/null > mkfifo $FIFO > > while true > do > sleep 10 > if read command <$FIFO > then > echo $command > ($command) > fi > done > > > > > -NOTE: Kids! Don't try this at home! On any other system executing > whatever we write to a pipe that is world-writable is a huge security > problem. In this instance, I think its OK for a media player that > only you have access to. Just don't use this trick on production > systems! *You run this by putting "/home/tc/atnowd >>/tmp/dac.txt" as > a "User Command" under "Tweaks" in the picoreplayer web interface.* > The redirection to a file can be left off once you are done testing. > Just ssh in and "tail -f /tmp/dac.txt" to see what it's doing so you > can test everything.- > > /HOME/TC/ATNOW> Code: > > > #!/bin/sh > FIFO="/tmp/atnowd.fifo" > echo $@ >>$FIFO > > > > > /ETC/UDEV/RULES.D/10-DAC.RULES> Code: > > > SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="152a/85dd/206", RUN+="/home/tc/atnow /home/tc/DAC.sh" > SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="152a/85dd/206", RUN+="/home/tc/atnow /home/tc/noDAC.sh" > > > > > -NOTE: I used "usb_device" as the DEVTYPE since my DAC will add the > USB device and then add a bunch of USB interfaces, and I don't want to > run any of this multiple times. There is possibility that the DAC.sh > might be run before the interfaces are loaded, but this is a race > condition in theory and not in practice! Obviously, substitute the > "PRODUCT" for your DAC - that is for an SMSL SU-9- > > /HOME/TC/NODAC.SH> Code: > > > #!/bin/sh > PIDFILE=/var/run/squeezelite.pid > > echo "Stopping squeezelite" > pcp stop > sudo /usr/local/etc/init.d/squeezelite stop > sleep 5 > killall -9 squeezelite > rm $PIDFILE > sleep 1 > sudo /usr/local/etc/init.d/squeezelite status > > > > > -NOTE: You can probably remove the status stuff at the end. And yes, > this is kinda brute force. The idea is to make sure no processes are > holding onto stale file handles, possibly preventing new processes > from starting. - > > /HOME/TC/DAC.SH> Code: > > > #!/bin/sh > > echo "Starting squeezelite" > sudo /usr/local/etc/init.d/squeezelite start > sudo /usr/local/etc/init.d/squeezelite status > pcp play > > > > > -BUG: When turning on the DAC, squeezelite is started and shows it to > be paused right where you left it. The moment it is unpaused, it > starts at the beginning of the playlist. I have tried all sorts of > stuff in both DAC.sh and noDAC.sh to try and fix this, but it just > doesn't work. Its a lot better than rebooting your Pi when you turn > on your DAC.- > > Hope this helps someone. Remember to do a "pcp br" so that all the > files are saved (and remember to chmod +x all the scripts), the atnowd > starts, and your udev rules are read. You can do all that manually > for testing, but this should work out of the box if you just change > the PRODUCT.Someone else had a similar issue. Their posts start here.
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
carsten_h wrote: > Yes, I think that was the work from this thread. But it seems that there > is not the whole script which is used in this thread. > > No, not really. Maybe you can try the last version of the script from > this thread here. Yes, that was from this thread. The script isn't the issue, but I wouldn't mind seeing the latest version (I'm NOT searching through 30 pages!), but I doubt it would help Paul Webster wrote: > Try taking the "sudo" out. Tried, but thats not the issue. Without sudo it just runs as whatever permissions "udev" has left it and we need MORE permissions, not less. My issue is that I route my DAC through a tube preamp and then into my AVR. I "turn on" my squeezebox by selecting the input on the AVR. The AVR switches to the jivelite interface on the TC screen and uses its trigger out to turn on the DAC and tube preamp. I have a remote with a USB dongle that can operate the UI (as well as use my phone, tablet, etc). I don't turn off the Pi because it doesn't use much power and I don't want to wait for a long boot process. The DAC isn't used for other media since non-music content is surround sound and I use the DACs in the AVR so its strictly for music. Apparently, udevd drops some permission that squeezelite needs to start. I believe it could be a real-time priority permission. Either an upgrade to udev caused this drop or an upgrade to squeezelite caused it to request it, so running a script from udev will fail. The busy waits I've seen posted here using "sleep" is just a bad idea. You are causing a context switch every second and polling for an event that the system can notify you of. That is the whole point of udev! Here is my solution: /HOME/TC/ATNOWD Code: #!/bin/sh FIFO="/tmp/atnowd.fifo" echo "Starting atnowd" rm -f $FIFO 2>/dev/null mkfifo $FIFO while true do sleep 10 if read command <$FIFO then echo $command ($command) fi done -NOTE: Kids! Don't try this at home! On any other system executing whatever we write to a pipe that is world-writable is a huge security problem. In this instance, I think its OK for a media player that only you have access to. Just don't use this trick on production systems! *You run this by putting "/home/tc/atnowd >>/tmp/dac.txt" as a "User Command" under "Tweaks" in the picoreplayer web interface.* The redirection to a file can be left off once you are done testing. Just ssh in and "tail -f /tmp/dac.txt" to see what it's doing so you can test everything.- /HOME/TC/ATNOW Code: #!/bin/sh FIFO="/tmp/atnowd.fifo" echo $@ >>$FIFO /ETC/UDEV/RULES.D/10-DAC.RULES Code: SUBSYSTEM=="usb", ACTION=="add", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="152a/85dd/206", RUN+="/home/tc/atnow /home/tc/DAC.sh" SUBSYSTEM=="usb", ACTION=="remove", ENV{DEVTYPE}=="usb_device", ENV{PRODUCT}=="152a/85dd/206", RUN+="/home/tc/atnow /home/tc/noDAC.sh" -NOTE: I used "usb_device" as the DEVTYPE since my DAC will add the USB device and then add a bunch of USB interfaces, and I don't want to run any of this multiple times. There is possibility that the DAC.sh might be run before the interfaces are loaded, but this is a race condition in theory and not in practice! Obviously, substitute the "PRODUCT" for your DAC - that is for an SMSL SU-9- /HOME/TC/NODAC.SH Code: #!/bin/sh PIDFILE=/var/run/squeezelite.pid echo "Stopping squeezelite" pcp stop sudo /usr/local/etc/init.d/squeezelite stop sleep 5 killall -9 squeezelite PIDFILE=/var/run/squeezelite.pid rm $PIDFILE sleep 1 sudo /usr/local/etc/init.d/squeezelite status -NOTE: You can probably remove the status stuff at the end. And yes, this is kinda brute force. The idea is to make sure no processes are holding onto stale file handles, possibly preventing new processes from starting. - /HOME/TC/DAC.SH Code: #!/bin/sh echo "Starting squeezelite" sudo /usr/local/etc/init.d/squeezelite start sudo /usr/local/etc/init.d/squeezelite status pcp play -BUG: When turning on the DAC, squeezelite is started and shows it to be paused right where you left it. The moment it is unpaused, it starts at the beginning of the playlist. I have tried all sorts of stuff in both DAC.sh and noDAC.sh to try and fix this, but it just doesn't work. Its a lot better than rebooting your Pi when you turn on your DAC.- Hope this helps someone. Remember to do a "pcp br" so that all the files are saved (and remember to chmod +x all the scripts), the atnowd starts, and your udev rules are read. You can do all that manually for testing, but this should work out of the box if you just change the PRODUCT.
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Try taking the "sudo" out. Paul Webster author of \"now playing\" plugins covering radio france (fip etc), planetradio (bauer - kiss, absolute, scala, jazzfm etc), kcrw, abc australia and cbc/radio-canada and, via the extra \"radio now playing\" plugin lots more - see https://forums.slimdevices.com/showthread.php?115201-announce-radio-now-playing-plugin Paul Webster's Profile: http://forums.slimdevices.com/member.php?userid=105 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
uudruid74 wrote: > There is a how-to > (https://docs.picoreplayer.org/projects/autostart-squeezelite-from-usb-dac/) > that suggests this should be working. Yes, I think that was the work from this thread. But it seems that there is not the whole script which is used in this thread. uudruid74 wrote: > Any ideas? No, not really. Maybe you can try the last version of the script from this thread here. pi4 4gb picoreplayer with lms and squeezelite for usb inside an argon one case pi3b+ (7\" display, hifiberry dac+ pro) picoreplayer with squeezlite/jivelite for hifiberry and bluetooth headphone inside a smartipi touch case two airport express ikea symfonisk carsten_h's Profile: http://forums.slimdevices.com/member.php?userid=69113 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Greg Erskine wrote: > hi carsten_h, > > I can't give you a definite answer but... here's a guess. > > I believe in pCP7 there was a problem getting the card name (from USB > DAC) which caused errors restoring asound.state. > > The USB restart scripts worked around this. > > Maybe because we fixed a few ALSA things in pCP8.0.0 it broke > something. > > Or, it could be these scripts don't play nice with the instu upgrade > process. > > regards > Greg Pulling my hair out here. I'm trying to restart squeezelite via udev rules. The script is executing. It tries to restart the server, but it doesn't actually start. If I run the same script via the command line, it runs and starts just fine. There is a how-to (https://docs.picoreplayer.org/projects/autostart-squeezelite-from-usb-dac/) that suggests this should be working. The actual call to the init script is run via sudo so it shouldnt be a permissions thing. Any ideas? uudruid74's Profile: http://forums.slimdevices.com/member.php?userid=72371 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
hi carsten_h, I can't give you a definite answer but... here's a guess. I believe in pCP7 there was a problem getting the card name (from USB DAC) which caused errors restoring asound.state. The USB restart scripts worked around this. Maybe because we fixed a few ALSA things in pCP8.0.0 it broke something. Or, it could be these scripts don't play nice with the instu upgrade process. regards Greg Greg Erskine's Profile: http://forums.slimdevices.com/member.php?userid=7403 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Hello! After installing pcp 8.0 with an insitu update squeezelite is not longer starting at boot. The USB soundsticks are switched on but nothing happens. This is the pcp_Soundsticks.log file: Code: [ 12.73] Script parameters: find SoundSticks [ 12.76] Searching for SoundSticks with idVendor=05fc and idProduct=7849 in dmesg [ 12.79] SoundSticks detected on 1-1.4 [ 12.80] Restoring alsa settings for SoundSticks And I see this in pcp_boot.log: Code: Starting SQLITE-control.sh from /opt/bootlocal.sh... ... Waiting for sound card SoundSticks to populate. Done (1). ... Starting ALSA configuration... Done (1). When I switch of the soundsticks and switch them on squeezelite is running. So it is only a problem at boot time. pi4 4gb picoreplayer with lms and squeezelite for usb inside an argon one case pi3b+ (7\" display, hifiberry dac+ pro) picoreplayer with squeezlite/jivelite for hifiberry and bluetooth headphone inside a smartipi touch case two airport express ikea symfonisk carsten_h's Profile: http://forums.slimdevices.com/member.php?userid=69113 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Point taken. So pgf's original approach is best - init.d stop, followed by pkill. Maybe add a short sleep between the two, to give squeezelite a chance to finish its orderly shutdown. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
It was more of a general thought from me (and also I probably should not have said SIGHUP - that was just habit from the old days). To me it feels better to ask an application to perform an orderly close down before forcing it. On pCP this is probably less important because there is probably nothing that is going to be saved over a reboot as a result of the action. I have seen (again old times) that files can be left in a strange state as the result of a kill -9 which then makes a subsequent restart not always work - so when I use kill by hand I usually try a polite one first then check to see if it has gone ... and if not then I try a -9 but make a mental note to watch out when I restart it (that mental note then fades away into oblivion just before I needed to remember it). Paul Webster http://dabdig.blogspot.com author of \"now playing\" plugins covering radio france (fip etc), kcrw, supla finland, abc australia, cbc/radio-canada and rte ireland Paul Webster's Profile: http://forums.slimdevices.com/member.php?userid=105 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Paul Webster wrote: > Given that the situation is relatively rare and that an extra few > seconds is unlikely to make a difference then a > SIGHUP then pause and check again and SIGKILL if still running should be > OK. Do you mean as a general purpose approach for the init.d script? For this USB DAC script, I see no harm in using SIGKILL immediately. Is there anything important that Squeezelite would have wanted to do first if given the chance? If it can't do that, does it matter, given that the DAC has gone? Here's where I'm currently at with pgf's script. I separated the start/stop tasks into their own function (the commands are only wrapped inside 'log' commands to keep the log file tidy): Code: squeezelite() { case $1 in start) log $(/usr/local/etc/init.d/squeezelite start 2>&1) ;; stop) # log $(/usr/local/etc/init.d/squeezelite stop 2>&1) log "Stopping Squeezelite player: Squeezelite..." result=$(start-stop-daemon --stop --quiet -s SIGKILL -p /var/run/squeezelite.pid 2>&1) if [ "$result" ]; then log $result; fi sudo rm -f /var/run/squeezelite.pid ;; esac } chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Given that the situation is relatively rare and that an extra few seconds is unlikely to make a difference then a SIGHUP then pause and check again and SIGKILL if still running should be OK. Paul Webster http://dabdig.blogspot.com author of \"now playing\" plugins covering radio france (fip etc), kcrw, supla finland, abc australia, cbc/radio-canada and rte ireland Paul Webster's Profile: http://forums.slimdevices.com/member.php?userid=105 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
paul- wrote: > Are you guys using the absolute latest squeezelite package? The have > been changes after pCP 7 was released that affected the -C option. On my test Pi3A+ I've been using the Squeezelite version that was part of the the pCP7.0.0 image: v1.9.8-1287-pCP. I've just updated to v1.9.9-1364-pCP. With this version, the symptoms are the same with the -C option: if no music is playing the init.d script kills the process, but with music playing it doesn't. paul- wrote: > Im not sure what you are expecting SIGTERM to do. This just tells the > program to shutdown normally. In all of these cases being discussed, > abnormal conditions are present, so the shutdown process is unable to > complete. Using an escalated termination signal is quite expected. I agree - it seems unfair to ask Squeezelite to shut down 'normally' when the DAC that it's playing to suddenly disappears. Given that argument, I think the SIGKILL signal seems like the way forward. There might be a case for updating the init.d script to use '-s SIGKILL', so that it works in all eventualities, but as pgf points out, that would deny Squeezelite the opportunity to do what it might want to under a normal shutdown. So maybe it's best left as is, and the subject of this thread can be tackled in the knowledge that this is an abnormal situation that requires a different call to the start-stop-daemon. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Im not sure what you are expecting SIGTERM to do. This just tells the program to shutdown normally. In all of these cases being discussed, abnormal conditions are present, so the shutdown process is unable to complete. Using an escalated termination signal is quite expected. piCorePlayer a small player for the Raspberry Pi in RAM. Homepage: https://www.picoreplayer.org Please 'donate' (https://www.paypal.com/cgi-bin/webscr?cmd=_donations=U7JHY5WYHCNRU=GB_code=USD=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted) if you like the piCorePlayer paul-'s Profile: http://forums.slimdevices.com/member.php?userid=58858 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Are you guys using the absolute latest squeezelite package? The have been changes after pCP 7 was released that affected the -C option. piCorePlayer a small player for the Raspberry Pi in RAM. Homepage: https://www.picoreplayer.org Please 'donate' (https://www.paypal.com/cgi-bin/webscr?cmd=_donations=U7JHY5WYHCNRU=GB_code=USD=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted) if you like the piCorePlayer paul-'s Profile: http://forums.slimdevices.com/member.php?userid=58858 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > FYI, Ralph just helped me learn (while diagnosing the SIGTERM thing) > that the shutdown bug doesn't happen if -C is used. I get the > impression (and I'm going to confirm with him) that -C should always be > used with USB devices that might be unplugged or turned off. (Clearly > it should shut down correctly in either case, of course.) There had to be a simple explanation. I can confirm that on my Pi3A+, where I experienced the issue, I did not have the -C option, but when I add -C the behaviour is different. I won't say it's cured though. If there is no audio playing when the DAC is removed, the squeezelite process dies completely without the extra pkill, but if there's audio playing, the process doesn't die unless I include the extra pkill, even if I wait much longer that the 5 seconds I specified with the -C option. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
FYI, Ralph just helped me learn (while diagnosing the SIGTERM thing) that the shutdown bug doesn't happen if -C is used. I get the impression (and I'm going to confirm with him) that -C should always be used with USB devices that might be unplugged or turned off. (Clearly it should shut down correctly in either case, of course.) pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
I removed the old udev script from my main Pi4B player, and installed your new script (with a few personalisations: logfile named after the audio card, player powered up in LMS after a restart, 'restart' split into new-style stop and init.d start). It's working perfectly. Not really a surprise, but merely a confirmation that the 'kill' workaround doesn't interfere on a device where the original 'kill' worked reliably. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
coyrls wrote: > Submit an Issue at https://github.com/ralph-irving/squeezelite ? Perfect. Thank you. pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > > What should really happen is a) squeezelite should fix the SIGTERM > shutdown bug, and b) the init.d script should be scrubbed to eliminate > some of its issues. Maybe I'll figure out how to submit a bug against > squeezelite. If any of our dear readers know the answer, please let me > know. ;-) > > paul Submit an Issue at https://github.com/ralph-irving/squeezelite ? coyrls's Profile: http://forums.slimdevices.com/member.php?userid=44253 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > If any of our dear readers know the answer, please let me know. ;-) > Ralphy's yer man for Squeezelite. He's already seen the thread, so I'm sure he'll see your suggestions. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Sure, maybe separating out the stop/start, and adding in the pkill, would be better. In my testing I never saw an issue with the restart, but it could be safer. Since the restart is happening when the device is present, the squeezelite shutdown bug may not be triggered. What should really happen is a) squeezelite should fix the SIGTERM shutdown bug, and b) the init.d script should be scrubbed to eliminate some of its issues. Maybe I'll figure out how to submit a bug against squeezelite. If any of our dear readers know the answer, please let me know. ;-) paul pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > > You should do whatever you want with this, though now that you have a > good workaround for stopping squeezelite properly, maybe you'll just use > your script. > That's brilliant, thanks Paul. I don't really see the benefit of the udev approach over your approach. Your script is leaner, and doesn't require any 'installation', other than to call it from a User Command. If this was StackExchange, this should be the top answer to the question "How do I start/restart Squeezelite when I plug in my USB DAC?" I'm left with a couple of nagging doubts. 1) If I'm remembering and interpreting correctly, I think Bogg also reported that his system would not start squeezelite via the start-stop-daemon. That was the reason I implemented a copy of the 'start' approach in my script. It would be interesting if Bogg could uninstall the old udev script and give this one a try, to see if that's still the case. 2) Your script uses the 'restart' option of the init.d script, which simply does a behind-the-scenes 'stop' then 'start'. It would probably be safer for your script to explicitly do a new-style 'stop' followed by an init.d 'start', although I recognise that it should never get to the state that causes this problem, i.e. where the DAC has disappeared just before the script does a restart, without the script explicitly doing a new-style stop first. I hope that explanation is not too muddled. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
In any case, I won't be adding that to my script, because none of those commands will work on my system. (I connect to the LMS server via an ssh tunnel, so my LMS server address is actually localhost. I use a custom -s option on the squeezelite config page to do this.) So here's my current script. To properly support lots of custom operations when the device comes and goes it should really run a set of scripts from a "device-appears" and a "device-goes-away" directory. But that starts to sound a lot like recreating udev, so I'm not going to do that. ;-) You should do whatever you want with this, though now that you have a good workaround for stopping squeezelite properly, maybe you'll just use your script. paul Code: #!/bin/sh # watch_usb_audio -- a script to stop/restart squeezelite when a # removeable audio device comes and goes. # logging to a name starting with "pcp_" causes output to display # under "Diagnostics" in the web interface. logfile=/var/log/pcp_watch_usb_audio.log exec >$logfile 2>&1 usage_header() { # Not a traditional usage message. More like a short README, # shown at the start of the log. cardname=${alsacard:-} # use $alsacard, or "" cat
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > Any reason you can't just use the "pcp" command (which I just stumbled > across). Seems safer than loading their internal files. > > Code: > > > ==kitchen(tc)>> pcp help > = > Basic piCorePlayer CLI > - > Squeezelite/LMS > --- > - pcp play : play current track in playlist > - pcp stop : stop current track > - pcp pause : pause current track > - pcp up : volume up > - pcp down : volume down > - pcp next : next track > - pcp prev : previous track > - pcp rand : generate random playlist > - pcp power [on|off] : software power on or off > - pcp volume [0-100] : set volume between 0 to 100 > - pcp rescan : look for new and changed media files in connected LMS library > - pcp wipecache : clear connected LMS library and rescan > - pcp mode : display Squeezelite's current mode > - > piCore > -- > - pcp bu : (b)ack(u)p > - pcp sd : (s)hut(d)own > - pcp bs : (b)ackup then (s)hutdown > - pcp rb : (r)e(b)oot > - pcp br : (b)ackup then (r)eboot > - > piCorePlayer > > - pcp d0 : debug off > - pcp d1 : debug on > - > Jivelite > > - pcp kj : (k)ill (j)ivelite > - > > Tsk. Even simpler. If we dig deep enough there's probably a command to start squeezelite when the DAC is powered up.. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Any reason you can't just use the "pcp" command (which I just stumbled across). Seems safer than loading their internal files. Code: ==kitchen(tc)>> pcp help = Basic piCorePlayer CLI - Squeezelite/LMS --- - pcp play : play current track in playlist - pcp stop : stop current track - pcp pause : pause current track - pcp up : volume up - pcp down : volume down - pcp next : next track - pcp prev : previous track - pcp rand : generate random playlist - pcp power [on|off] : software power on or off - pcp volume [0-100] : set volume between 0 to 100 - pcp rescan : look for new and changed media files in connected LMS library - pcp wipecache : clear connected LMS library and rescan - pcp mode : display Squeezelite's current mode - piCore -- - pcp bu : (b)ack(u)p - pcp sd : (s)hut(d)own - pcp bs : (b)ackup then (s)hutdown - pcp rb : (r)e(b)oot - pcp br : (b)ackup then (r)eboot - piCorePlayer - pcp d0 : debug off - pcp d1 : debug on - Jivelite - pcp kj : (k)ill (j)ivelite - pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > No -- SIGTERM is the default, for all versions of kill/pkill/killall. > > For some reason, if the audio device has gone away (probably not a > well-tested scenario), one of squeezelite's threads doesn't die from the > first kill -TERM, but does die from the second. > > I've put a similar workaround in my script. > > I want to look at your soft power-off code, then I'll publish a new > version. Forget my earlier soft power-off code. Do this: Put this somewhere near the top: Code: . /usr/local/etc/pcp/pcp.cfg audiodev=$(echo $OUTPUT | awk -FCARD= '{print $2}' | awk -F, '{print $1}' ) . /var/www/cgi-bin/pcp-functions . /var/www/cgi-bin/pcp-lms-functions The first line populates a load of pCP squeezelite variables, so you can get audiodev from $OUTPUT, and $NAME holds the player name. Then after the restart command, this is all that's needed. Code: # turn on player in LMS pcp_lms_power 1 chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
No -- SIGTERM is the default, for all versions of kill/pkill/killall. For some reason, if the audio device has gone away (probably not a well-tested scenario), one of squeezelite's threads doesn't die from the first kill -TERM, but does die from the second. I've put a similar workaround in my script. I want to look at your soft power-off code, then I'll publish a new version. pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
>From the busybox source code (for debianutils) (https://github.com/brgl/busybox/blob/master/debianutils/start_stop_daemon.c) Code: Options which are valid for --stop only: -s,--signal SIG Signal to send (default:TERM) Could the piCore version of the source code be different? chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > Have you tried using SIGTERM again, rather than SIGKILL? Well blow me - that works too. What signal does it send if you don't specify one? chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Have you tried using SIGTERM again, rather than SIGKILL? pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > You'll be happy to know I'm seeing an incomplete kill of squeezelite on > my system as well. I'll look into it. > > Note that squeezelite, while not killed completely, has been crippled: > 2 of its 4 threads do die. > > paul Well that's encouraging, in a way. What model RPi are you running? As a last resort, this works for me now: Code: # sudo /usr/local/etc/init.d/squeezelite stop sudo start-stop-daemon --stop --quiet -s SIGKILL -p /var/run/squeezelite.pid sudo rm -f /var/run/squeezelite.pid chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
You'll be happy to know I'm seeing an incomplete kill of squeezelite on my system as well. I'll look into it. Note that squeezelite, while not killed completely, has been crippled: 2 of its 4 threads do die. paul pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
ralphy wrote: > pCP uses and includes 'JSON.awk' (https://github.com/step-/JSON.awk) to > parse json output. Haha - while I was browsing through the pCP source code to find an example of JSON.awk in use, I found 'pcp_lms_power' (and all the other defined functions). All the hard work has been done by the pCP team! All I have to do is set NAME to be the LMS player name, then call 'psp_lms_power 1' or 'pcp_lms_power 0' to turn the player on or off. Fantastic. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
ralphy wrote: > pCP uses and includes 'JSON.awk' (https://github.com/step-/JSON.awk) to > parse json output. Perfect - thank you for the tip. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > Ahem. It doesn't work reliably. Not surprising for a JSON newbie I > suppose. It seems that the player details aren't always returned in the > same order, so I can't 'awk' for the player name THEN the MAC address. > I was hoping to get away without parsing the JSON rigorously - is there > an easy way to do that in a shell script? pCP uses and includes 'JSON.awk' (https://github.com/step-/JSON.awk) to parse json output. Ralphy *1*-Touch, *5*-Classics, *3*-Booms, *2*-UE Radio 'Squeezebox client builds' (https://sourceforge.net/projects/lmsclients/files/) 'donations' (https://www.paypal.com/cgi-bin/webscr?cmd=_donations=LL5P6365KQEXN=CA_name=Squeezebox%20client%20builds_code=USD=PP%2dDonationsBF%3abtn_donate_SM%2egif%3aNonHosted) always appreciated. ralphy's Profile: http://forums.slimdevices.com/member.php?userid=3484 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Greg Erskine wrote: > Thx. Ahem. It doesn't work reliably. Not surprising for a JSON newbie I suppose. It seems that the player details aren't always returned in the same order, so I can't 'awk' for the player name THEN the MAC address. I was hoping to get away without parsing the JSON rigorously - is there an easy way to do that in a shell script? chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Thx. Greg Erskine's Profile: http://forums.slimdevices.com/member.php?userid=7403 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
I changed 'sudo /usr/local/etc/init.d/squeezelite stop' to 'sudo start-stop-daemon --stop --quiet -p /var/run/squeezelite.pid' in your script, and it made no difference. But then I discovered that the start-stop-daemon has the '-s' flag to determine which signal is sent. And what do you know, sending SIGKILL (the equivalent of 'kill -9' that you told me not to use :)) works! chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > Aargh! Guess what. On my Pi3A+, the command > '/usr/local/etc/init.d/squeezelite stop', when called within your script > (with or without 'sudo'), only deletes the pidfile. It does NOT kill > the squeezelite process. Exactly the same behaviour as I was seeing > with the udev script. > > Calling 'sudo /usr/local/etc/init.d/squeezelite stop' from the command > line DOES kill the process, but only if the pidfile is present. On this Pi3A+, the 'Restart Squeezelite with new settings' button on the pCP main page DOES succeed in killing the old process and starting a new one. So I assumed it must be doing something different. But in fact 'main.cgi' calls 'restartsqlt.cgi' which calls 'pcp_squeezelite_stop' then 'pcp_squeezelite_start'. No prizes for guessing that 'pcp_squeezelite_stop' calls 'sudo /usr/local/etc/init.d/squeezelite stop'. So how on earth can it be that 'sudo /usr/local/etc/init.d/squeezelite stop', when called by pCP or by user tc from the command line, will successfully stop the process, but when called from a User Command script or a udev script it will not? Makes no sense! chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Greg Erskine wrote: > Where does the softpower function come from? I don't do json stuff. Nor do I! I cobbled it together from other examples I found in pcp-lms-functions. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Where does the softpower function come from? I don't do json stuff. Greg Erskine's Profile: http://forums.slimdevices.com/member.php?userid=7403 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Aargh! Guess what. On my Pi3A+, the command '/usr/local/etc/init.d/squeezelite stop', when called within your script (with or without 'sudo'), only deletes the pidfile. It does NOT kill the squeezelite process. Exactly the same behaviour as I was seeing with the udev script. Calling 'sudo /usr/local/etc/init.d/squeezelite stop' from the command line DOES kill the process, but only if the pidfile is present. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > > Anything would work. I can make it 1 second. I confess it makes me > twitch a little, but 1 second is eons in modern computer clock speed > time. > That was my feeling too. Isn't this the way a daemon works (something like pigpiod that constantly watches for gpio events), or does they all use a different approach, like system events? pgf wrote: > You go guy! I have no idea what you're talking about. :-) > I found that if the player is switched off in LMS before the script stops squeezelite, the next time the script restarts squeezelite it comes back in the same 'soft off' state. It's a really minor issue, but I prefer that if the DAC is powered up, squeezelite should restart in the 'soft on' state. This is my attempt to do that by sending the appropriate command to LMS. Call it with 'softpower "$NAME" 1', where $NAME is obtained from /usr/local/etc/pcp/pcp.cfg. I'm totally new to the JSON interface, so there may well be more efficient ways to do this. And I suspect my function will go wrong if the player's $NAME has spaces in it, because it will look like more than one argument. Code: # # send JSON command to soft power on/off (1/0) the player # softpower() { player_name=$1 pwr=$2 #get LMS address and port . /var/www/cgi-bin/pcp-functions LMSIP=$(pcp_lmsip) . /usr/local/etc/pcp/pcp.cfg [ x"" = x"$LMSWEBPORT" ] && LMSPORT=9000 || LMSPORT=$LMSWEBPORT log "LMS address = $LMSIP:$LMSPORT" $logfile # get player's MAC address from the player name player_info=$(busybox wget -q -O- --post-data='{"id":1,"method":"slim.request","params": [ "-", [ "players", "0", "999" ] ]}' --header 'Content-Type: application/json' http://$LMSIP:$LMSPORT/jsonrpc.js) MAC=$(echo $player_info | awk -F "$player_name" '{print $2}' | awk -F playerid '{print $2}' | awk -F \" '{print $3}') # send soft power request to LMS result=$(busybox wget -q -O- --post-data='{"id":1,"method":"slim.request","params": ["'$MAC'",["power",'$pwr']]}' --header 'Content-Type: application/json' http://$LMSIP:$LMSPORT/jsonrpc.js) log "$result" $logfile } pgf wrote: > > I'm not sure what a --nostop would do. All I call is "restart" now, not > "stop". If they don't want "restart" either, then... why would they > run this script? The only thing that happens right now when unplugging > the device is a log message. > I realise that didn't make a lot of sense without an explanation that, for me, the obvious missing function is to stop squeezelite when the DAC is powered down - so a '/usr/local/etc/init.d/squeezelite stop' command in the second section of the script. That way, squeezelite will come and go with the DAC. Clearly you personally don't need that function, so you'd be a candidate for the --nostop option, which would prevent any of the commands in the second section from being triggered. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
> The cardname is then part of the $OUTPUT variable, e.g. > "hw:CARD=DragonFly,DEV=0", from which 'DragonFly' would need to be > extracted. > I can make that be the default, but I'll allow overriding it on the command line. > 2) Do you have any thoughts on the frequency that this script checks for > the DAC? You've currently set 4 seconds, but how much of a drain on > resources would it cause if that was, say, 1 second? Maybe make this a > command line argument? > Anything would work. I can make it 1 second. I confess it makes me twitch a little, but 1 second is eons in modern computer clock speed time. > 3) If you put the log file in /var/log/, and precede its name with > 'pcp_', it will show up in the pCP -> Diagnostics -> Logs page, so users > won't have to use a separate shell to see what's going on. It needs root > permissions to write to this folder, but I think that's OK because User > Commands are run as root. > Okay. Didn't know about that. Can do. > 4) For my own setup I prefer that Squeezelite is soft powered on when > the DAC is turned on, regardless of its previous soft power state, so > I've been learning about the necessary JSON commands to do that this > evening. So for my own copy I'm going to add a function to do that and > add it to the commands that are run when the device appears. > You go guy! I have no idea what you're talking about. :-) > 5) There's at least one user of the udev script who does not want > Squeezelite to be killed when the DAC is powered off. I added the > --nostop option so that the 'remove' udev rule was omitted in the > installation. I wonder if a --nostop command line option could be added > to your script to achieve the same result. > I'm not sure what a --nostop would do. All I call is "restart" now, not "stop". If they don't want "restart" either, then... why would they run this script? The only thing that happens right now when unplugging the device is a log message. > Whilst I'll be happy to do these modifications for myself, I'm more than > keen to see how an experienced programmer would make them . I > learn a little bit more every time I look at someone else's code. > Don't worry -- my sense of ownership will fade very quickly, and I'll be happy to let you take over. ;-) pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > Since you're thinking of looking at my script, here's a cleaned up > version. It makes it a little more obvious where to put one's > commands. > > I call it "watch_usb_audio". > That's great - so many neat little tricks that I've not seen before, as befits a busybox contributor! Thanks for posting. I shall enjoy playing with that tomorrow. Some immediate thoughts: 1) Audiodev can be read from /usr/local/etc/pcp/pcp.cfg. That would make it completely general, and would mean it doesn't need a command line argument. It would also mean it would adapt to a different DAC when it is configured in the pCP Squeezelite settings. I did this in the udev script with Code: cardname=$(cat /usr/local/etc/pcp/pcp.cfg | grep ^OUTPUT | awk -FCARD= {'print $2'} | awk -F, {'print $1'}) but I saw the pCP team's much neater way of doing it in the init.d script: Code: # Read from config file . /usr/local/etc/pcp/pcp.cfg The cardname is then part of the $OUTPUT variable, e.g. "hw:CARD=DragonFly,DEV=0", from which 'DragonFly' would need to be extracted. 2) Do you have any thoughts on the frequency that this script checks for the DAC? You've currently set 4 seconds, but how much of a drain on resources would it cause if that was, say, 1 second? Maybe make this a command line argument? 3) If you put the log file in /var/log/, and precede its name with 'pcp_', it will show up in the pCP -> Diagnostics -> Logs page, so users won't have to use a separate shell to see what's going on. It needs root permissions to write to this folder, but I think that's OK because User Commands are run as root. 4) For my own setup I prefer that Squeezelite is soft powered on when the DAC is turned on, regardless of its previous soft power state, so I've been learning about the necessary JSON commands to do that this evening. So for my own copy I'm going to add a function to do that and add it to the commands that are run when the device appears. 5) There's at least one user of the udev script who does not want Squeezelite to be killed when the DAC is powered off. I added the --nostop option so that the 'remove' udev rule was omitted in the installation. I wonder if a --nostop command line option could be added to your script to achieve the same result. Whilst I'll be happy to do these modifications for myself, I'm more than keen to see how an experienced programmer would make them :). I learn a little bit more every time I look at someone else's code. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Heh. Yup. pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Very nice. A minor point, I think your second comment should read: "# commands to run when the device is unplugged go here". coyrls's Profile: http://forums.slimdevices.com/member.php?userid=44253 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Since you're thinking of looking at my script, here's a cleaned up version. It makes it a little more obvious where to put one's commands. I call it "watch_usb_audio". Code: #!/bin/sh exec >/home/tc/watch_usb_audio.log 2>&1 audiodev=$1 usage() { cat <&2 usage: $0 audio-device-name The only argument to this script should be your USB audio device name, as seen in /proc/asound. On my machine my Harman Kardon Soundsticks show up as "Soundsticks": $ ls -F /proc/asound Headphones@ card1/ hwdeppcm version SoundSticks@ cardsmodules seq/ card0/ devices oss/ timers EOF exit 1 } if [ ! "$audiodev" ] then usage fi log() { echo $(date +%Y-%m/%d-%X) "$@" } device_present() { test -e /proc/asound/$audiodev } wait_for_device() { while ! device_present do sleep 4 done } wait_for_device_to_go_away() { while device_present do sleep 4 done } watch_usb_audio() { while : loop forever do wait_for_device log $audiodev is now present # commands to run when the device is plugged in go here alsactl restore /usr/local/etc/init.d/squeezelite restart wait_for_device_to_go_away log $audiodev has vanished # commands to run when the device is plugged in go here done } log "Watching for USB device '$audiodev'" if ! device_present then log Device not present at startup. Will wait... fi watch_usb_audio & pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > > More good advice, thank you. But why is it a bad habit? > > When a process receives a signal, it usually has a chance to do something -- in fact, some signals are -only- used for "doing something", and don't kill a process by default. They might be used to tell the process to re-read its config file, for instance. But even if it's being told to die (which is what SIGTERM, the default signal from kill) is usually used for, it still might want to flush some output buffers, or if it has created its own pidfile, it might want to remove it. At the very least, the process might want to log that it's dying because of a signal. So it would do any of those things before calling exit. Now, a misbehaved (or buggy) process might catch your SIGTERM signal and then not exit. That's what SIGKILL (i.e., kill -9) is for. SIGKILL can't be caught and handled by a process -- it just kills it immediately. If you use it by habit, you may be preventing the process you're killing from doing an orderly shutdown. Kind of like pulling the plug on your PC instead of typing shutdown. It'll usually be fine when you start it back up, but then that one time ;-) pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > Just a nit. This line, from your script, does _not_ create the pidfile > using sudo: > > Code: > > sudo /bin/echo "$PID" > $PIDFILE > > > > Ooh, thank you - I did wonder about that. Thanks for the tip about tee. pgf wrote: > > I still don't believe that "kill" will do anything different than > /bin/kill, given the two are running in an identical environment. (I > also don't believe you should be using "-9" everywhere. Squeezelite > dies perfectly happily with a plain "kill". Using -9 is a bad habit.) > More good advice, thank you. But why is it a bad habit? pgf wrote: > > I do have a couple of other comments on and questions about your script, > if you don't mind. Not that I see anything explicitly wrong, but maybe > they can be simplified, and simpler code is easier and safer. > > First: > Is there any reason not to just use the shell to find the binary? And, > why does it matter if it's a symlink. > I copied this code from the init.d script. I believe it uses this approach because of the pCP option to use a bespoke squeezelite binary instead of the supplied one. Not sure about the symlink stuff. pgf wrote: > > Second: > Anything wrong with letting the shell tell you the PID? That's what $! > is for. It always contains the pid of the last process put into the > background. > Yeah, that's my code. And I didn't know better. Now I do :) pgf wrote: > > Lastly, even though you're no longer using the init.d script to > start/stop the daemon, you're still using it to check the daemon's > status. But all it does when you ask, is checks to see if the pidfile > exists. You should also also check to see if the process represented by > that pidfile exists. You can do that with the "-0" option to kill: > The init.d script does check whether a process with the same PID as the one in the pidfile is running: Code: status) # Check if our squeezelite daemon is running. if [ -f $PIDFILE ]; then PID=`cat $PIDFILE` PIDS=`/bin/busybox pgrep $DAEMON | awk '{printf "%s ", $1}'` for GOTPID in $PIDS; do if [ x"$GOTPID" = x"$PID" ]; then echo "$PNAME is running. PID=$PID" exit 0 fi done fi echo "$PNAME not running." exit 1 ;; I think this approach allows for the possibility that a user might start a second squeezelite process via a command line, e.g. a bluetooth player. pgf wrote: > Anyway, I'm sure you'll figure out your problem. You set yourself a > lofty goal when you started this project, and you've done well so far! > I'm more and more starting to think that your approach would be a better way to do this! As a user command, it would probably avoid all the issues around the start-stop-daemon behaving differently under udev. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > > I can't recall whether I've tried modifying the init.d script to use > sudo with the start-stop-daemon. Something else to try Made no difference. The daemon was unable to stop the process on my Pi3A+. I have a new Pi4B arriving tomorrow*, so I'm going to start afresh with virgin pCP7 images just to make sure I'm comparing like with like. *Bought it from Digikey, only because I needed something to take me over the free carriage threshold. So that saved me £13, and it was £11 cheaper than in the UK as well, so £24 'saved'. It would have been rude not to. :) chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > Thanks for taking a look in that much detail. I'd love to agree with > your final statement, but I've been very careful to make sure that the > pidfile and the process stay in sync. My current test script avoids the > init.d script altogether - it starts Squeezelite manually (it doesn't > use 'sudo', but since it's called by udev the process is owned by root > anyway), and the pidfile is created with 'sudo bin/echo...' (perhaps the > sudo isn't necessary for the same reason that the script is run under > udev). > Just a nit. This line, from your script, does _not_ create the pidfile using sudo: Code: sudo /bin/echo "$PID" > $PIDFILE The echo runs as sudo, but the redirection into the pidfile is done as the non-sudoed script. In the shell language, redirections belong to the shell, not the command that they're redirecting. There are various workarounds, but the most popular I think is to use tee to write the file for you. (It turns out there aren't that many programs which will simply take stdin and put it into a file. Using tee for this is convenient, even if you have to discard the output from tee itself.) Code: echo $PID | sudo tee $PIDFILE >/dev/null As you say, the distinction should be moot, if it's being run from udev, so as I said, this is just a nit, and an FYI. > > > So with everything in sync, the default 'kill' is NOT able to kill the > process, whereas /bin/kill IS. In both cases, the kill command is being > called directly by the udev script (i.e. without invoking the > start-stop-daemon) in response to the DAC being unplugged, > > And of course there's the other thorny little complication that the > behaviour of 'start-stop-daemon stop' is different on my Pi4B, where it > works. I still don't believe that "kill" will do anything different than /bin/kill, given the two are running in an identical environment. (I also don't believe you should be using "-9" everywhere. Squeezelite dies perfectly happily with a plain "kill". Using -9 is a bad habit.) I do have a couple of other comments on and questions about your script, if you don't mind. Not that I see anything explicitly wrong, but maybe they can be simplified, and simpler code is easier and safer. First: Code: # Set DAEMON to the actual binary [ -f $TCEMNT/tce/squeezelite ] && DAEMON=`readlink $TCEMNT/tce/squeezelite` || DAEMON=/usr/local/bin/squeezelite # Legacy check, incase this is the binary instead of symlink. [ "$DAEMON" = "" ] && DAEMON=$TCEMNT/tce/squeezelite Is there any reason not to just use the shell to find the binary? And, why does it matter if it's a symlink. Code: DAEMON=$(which squeezelite) Second: Code: $DAEMON -n "$NAME" .& sleep 1 local PID=$(/bin/busybox pgrep $DAEMON | /usr/bin/awk '{print $1}') sudo /bin/echo "$PID" > $PIDFILE Anything wrong with letting the shell tell you the PID? That's what $! is for. It always contains the pid of the last process put into the background. Code: $DAEMON -n "$NAME" & echo $! >$PIDFILE Lastly, even though you're no longer using the init.d script to start/stop the daemon, you're still using it to check the daemon's status. But all it does when you ask, is checks to see if the pidfile exists. You should also also check to see if the process represented by that pidfile exists. You can do that with the "-0" option to kill: Code: if [ -e $PIDFILE ] && kill -0 $(cat $PIDFILE) then echo process is running else echo no process found fi Anyway, I'm sure you'll figure out your problem. You set yourself a lofty goal when you started this project, and you've done well so far! paul pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > One more possible gotcha with the init.d script: > I'd say this counts as an edge case that is unlikely to arise, because in normal operation pCP runs everything as root and everything stays in sync nicely. I don't believe these possible loopholes are what's behind the inability of the start-stop-daemon, on some devices, to kill the squeezelite process when invoked by a udev rule. But I could be wrong :) I can't recall whether I've tried modifying the init.d script to use sudo with the start-stop-daemon. Something else to try chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > > > So with everything in sync, ... > That's a bit of a red herring in this particular case, since my test script calls the kill command without regard to the pidfile - purely for test purposes of course. I then tidy up if necessary by deleting both the pidfile and the squeezelite process to get back to a known state. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
coyrls wrote: > In bash, you can disable a builtin with "enable -n" but the busybox > shell is ash, not bash and ash does not have the enable command. I have > struggled to find decent documentation for ash but what I have found > doesn't document any way to disable builtins. What is the issue with > using /bin/kill as the command? Thanks for looking into this. I have no issue with calling /bin/kill directly, but I wondered if the start-stop-daemon was relying on the default kill command. pgf has confirmed that it is using the system kill command however. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
pgf wrote: > > I think there are a lot of places where scripts and test cases can go > wrong without needing to investigate the kill command itself. > Thanks for taking a look in that much detail. I'd love to agree with your final statement, but I've been very careful to make sure that the pidfile and the process stay in sync. My current test script avoids the init.d script altogether - it starts Squeezelite manually (it doesn't use 'sudo', but since it's called by udev the process is owned by root anyway), and the pidfile is created with 'sudo bin/echo...' (perhaps the sudo isn't necessary for the same reason that the script is run under udev). So with everything in sync, the default 'kill' is NOT able to kill the process, whereas /bin/kill IS. In both cases, the kill command is being called directly by the udev script (i.e. without invoking the start-stop-daemon) in response to the DAC being unplugged, And of course there's the other thorny little complication that the behaviour of 'start-stop-daemon stop' is different on my Pi4B, where it works. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
One more possible gotcha with the init.d script: run the start script, using sudo. run the stop script, without sudo. the pid file is now gone, but the squeezelite processes are still there. run the start script again, using sudo. the script doesn't see a pidfile, so it starts a new squeezelite, and records its pid. but that squeezelite can't run, because another instance is already running. so it dies. you still have the old squeezelite running, but the pidfile is now incorrect. Code: ==kitchen(tc)>> sudo killall squeezelite ==kitchen(tc)>> sudo rm -f /var/run/squeezelite.pid ==kitchen(tc)>> sudo /usr/local/etc/init.d/squeezelite start Starting Squeezelite player: Squeezelite... ==kitchen(tc)>> cat /var/run/squeezelite.pid 4918 ==kitchen(tc)>> /usr/local/etc/init.d/squeezelite stop Stopping Squeezelite player: Squeezelite... start-stop-daemon: warning: killing process 4918: Operation not permitted ==kitchen(tc)>> cat /var/run/squeezelite.pid cat: can't open '/var/run/squeezelite.pid': No such file or directory ==kitchen(tc)>> sudo /usr/local/etc/init.d/squeezelite start Starting Squeezelite player: Squeezelite... ==kitchen(tc)>> ps | grep s[q]ueeze 4918 root 0:00 /usr/local/bin/squeezelite -n kitchen -o hw:CARD=SoundSticks,DEV=0 -a 80 4 1 -m 00 00 00 00 00 41 -s localhost ==kitchen(tc)>> cat /var/run/squeezelite.pid 4944 Honestly, chill, I'm surprised you've done as well as you have, given the tools you're working with. :-) pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
kill (from within ash) and /bin/kill (linked to busybox) are the same program, almost. The version in ash has to first handle job ids ("kill %2"), but then the common code is called. start-stop-daemon doesn't invoke a kill program at all. Like any reasonable program, it simply invokes the kill() system call itself. But decades of doing shell programming on unix/linux tell me that your problem isn't because kill isn't doing its job. There's something else wrong -- either kill isn't really being invoked, or its trying to kill the wrong process, or the pidfile contains the wrong pid, or something. Regarding the script /usr/local/etc/init.d/squeezelite: if it finds /var/run/squeezelite it thinks it's running. If it doesn't find it, it thinks it's not. That would be fine, except: If I kill squeezelite manually, with killall squeezelite, or pkill squeezelite, the processes go away, but the pid file remains. If (after removing /var/run/squeezelite.pid) I invoke "/usr/local/etc/init.d/squeezelite start" *without* sudo, squeezelite will happily start, running as the user "tc", but the pidfile won't be created (because tc doesn't have permissions to write to /var/run). Running the script again whether as tc or as root, yields "Squeezelite is not running.", simply because the pid file doesn't exist. Alternatively, if I run the ".../squeezelite start" with sudo, and then run the "stop" without sudo, then of course the processes are left running (tc doesn't have permission to kill them), but the pidfile is removed!! That's because the init.d script uses "sudo rm -f $PIDFILE". Sigh. If it's going to remove the pid file with sudo, it should invoke start-stop-daemon with sudo. But really, why is a system script using sudo at all?? I think there are a lot of places where scripts and test cases can go wrong without needing to investigate the kill command itself. paul pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > That makes sense, thank you. > > So assuming that's the case, is there a way to override the default, > such that 'kill' (specified without a path) will use the busybox version > in /bin? > > It still seems possible that the start-stop-daemon is using the default > external command, rather than doing the same thing as kill via its own > source code, so I'd like to change the default and see if the behaviour > of the start-stop-daemon changes. In bash, you can disable a builtin with "enable -n" but the busybox shell is ash, not bash and ash does not have the enable command. I have struggled to find decent documentation for ash but what I have found doesn't document any way to disable builtins. What is the issue with using /bin/kill as the command? coyrls's Profile: http://forums.slimdevices.com/member.php?userid=44253 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
coyrls wrote: > I think the "default" kill will be the shell built in version. > That makes sense, thank you. So assuming that's the case, is there a way to override the default, such that 'kill' (specified without a path) will use the busybox version in /bin? It still seems possible that the start-stop-daemon is using the default external command, rather than doing the same thing as kill via its own source code, so I'd like to change the default and see if the behaviour of the start-stop-daemon changes. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
I think the "default" kill will be the shell built in version. coyrls's Profile: http://forums.slimdevices.com/member.php?userid=44253 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > I have a theory that I'd like to test, but I'm not sure how. > > I've now methodically repeated my earlier tests on my troublesome > Pi3A+. > 1) Called from within my own script (bypassing the init.d script), the > command 'start-stop-daemon --stop -p $PIDFILE' reports that it has > stopped the process, but the process stays running. > 2) If I replace that command with 'sudo kill -9 $PID', the process stays > running. > 3) If I replace that command with 'sudo /bin/kill -9 $PID', the process > is successfully killed. > 4) From the command line, all three of these methods successfully kill > the process. > > So 1-3 versus 4 shows there's something different about the udev > environment compared to a normal user shell. > Hmm, this is odd - /bin/kill IS the same as the default kill. Code: tc@pCP:~$ type kill; which -a kill kill is a shell builtin /bin/kill tc@pCP:~$ ll /bin/kill lrwxrwxrwx1 root root 7 Jan 1 1970 /bin/kill -> busybox But it behaves differently: Code: tc@pCP:~$ kill --help sh: bad signal name '-help' tc@pCP:~$ /bin/kill --help BusyBox v1.31.1 (2020-12-18 22:25:41 EST) multi-call binary. Usage: kill [-l] [-SIG] PID... Send a signal (default: TERM) to given PIDs -l List all signal names and numbers chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
I have a theory that I'd like to test, but I'm not sure how. I've now methodically repeated my earlier tests on my troublesome Pi3A+. 1) Called from within my own script (bypassing the init.d script), the command 'start-stop-daemon --stop -p $PIDFILE' reports that it has stopped the process, but the process stays running. 2) If I replace that command with 'sudo kill -9 $PID', the process stays running. 3) If I replace that command with 'sudo /bin/kill -9 $PID', the process is successfully killed. 4) From the command line, all three of these methods successfully kill the process. So 1-3 versus 4 shows there's something different about the udev environment compared to a normal user shell. But the theory I want to test is that the start-stop-daemon is using the default kill. I'm guessing that in fact it's simply using the same source code within busybox, so there'll be no way to change that. But if it is instead calling the default binary for the kill command, how can I change the default binary to be the one in /bin? Assuming the default kill command is a symlink to the busybox command, can I replace that symlink with one that points to /bin/kill, and if so, how? If I can do that I could then repeat the test with the start-stop-daemon to see if that has forced it to use /bin/kill. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > > @Bogg - it would be good to know if this version still works in your > case. Just replace the entire script. No need to re-run the install, > unless you give this script a different name. > v1.1.0 - 'workaround' version to bypass start-stop-daemon Hi Chill, I can confirm v1.1.0 works perfectly on my 3B (non plus) It kills and restarts many times in a row without fail, and starts when booted without dac. Everything appears great. Bogg's Profile: http://forums.slimdevices.com/member.php?userid=50888 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
I'm not sure how to tackle finding out why the start-stop-daemon doesn't work consistently, but in the meantime... The path available from within my udev script is: Code: /sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin Compare that with the path available from a user shell: Code: /home/tc/.local/bin:/usr/local/sbin:/usr/local/bin:/apps/bin:/usr/sbin:/usr/bin:/sbin:/bin:/etc/sysconfig/tcedir/ondemand I've made a full version of the 'workaround' script - one that doesn't use the start-stop-daemon at all, and which fully implements all the proper squeezelite settings in the same as the start-stop-daemon. I simply lifted the code directly from the daemon. I don't like to do this because it's a duplication of code, and if the start-stop-daemon gets updated to cope with new Squeezelite options this will also need to be updated. But unless, or until, I get to the bottom of the start-stop-daemon issues this can serve as a working generalised version for now. @Bogg - it would be good to know if this version still works in your case. Just replace the entire script. No need to re-run the install, unless you give this script a different name. v1.1.0 - 'workaround' version to bypass start-stop-daemon +---+ |Filename: SQLITE-control.sh_v1.1.0.zip | |Download: http://forums.slimdevices.com/attachment.php?attachmentid=33714| +---+ chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Greg Erskine wrote: > I notice Paul has installed the gawk/awk extension, probably gnu?. You > have to be careful not to develop code on requires the use of the full > blown version of the command without handling the installation of the > extension. > > We have been caught before installing gnu wget. We used the -s option > and it is not available, gnu wget uses --spider. Ooops. My bad. I thought I was fetching examples on a fairly pristine pCR, but I had misremembered, and was using the one I'd installed the development toolchain on. So the fact that gnu awk was installed on my machine has no bearing on chill's problems. Sorry for any confusion. But that's something to check Bogg's (was that who it was?) system -- are there extensions installed that could change how things work? paul pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
I notice Paul has installed the gawk/awk extension, probably gnu?. You have to be careful not to develop code on requires the use of the full blown version of the command without handling the installation of the extension. We have been caught before installing gnu wget. We used the -s option and it is not available, gnu wget uses --spider. Greg Erskine's Profile: http://forums.slimdevices.com/member.php?userid=7403 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > Thanks again - very instructive, and it gives me something to look into > tomorrow. I know that the path available to a script called by udev is > indeed rather shorter than the one available under a user shell (i'll > post it again tomorrow). But does this make a difference if a command > is part of busybox? If it's part of busybox, does it even bother to > look in the path for a separate binary? Or do I have this wrong, and > the busybox commands ARE all separately linked to somewhere in the > path? > You answered your own question: the busybox builtins (like awk, sort, not the ash builtins like cd and alias) are found via PATH, because they're symlinked into various traditional bin directories. If a busybox builtin isn't linked into any of those places (unlikely) it can still be run with "busybox cmd ..." if need be. But they won't be found "automatically" simply because they're part of busybox. > And assuming the busybox built-in version is found, what could cause a > built-in command to fail when called in the udev environment (on some > setups), whereas the explicitly specified binary doesn't? > I don't know the answer to that. It's possible that the behavior of busybox is affected by environment variables (I could imagine a variable to enforce POSIX compliance, for instance). But other than that, invoking by full path shouldn't change anything, unless the full path is getting you a different executable (as in the case of the two awks on the system). paul pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Thanks again - very instructive, and it gives me something to look into tomorrow. I know that the path available to a script called by udev is indeed rather shorter than the one available under a user shell (i'll post it again tomorrow). But does this make a difference if a command is part of busybox? If it's part of busybox, does it even bother to look in the path for a separate binary? Or do I have this wrong, and the busybox commands ARE all separately linked to somewhere in the path? And assuming the busybox built-in version is found, what could cause a built-in command to fail when called in the udev environment (on some setups), whereas the explicitly specified binary doesn't? And the other thing that's puzzling me - what could explain the 'stop' part of the start-stop-daemon working on some setups and not others, when the setups are based on the same pCP base. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
> For instance, awk --help reports 'BusyBox v1.31.1 (2020-12-18 22:25:41 > EST)' when called as either awk or /usr/bin/awk, whereas '/bin/echo > --help' reports 'BusyBox v1.31.1 (2020-12-18 22:25:41 EST)' but without > the path it simply echoes '--help'. So I'm curious where the separate > executables come from. Are some simply links to the busybox versions, > whereas others are standalone binaries? Yeah, it can get confusing. On pcp, a command can be provided by a) ash itself, b) a busybox builtin (invoked either via a symlink from 'cmd' to busybox, or "busybox 'cmd'"), or c) from a separate executable entirely. bash is friendlier than ash in that it provides a builtin command called "type" which, if you invoke "type -a cmd" will tell you everywhere in your shell, or along your PATH that 'cmd' can be found. Sadly, ash's "type" command has no '-a' option, and will only tell you about the first version of 'cmd' that's available, and will stop. So "type echo" only prints "echo" (note the absence of slashes) and "type awk" only prints "/usr/local/bin/awk". The good news is that "which -a" will find everything in your PATH. So you if you use both commands, you get all the information you need. Some might be duplicated. So: Code: $ $ type echo; which -a echo echo is a shell builtin /bin/echo $ ls -l /bin/echo lrwxrwxrwx1 root root 7 Jan 1 1970 /bin/echo -> busybox* $ $ type awk; which -a awk awk is /usr/local/bin/awk /usr/local/bin/awk /usr/bin/awk $ $ ls -l /usr/local/bin/awk /usr/bin/awk lrwxrwxrwx1 root root17 Jan 1 1970 /usr/bin/awk -> ../../bin/busybox* lrwxrwxrwx1 root root34 Jan 1 1970 /usr/local/bin/awk -> /tmp/tcloop/gawk/usr/local/bin/awk* There are two versions of echo on the system. I'd be surprised if they behave differently -- since they're both provided by busybox. There are also two versions of awk, but in this case one is provided by busybox, and the other by an extension. I suspect the built-in version is more primitive than the external one. So I suspect udev is invoked with a different PATH than you're using. Most likely it doesn't include /usr/local/bin -- if I were writing critical system code, I wouldn't rely on /usr/local/bin either. paul pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Yeah, I was wrong about 'restart' killing the old process. It doesn't on the Pi3A+. Ok, so that's slightly more consistent - the 'stop' function of the daemon doesn't seem to work at all. I tried making the init.d script use /sbin/start-stop-daemon, but it made no difference. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Thanks Paul, that's all useful information. I've noticed that some of these commands that don't seem to work without specifying a path seem to be exactly the same versions in the default shell and in the specific binary location, whereas some seem to be different. For instance, awk --help reports 'BusyBox v1.31.1 (2020-12-18 22:25:41 EST)' when called as either awk or /usr/bin/awk, whereas '/bin/echo --help' reports 'BusyBox v1.31.1 (2020-12-18 22:25:41 EST)' but without the path it simply echoes '--help'. So I'm curious where the separate executables come from. Are some simply links to the busybox versions, whereas others are standalone binaries? I've reverted to the original script on my Pi3A+, where the start-stop-daemon apparently won't 'stop' the process, but it does 'start' it. But I'm getting very confused and will probably call it a day very soon. I'm getting confused because: 1) The script doesn't call the start-stop-daemon itself - it calls the init.d script which uses the start-stop-daemon appropriately. 2) When I call the init.d script to 'stop' squeezelite, the process doesn't actually get killed 3) When I call the init.d script to 'restart' squeezelite, the old process gets killed and a new one is started. The odd thing about this is that to do a 'restart', the init.d script simply asks the daemon to do a 'stop' followed by a 'start'. So why does 'stop' on its own not work, whereas 'stop' followed by 'start' does? I need to double check this behaviour again, Pi3A+ versus Pi4B, because it doesn't make sense. I've tried loading bash and forcing my script to run under bash, as well as forcing the init.d script to run under bash, but neither seem to make the start-stop-daemon successfully stop squeezelite. The start-stop-daemon seems to be part of busybox. It would be interesting I think to look at the source code to try and understand what it actually does. And maybe I should try making the init.d script use /sbin/start-stop-daemon instead of the default version, but I note that both versions report 'BusyBox v1.31.1 (2020-12-18 22:25:41 EST)'. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
chill wrote: > > Anyone know how I can check for these built-in commands from within a > script? What makes them 'built-in' - is it some default shell > configuration? Could I manually load that configuration at the start of > the script, so that even if these built-in commands aren't available to > udev they would be to the script? I can probably help with this. I used to contribute patches and bug fixes to busybox pretty often -- we were using it in an embedded product I was working on. First, there are two kinds of "built in" with regards to the shell. All shells (ash, bash, zsh, csh) have some number of commands that are implemented internally to the shell. "cd", for instance, couldn't be done by an external program -- the external program would change directroy, and exit, and leave the shell where it always was. So "cd", "alias", "bg", fg", "read", etc are always built-in, because they have to be. "echo" and "kill" don't have to be, but for efficiency they usually are. echo is built-in for efficiency, kill is built in because it can be smarter if it is. Note that just because a command like echo or kill is built-in to the shell, it doesn't mean there isn't also a regular program by that name in the filesystem. Try "type -a echo" or "type -a kill" at a bash prompt, for instance. That lets other programs besides the shell run them if they need to. All of the above is true with or without busybox. Busybox adds another layer of "builtin-ness". When two programs are compiled (like "mv" and "cat", say) they end up containing a lot of redundant code. Even if they both use shared libraries for things like printf, or for reading and writing files, they still each have their own argument parsing, their own usage message, maybe some other common code idioms. If you took mv.c and cat.c and merged them into one executable called "twoprogs", you could imagine that "twoprogs" might be smaller than the sum of the sizes of the separate mv and cat. And you could still get with behavior with "twoprogs mv file1 file2" or "twoprogs cat file". Busybox is a merge like that, of a whole lot of programs. Do an "ls -l /sbin /bin /usr/bin | less" on a pcp box, and/or type "buybox --help" to get a list of all of the programs that are merged into one. And now, back to your problem: if awk isn't working without a full path, or pgrep isn't working without "busybox pgrep", it's really unlikely to be busybox's fault. busybox is a very mature program (I worked on it over 10 years ago), and is really unlikely to have the problems you're describing. (awk, for instance, isn't part of busybox -- it's an extension, I believe.) I'll stop now. paul pgf's Profile: http://forums.slimdevices.com/member.php?userid=58510 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
I'll keep subscribing for the future updates, and just enjoy how well things work for now. Thanks Bogg's Profile: http://forums.slimdevices.com/member.php?userid=50888 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Bogg wrote: > I'm very very grateful for all the effort you have taken Chill. I though > when I first posted that I had just made a simple mistake that someone > would point out and I'd be up and running like everyone else. Instead I > caused hours of work to resolve all kinds of problem. > > Should I consider that script gold standard, no future changes needed, > or are you likely to still tinker some more? I certainly wouldn't treat it as the final version. Even when I believe there's nothing else to do there's always more to learn, as this example shows! But in this case I -know- there's more to do - this was only really a test to work around a problem, and as a result, as mentioned, your Squeezelite configuration is currently hard-wired. Any changes you make via the pCP Squeezelite page won't be reflected in this script. That aspect needs fixing, and I suspect that the longer-term solution will depend on finding out why the start-stop-daemon doesn't work in some cases. chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
I'm very very grateful for all the effort you have taken Chill. I though when I first posted that I had just made a simple mistake that someone would point out and I'd be up and running like everyone else. Instead I caused hours of work to resolve all kinds of problem. Should I consider that script gold standard, no future changes needed, or are you likely to still tinker some more? Bogg's Profile: http://forums.slimdevices.com/member.php?userid=50888 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
I'm very very grateful for all the effort you have taken Chill. I thought when I first posted I'd made a simple mistake that someone would point out and I'd be up and running like everyone else. Instead I caused hours of work to resolve all kinds of problems. Should I consider that script gold standard, no future changes needed, or are you likely to still tinker some more? Bogg's Profile: http://forums.slimdevices.com/member.php?userid=50888 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Bogg wrote: > Success Again ! > And better tested this time. I've on and off half a dozen times in a > row, and it's reacted perfectly every time ! > The pcp web and skins are always in sync, sqlite is always killed, and > always comes back. > I've even rebooted pcp with the dac off. sqlite doesn't start, and > switch on dac, and sqlite starts ! > > It's fantastic :D Excellent, thank you. That's how it's supposed to work! So I reckon the failure of the start-stop-daemon and the non-functioning of the built-in commands (echo, awk, kill etc) must be related. It's odd that things work on some installations and not on others. If the daemon was called from the USB script itself I could try prefixing it with its path (/sbin/start-stop-daemon), but it's not - it's the init.d script that calls it. I guess I could try that with my own Pi3A+ setup to see if that fixes it, but that wouldn't be a viable option for the script, since the init.d script isn't readily editable for end users. Anyone know how I can check for these built-in commands from within a script? What makes them 'built-in' - is it some default shell configuration? Could I manually load that configuration at the start of the script, so that even if these built-in commands aren't available to udev they would be to the script? chill's Profile: http://forums.slimdevices.com/member.php?userid=10839 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix
Re: [SlimDevices: Unix] Start/restart squeezelite when plug-in USB dac
Success Again ! And better tested this time. I've on and off half a dozen times in a row, and it's reacted perfectly every time ! The pcp web and skins are always in sync, sqlite is always killed, and always comes back. I've even rebooted pcp with the dac off. sqlite doesn't start, and switch on dac, and sqlite starts ! It's fantastic :D Bogg's Profile: http://forums.slimdevices.com/member.php?userid=50888 View this thread: http://forums.slimdevices.com/showthread.php?t=113661 ___ unix mailing list unix@lists.slimdevices.com http://lists.slimdevices.com/mailman/listinfo/unix