Servers by jDrones

Start Mavproxy as a service

I tried to make a service that starts mavproxy in my rasperry. I made the service file and put it in systemd, i put the complete part in the exec of the service fie and user pi and all other settings. Once i start it with systemctl the service turns green and doesn’t throw any error but nothing comes out. If i use the same path i use in the service file in the command line it starts and does its things.
Is there anything special i have to add to make it work?
I am at home now and don’t have the file with me but i’ll post it tomorrow. Any help will be greatly appreciated.

Another little question, if i wanted to update my installed mavproxy to the latest release how should i proceed? pip install --upgrade MAVProxy?

Corrado

Here is the script:

[Unit]
Description=My service
After=network.target

[Service]
ExecStart=/usr/local/lib/python3.7/dist-packages/MAVProxy/mavproxy.py --master=/dev/ttyAMA0 --baudrate=115200 --out=udp:10.8.0.100:14550 --aircraft=Quad
WorkingDirectory=/home/pi/
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

p.s. managed to update mavproxy, way easier than i tought, just run “pip install --upgrade MAVProxy” that is all it took.

Hi there!
I am trying to make a MAVProxy start as service as well, but it keeps crashes right away.
There is no error information except: “Process exit with error code” after calling systemctl status.
In the output file there is only standard starting info from MAVProxy and waiting for master.

Do you have any ideas what can be the issue?

P.S. I tried it on Navio image and clean raspbaian as well.

I’d suggest using an init script for Mavproxy (https://ardupilot.github.io/MAVProxy/html/getting_started/mavinit.html), and just a simple call to mavproxy by systemd

Hi, @james_pattison, thanks for answer. Unfortunately, this can’t be done because I need to define outputs depends on system configuration.

Isn’t is possible for you to start mavproxy simply in the /etc/rc.local ? That’s the way I’m doing this (also with different “on-the-fly” generated configurations).

@fingadar Main goal is to monitor mavproxy and restart it if it fail. Also second feature is control when it start, for example after network is working.

But I didn’t try it yet. I will check if it work.

Hello, I am also trying to run mavproxy as a service. But the service exits with status 203, which says it could not find the path to the executable. Did you mange to solve it?

Thanks

@Pavan Hi, after trying a lot of ways, finally found mine.

Create file with settings for service at: /etc/default/pixhawkmavlink

#MASTER settings
DEVICE="/dev/ttyAMA0"
DEVICE_BAUD="921600"

#UDP config
UDP_ADR="255.255.255.255"
UDP_PORT="14550"

Next, create file with service at: /etc/systemd/system/pixhawkmavlink.service

[Unit]
Description=Pixhawk to mavproxy/mavros deamon
#Documentation=
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
User=pi
EnvironmentFile=/etc/default/pixhawkmavlink
ExecStartPre=
ExecStart=/usr/local/bin/mavproxy.py --master=${DEVICE},${DEVICE_BAUD} --out=udpbcast:${UDP_ADR}:${UDP_PORT} --aircraft=pixhawk --cmd="set flushlogs True" --state-basedir="/home/pi/" --daemon
ExecStartPost=
ExecStop=
ExecReload=
Restart=on-failure

[Install]
WantedBy=multi-user.target

At the end, you can create configuration script at: /usr/local/bin/pixhawk_configure.sh or type everything by hand. In my opinion better way is to make script, you will have saved commands if you need to restart it.

#! /bin/bash

sudo systemctl daemon-reload
sudo systemctl enable pixhawkmavlink
sudo systemctl daemon-reload
sudo service pixhawkmavlink start
service --status-all

Launch script with sudo, which will launch the service. After every boot, it will wait for WiFi connection or Ethernet and then launch service.
In the /etc/default/pixhawkmavlink file you can change settings like baudrate or serial device and port for UDP. If you need, you can create your own settings and use it in service file.
You can also change names of files if needed.

Good luck!

Edit: I am working on Navio image with preinstalled mavproxy.

1 Like

Thank you for the answer. I tried it and when I run the service with ExecStart=/usr/local/bin/mavproxy.py…, I get an error ‘No executable found’. I see the Mavproxy is installed in /home/pi/.local/bin/ in the pi. But when I use this path, the service still does not run and the service status says error 203. Is the Mavproxy in your system installed in /usr/local/bin/ ?

We use supervisor https://linoxide.com/linux-how-to/supervisor-monitor-linux-servers-processes/ to launch and monitor processes in our vehicles

Yes, it’s preinstalled.
If in your case its installed in /home/pi seems like you only make installation for user, not root. In this case you could experience problem launching program from different user. Try start mavproxy with sudo, and see whats going on.

So having User as pi and a script with mavproxy launch command in it solved the issue.

User=pi

ExecStart=/usr/bin/screen -DmS mavproxy /home/pi/mavproxylaunch.sh

Thanks

1 Like
Servers by jDrones