RaspDAB/Automate operation with Supervisor
m (Hb9egm moved page Automate operation with Supervisor to RaspDAB/Automate operation with Supervisor without leaving a redirect)
(→The contents of the configuration file)
|(One intermediate revision by one user not shown)|
Latest revision as of 16:32, 11 July 2018
 Installing Supervisor
It is time to make the operation automatic, such that when you power up the Raspberry Pi it will start the encoders and the multiplexer and deliver a multiplexed stream to the EasyDAB board.
To do so we use a software package called supervisor (extended information can be found at http://supervisord.org). We first need to install it with
$ sudo apt-get install supervisor
This will probably also install python-meld3 as it needs that package to function correctly.
 Supervisor configuration files folder
In this manual we will put the supervisor configuration files in a folder config in the user's home directory. If you want to put this elsewhere you need to make appropriate changes to the commands shown here. You can do this from a terminal window with
$ mkdir config
or from the graphical file manager. In this folder we make 2 subfolders, supervisor and mux:
$ chdir config $ mkdir supervisor $ mkdir mux
Again, you can also do this with the graphical filemanager.
Now we can make the configuration file for program srv1 (the name is arbitrary, you can use your own names to make identification of the stations easy). Do this for all stations that you want include in the ensemble.
 The contents of the configuration file
Now let's have a look at the configuration file for the encoders. The following are examples:
[program:enc-srv1] # DAB encoding using odr-audioenc command=/usr/local/bin/odr-audioenc -v [URL of audio stream] -C 200 -b 64 -r 48000 -c 2 -o tcp://localhost:59001 -D -L --audio-resampler=samplerate -L --src-converter-type=0 -p 58 -P /tmp/srv1-pad.fifo autostart=true autorestart=true startretries=100 priority=10 stderr_logfile=/var/log/supervisor/enc-srv1.log stdout_logfile=/var/log/supervisor/enc-srv1.log
[program:pad-srv1] # PAD encoding using odr-padenc command=/usr/local/bin/odr-padenc -o /tmp/srv1-pad.fifo -p 58 -t /home/[UserID]/PAD/srv1/DLS/DLS1.txt -d /home/[UserID]/PAD/srv1/MOT autostart=true autorestart=true startretries=100 priority=10 stderr_logfile=/var/log/supervisor/pad-srv1.log stdout_logfile=/var/log/supervisor/pad-srv1.log
So you define a name for the program that supervisor uses to identify the process it governs. In this case 2 programs, the audio encoder and PAD encoder for station srv1.
You declare the command line as if you would invoke the program from a command line in a terminal window. Note that we don't use the more verbose reporting, as this would all be put in the log file, which is not necessary. The next 2 lines tell the supervisor program to start the program automatically, and also restart it when it stops. The number of startretries may seem high, but this is to ensure the audio encoder makes a sufficient number of retries when the connection to the stream server is temporarily lost. Then you can declare the priority, which in our case should all be the same - perhaps with the exception of the multiplexer. And you provide the location of the log files, in this case just one file in which both error and normal log messages are collected.
Make similar files for each station, and put these in the config/supervisor folder.
The configuration file for the multiplexer is similar:
[program:mux] command=/usr/local/bin/odr-dabmux -e /home/[UserID]/config/mux/dab.mux autostart=true autorestart=true priority=100 stderr_logfile=/var/log/supervisor/mux.log stdout_logfile=/var/log/supervisor/mux.log
Note we give this priority 100 to delay the start of the multiplexer to give the processor time to start the NTP protocol and update the time.
 Special Note for Commands that start Child Processes
In certain situations, your command may need to start more than one process. For example:
command=bash -c "rtpdump -F payload 18.104.22.168/5004 | sox -t raw -e signed-integer -r 48000 -c 2 -b 24 -B /dev/stdin -t raw --no-dither -r 48000 -c 2 -b 16 -L /dev/stdout gain 4 | odr-audioenc --format=raw --dab --bitrate=128 --dabmode=j --dabpsy=2 --pad=24 --pad-fifo=/home/dabsys/site/mot/sam.mot --input=/dev/stdin --output=tcp://127.0.0.1:9010" stopasgroup=true
This composite command extracts linear audio from a multicast source (such as Telos Alliance "Livewire" system), piping the audio to sox to convert the audio format and levels and then piping onwards to the odr-audioenc process.
This scenario requires special handling:
- The entire composite command should be specified within the correct shell - in this case, bash. This prevents parsing confusion.
- An additional line is added to the configuration - stopasgroup=true. This tells supervisor to stop this process AND all the child processes it has spawned. If you don't do this, you'll end up with orphaned sox and odr-audioenc processes, which will continue to stream silent packets to the destination.
For each radio program that will be part of the multiplex ensemble you need to create a symbolic link into the /etc/supervisor/conf.d/ folder. This is where supervisor will look for the configuration files. Providing symbolic links will point the program to the files we just created, so supervisor will know the parameters for the audio and PAD encoders and the multiplexer.
Now we can make the symbolic links (assuming 'odr' is your username):
$ sudo ln -s /home/odr/config/supervisor/srv1.conf /etc/supervisor/conf.d/srv1.conf
for the configuration file for program srv1. You should do this for all stations you want to include in the multiplex and the multiplex program configuration file itself.
 Getting Supervisor to work
For every change you make to the configuration files you need to call supervisorctl to reread and update its configuration:
$ sudo supervisorctl reread $ sudo supervisorctl update
This will start supervisord and install it as a deamon, so it will automatically start from now on and start/restart the programs. All services are launched from supervisor, you don't need to start them manually anymore.
To show status of all services :
$ sudo supervisorctl status
To [stop|start|restart] a service :
$ sudo supervisorctl [stop|start|restart] service-name
To apply change after change anything in /home/[UserID]/config/supervisor/ file you need to call supervisor to reread and update configuration.
If you simply type
this will not revert to the command prompt, but you will be able to monitor the supervisor status and issue the commands directly.
Supervisor redirects all logs from the tools to files in /var/log/supervisor/ You may need to ensure yourself that this directory exists. The logs will get rotated according to the policy defined by your distribution. More details in the child logging section of the documentation. Please refer to the official supervisor documentation for more details.
If you have correctly installed all programs and configured them correctly you will now have a micro DAB transmitter, with the audio encoding, PAD encoding and multiplexer in a single Raspberry Pi and the modulator in the EasyDAB v2 board, that will automatically start to encode and multiplex and subsequently modulate and transmit the DAB ensemble as soon as you provide a supply voltage. It may take about a minute for the whole process to start, but once it does it will continue until you remove the supply voltage again.