In this article, you will learn how to make MMDVMHost automatically start when your Raspberry Pi is turned on.
The automatic start of MMDVMHost
On the Raspberry Pi, there are two solutions (the ones I know) to automatically launch software when the Raspbeery Pi is turned on (or rebooted), running under Raspbian.
Simple startup
To start MMDVMHost automatically, the easiest solution is to edit this startup file and add the command line to start MMDVMHost before the statement exit 0
sudo nano /etc/rc.local
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. # Print the IP address _IP=$(hostname -I) || true if [ "$_IP" ]; then printf "My IP address is %s\n" "$_IP" fi sudo /opt/MMDVMHost/MMDVMHost /opt/MMDVMHost/MMDVM.ini exit 0
Starting with declaring a MMDVMHost service
Another solution, a little more elegant is to create a service.
Prerequisites
Installation of screen
sudo apt-get install screen
Creating the service file
sudo nano /lib/systemd/system/mmdvmhost.service
[Unit] Description=MMDVM Host Service After=syslog.target network.target [Service] User=root WorkingDirectory=/opt/MMDVMHost ExecStart=/usr/bin/screen -S MMDVMHost -D -m /opt/MMDVMHost/MMDVMHost /opt/MMDVMHost/MMDVM.ini ExecStop=/usr/bin/screen -S MMDVMHost -X quit Restart=always RestartSec=10 [Install] WantedBy=multi-user.target
In the [Service] section, the last two lines make it possible to restart MMDVMHost in the event of a crash. It should be noted that it is very rare to be confronted with unexpected stops of MMDVMHost. We will test the proper functioning of the restart further down in the article.
The MMDVMHost launch directories shown here correspond to those used during the MMDVMHost install tutorial.
Creating the launch timer file
The start of the service is delayed after 60 seconds after startup
sudo nano /lib/systemd/system/mmdvmhost.timer
[Timer] OnStartupSec=60 [Install] WantedBy=multi-user.target
Enforcement and service
sudo chmod 755 /lib/systemd/system/mmdvmhost.service sudo chmod 755 /lib/systemd/system/mmdvmhost.timer sudo ln -s /lib/systemd/system/mmdvmhost.service /etc/systemd/system/mmdvmhost.service sudo ln -s /lib/systemd/system/mmdvmhost.timer /etc/systemd/system/mmdvmhost.timer
We can restart the service manager
sudo systemctl daemon-reload
Now the MMDVMHost service is ready to start. At this point, we can start the service without restarting.
sudo systemctl start mmdvmhost.service
Verification of Service Operation
You can verify that the service launch MMDVMHost, by appearing in processes (ps) with the following statement. Must be displayed 3 rows.
sudo ps aux | grep MMDVMHost
root 9657 1.0 0.6 5192 2684 ? Ss 16:19 0:00 /usr/bin/SCREEN -S MMDVMHost -D -m /opt/MMDVMHost/MMDVMHost /opt/MMDVMHost/MMDVM.ini root 9662 18.2 1.2 15140 5436 pts/0 Ssl+ 16:19 0:00 /opt/MMDVMHost/MMDVMHost /opt/MMDVMHost/MMDVM.ini pi 9777 0.0 0.4 4268 1956 pts/1 S+ 16:19 0:00 grep --color=auto MMDVMHost
For verify the operation of the service, you will have access to the MMDVMHost log with the following command
sudo screen -r MMDVMHost
The operating status of the service is returned with this command
sudo systemctl status mmdvmhost.service
● mmdvmhost.timer Loaded: loaded (/lib/systemd/system/mmdvmhost.timer; enabled) Active: active (elapsed) since Sat 2017-05-20 16:33:10 CEST; 13min ago May 20 16:33:10 raspberrypi systemd[1]: Starting mmdvmhost.timer. May 20 16:33:10 raspberrypi systemd[1]: Started mmdvmhost.timer.
Let’s now test the automatic restart.
Step 1: The service is running, MMDVMHost is present in the list of processes:
sudo ps aux | grep MMDVMHost
root 9657 1.0 0.6 5192 2684 ? Ss 16:19 0:00 /usr/bin/SCREEN -S MMDVMHost -D -m /opt/MMDVMHost/MMDVMHost /opt/MMDVMHost/MMDVM.ini root 9662 18.2 1.2 15140 5436 pts/0 Ssl+ 16:19 0:00 /opt/MMDVMHost/MMDVMHost /opt/MMDVMHost/MMDVM.ini pi 9777 0.0 0.4 4268 1956 pts/1 S+ 16:19 0:00 grep --color=auto MMDVMHost
Step 2: We will kill the MMDVMhost process with
sudo killall MMDVMHost
Step 3: Immediately check the list of processes.
sudo ps aux | grep MMDVMHost
pi 6360 0.0 0.4 4268 1828 pts/0 S+ 16:37 0:00 grep --color=auto MMDVMHost
There is only one line left … But 10 seconds later, the same command again displays the 3 lines. MMDVMHost has been restarted!
root 6609 0.0 0.6 5192 2812 ? Ss 16:37 0:00 /usr/bin/SCREEN -S MMDVMHost -D -m /opt/MMDVMHost/MMDVMHost /opt/MMDVMHost/MMDVM.ini root 6613 6.4 1.3 16712 5920 pts/2 Ssl+ 16:37 0:03 /opt/MMDVMHost/MMDVMHost /opt/MMDVMHost/MMDVM.ini pi 7852 0.0 0.4 4268 1856 pts/0 S+ 16:38 0:00 grep --color=auto MMDVMHost
Other command
To stop the service
sudo systemctl stop mmdvmhost.service
Conclusion
Vous aurez compris que la seconde solution présentée et qui consiste à démarrer MMDVMHost en tant que service est plus robuste grâce à la fonction offerte par le service de redémarrer automatiquement MMDVMHost sur arrêt intempestif.
Au besoin les commentaires sont ouverts ci-dessous pour vos remarques, ou questions.