Starting darkice automatically on Raspbian Buster Lite

Status
Not open for further replies.

csadams

Chris
Feed Provider
Joined
May 12, 2015
Messages
8
Location
Berkeley, CA
Hi, I'm setting up my first feed and running into a few issues, the first of which is that darkice doesn't seem to start on reboot, and that I can't start the service manually after the first reboot.

I followed the instructions on this page: Raspberry Pi Broadcastify Build - The RadioReference Wiki, using Method 1 (darkice). I'm using a Raspberry Pi 3 Model B+, with Raspbian Buster Lite (version July 2019). I'm running it headless, via SSH, so I don't have the UI or any of the options and tools that come with it.

I can successfully run darkice manually and start the stream with a command like the one below:
$ sudo /usr/bin/darkice -c /etc/darkice1.cfg
But then I can't do anything else with my terminal, and if I close the connection, darkice stops.

I followed the instructions to set it up as a service...
The provided darkice1 file was moved to /etc/init.d/darkice1
And I ran the command:
$ sudo update-rc.d darkice1 defaults

Right after doing that for the first time, I ran:
$ sudo service darkice1 start
And the service seemed to start fine... the stream came online (but only the first time).

After a reboot, not only did the stream not start back up, it looked like darkice (or darkice1) was not running as expected.
So I ran the command again:
$ sudo service darkice1 start
It paused for a second or two, then returned me to the command prompt, and when I checked, darkice was not running. Many tests and reboots later, I still can't get it to start with that command or with a reboot.

That said, I did find a suggestion in one thread to try the different command:
$ sudo /etc/init.d/darkice1 start
And it replied with: "Starting darkice Instance #1"... and looks like darkice is running!

But it still won't start automatically on reboot.

Does anyone know what's going on here? Are the tools for starting a service maybe different in this newer version of Raspbian? Any advice on how to set this up to automatically start darkice after every reboot?
 

DC31

Member
Feed Provider
Joined
Feb 19, 2011
Messages
1,547
Location
Massachusetts
I agree, autostarting in Buster does not work well. For that reason I went back to Stretch Lite.

Recent versions of Raspbian use systemd to start programs.


Even with that I have not had good luck with Buster.

The tried and true way that I have used for years and still works under Stretch is to install screen (sudo apt install screen) and then run darkice in a detached screen (screen -dmS darkice-screen darkice -c /etc/darkice.cfg). Then you can close your Terminal.

To start it automatically, put a line in your crontab file (crontab -e):

@reboot screen -dmS darkice-screen darkice -c /etc/darkice.cfg

You can try this method using Buster, it might work, however, you may need to use Stretch as something with crontab and screen seems messed up.
 

csadams

Chris
Feed Provider
Joined
May 12, 2015
Messages
8
Location
Berkeley, CA
Thanks so much for the quick reply!

Bummer that it's so hard to start a service on Buster... seems like that should be pretty basic functionality. Oh well.

Ok, I'll try Stretch... where can I download the image? I can't seem to find anywhere to download it... Is there an equivalent page to Download Raspbian for Raspberry Pi ?

Thanks!
 

csadams

Chris
Feed Provider
Joined
May 12, 2015
Messages
8
Location
Berkeley, CA
Ok, for the record, here's what I did...
  • Flashed my SD card with the image: 2019-04-08-raspbian-stretch-lite.zip
  • Enabled SSH by adding "ssh" file to the card
  • Put card in RPi, booted, logged in remotely via putty
  • $ passwd -> changed password
  • $ sudo raspi-config -> set the timezone (under Localization) and expand the file system (under Advanced)
  • $ sudo reboot
  • $ sudo apt-get update
  • $ sudo apt-get upgrade
  • $ sudo apt-get install git cmake libusb-1.0-0.dev build-essential lame
  • $ sudo apt-get install libmp3lame-dev libvorbis-dev libshout-dev libtwolame0 libtwolame-dev libjack-jackd2-dev
  • $ sudo reboot
  • $ alsamixer -> switch to USB Audio device and set Capture device to level 3
  • $ sudo alsactl store
  • $ wget http://s.broadcastify.com/darkice/darkice_bcfy_v01.tar.gz
  • $ tar zxvf darkice_bcfy_v01.tar.gz
  • $ sudo mv darkice /usr/bin
  • skipped the instruction to run "sudo mv darkice1 /etc/init.d", since we'll be setting up the service a different way
  • $ sudo mv darkice.cfg /etc/darkice1.cfg
  • $ sudo nano /etc/darkice1.cfg -> edit my server, mount, password, and feed description - save & exit
Now, following your instructions...
  • $ sudo apt-get install screen
  • $ screen -dmS darkice-screen darkice -c /etc/darkice1.cfg -> note my config file has a different name
  • $ ps -A | grep dark -> 3342 pts/1 00:00:00 darkice (confirmed it's running, and I can hear the audio via Broadcastify)
  • $ crontab -e -> no cron file found, so it started a new one for me. Chose #2 nano editor
  • Added this line to the bottom of the file: @reboot screen -dmS darkice-screen darkice -c /etc/darkice1.cfg
  • Save & exit nano
Power cycled the RPi, logged back in via SSH, and unfortunately, I do not see darkice or screen running:
  • $ ps -A | grep dark -> nothing
  • $ ps -A | grep screen -> nothing
So... I tried adding a wait time, for network and any other stuff to start up...
  • Edited the line in my cron file to add "sleep 30 && ": @reboot sleep 30 && screen -dmS darkice-screen darkice -c /etc/darkice1.cfg
  • $ sudo reboot
  • Ah-ha! Now after the restart, screen and darkice appear to be running, and I hear my audio!
Awesome, seems to be working, after a hard reboot (power cycle), and not logging into the RPi again... the audio starts streaming on its own.

I'll start another thread with my next question... about how to debug the repeated clicking sounds I hear on my audio stream. It has actually been very useful for setup and testing (to know there's sound coming through), but I want to get rid of it for the final stream.

Thanks so much for your help!
 

csadams

Chris
Feed Provider
Joined
May 12, 2015
Messages
8
Location
Berkeley, CA
Yes, it is!

The 8+ hours of tearing my hair out over this, on the other hand, could have been spent much better.

Do you know if there's a way to update the documentation so that others can avoid this frustration?
 

DC31

Member
Feed Provider
Joined
Feb 19, 2011
Messages
1,547
Location
Massachusetts
Users are supposed to be able to edit the Wiki, but I have never invested the probably 10 hrs to figure out how.
 

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669
can I inquire why you didn't just make darkice a systemd service and let systemd run & monitor it?
 

csadams

Chris
Feed Provider
Joined
May 12, 2015
Messages
8
Location
Berkeley, CA
@a417 I tried that several times, in different ways, and was not able to get it to work. Possible I was just doing it wrong, but I couldn't figure it out.

@DC31 Interesting, Looks like standard wiki stuff. After some figuring out of the 2-level login, I was able to edit the page and add a troubleshooting section with the instructions for what I did. Thanks again.
 

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669
I initially eschewed systemd (and most of poettering's other work, like avahi and PulseAudio (wanna fix underruns in GRC....ditch pulseaudio) for running things as my learning process brought me up in the init scripts/SysV pathway.

I got fed up hacking cron tabs & rc.local scripts and watchdogs early on in my raspi streaming days as an in house audio source for my GnuRadio SDR, and I (probably took more time than ever) read a how-to on how to get a very simple service started, and then just moved my rtl_tcp over to a systemd service and literally never looked back.

Were you guys having "I can't write a service file" issues, or "I can't get systemd to run it"? It seems like a big change of philosophy (well, it is) but once I got a dirt simple "rtl_tcp.service" running, I was sold. I have never had to go log in and then run headless, I can get notification as to how and why it failed/crashed, and I can even decide where in the boot process I want it to load (no more delays for delay sake).

I don't use it in ALL of my installs, but I use it here. As for pulseaudio, that thing can go rot. Poettering is 1 for 2 in my book.
 

DC31

Member
Feed Provider
Joined
Feb 19, 2011
Messages
1,547
Location
Massachusetts
Do you run darkice as a service? If so, could you please share your Unit File? Obviously, it is over my head as well as csadams. When there is a relatively simple fix that just works, it is not worth the time investment to try to do it a better way. I am a retired engineer, not a computer programmer. My knowledge of python and linux is strictly trial and error, mostly the latter.
 

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669

scroll down about halfway, there is a pretty solid darkice service file for both user & root permissions at the bottom.


I run rtl_tcp as as service to stream the IQ locally to my network for various things, but the premise is exactly the same.
 

DC31

Member
Feed Provider
Joined
Feb 19, 2011
Messages
1,547
Location
Massachusetts
You are still over my head!

But, after a couple minutes of trial and error, not too much error this time, I believe that I have made a .service file that starts darkice:



[Unit]

Description=My service

After=network.target



[Service]

ExecStart=/usr/bin/darkice -c /etc/darkice1.cfg

Restart=always

User=pi



[Install]

WantedBy=multi-user.target
 

DC31

Member
Feed Provider
Joined
Feb 19, 2011
Messages
1,547
Location
Massachusetts
And, since I am locked into running pulseaudio as a requirement for another program on the pi:

[Unit]

Description=My service

After=network.target



[Service]

Environment=PULSE_SOURCE=alsa_input.usb-Solid_State_System_Co._Ltd._USB_PnP_Audio_Device-00.analog-mono

ExecStart=/usr/bin/darkice -c /etc/darkice1.cfg


Restart=always

User=pi



[Install]

WantedBy=multi-user.target



Thanks for the hints on making this work.
 

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669
No problem, I run RTL TCP from a 9 line service file much like yours (i don't need the environment line - you might not either, ymmv) and it just works. I figure systemd can babysit it and make sure it's running, and then you don't need to log in and run it headless as a poor man's daemon.

I figure systemd can do that well enough alone.
 

DC31

Member
Feed Provider
Joined
Feb 19, 2011
Messages
1,547
Location
Massachusetts
So the one hitch that I have found so far. The systemd file starting darkice works on Raspbian Stretch but fails when I try the same thing on Buster.

pi@buster-sdr:~ $ sudo systemctl status darkice.service
● darkice.service - LSB: Live audio streamer
Loaded: loaded (/etc/init.d/darkice; generated)
Active: active (exited) since Sat 2019-09-21 18:48:33 EDT; 1h 5min ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 4035)
Memory: 0B
CGroup: /system.slice/darkice.service

Sep 21 18:48:33 buster-sdr systemd[1]: Starting LSB: Live audio streamer...
Sep 21 18:48:33 buster-sdr systemd[1]: Started LSB: Live audio streamer.
pi@buster-sdr:~ $

Top shows no instance of darkice running.
 

a417

Active Member
Joined
Mar 14, 2004
Messages
4,669
that's because it's not.

for some reason it says its active(exited).
if it was working, it would say active(running) and then give you non-zero tasks & memory data, and the CGRoup would have the active process treespan below it.

Code:
sudo journalctl -u (yourservicename)
this code should report back all the journalctl logging for your service

I would also make sure that the command in your EXEC START is fully capable of running the program if you cut & pasted it into the command line
 
Status
Not open for further replies.
Top