-
Notifications
You must be signed in to change notification settings - Fork 0
Description
The last step in the configuration task #270 #276 is to load the config from the topside onto the raspberrypi's and restart the control software on each of these devices. I think the best way to do this would be to write a desktop script which scp's the files to the devices and then restarts.
Brief overview on how we launch the software, and how the configs play into this.
Each of the Raspberry pi's have a service on the operating system called systemd. Systemd is a program which reads service in a Unit file. Our application is run by systemd by launching our custom unit file eer.service found at playbooks/files/etc/systemd/system/eer.service. The command itself is the ExecStart command:
ExecStart=/usr/bin/java -cp "/opt/eer-{{ version }}/libs/*" {{ entry_point }} \
--default /opt/eer-{{ version }}/defaultConfig.yml \
--config /home/{{ ansible_user }}/config.yml--default is the base configuration file you see under the playbooks/files directory. This file gets copied to the pi's every deploy. --config is the override config. This is the file that we want to replace using the topside script.
You'll notice this command has a lot of weird notation in it {{ variable }}. That is the ansible-playbooks templating language. As the file is copied using the template command, all of these variables get replaced with strings.
- name: Copy unit file for systemd
template: src=files/etc/systemd/system/eer.service dest=/etc/systemd/system/eer.service mode=644This is what the file looks like after a deloy:
// on rasprime
ExecStart=/usr/bin/java -cp "/opt/eer-9.0.0/libs/*" com.easternedgerobotics.rov.Rov \
--default /opt/eer-9.0.0/defaultConfig.yml \
--config /home/pi/config.yml
// on picamera A
ExecStart=/usr/bin/java -cp "/opt/eer-9.0.0/libs/*" com.easternedgerobotics.rov.PicameraA \
--default /opt/eer-9.0.0/defaultConfig.yml \
--config /home/pi/config.yml
// on picamera B
ExecStart=/usr/bin/java -cp "/opt/eer-9.0.0/libs/*" com.easternedgerobotics.rov.PicameraB \
--default /opt/eer-9.0.0/defaultConfig.yml \
--config /home/pi/config.ymlAs you can see, each of the raspberry pi's launch a different class as the entry point into the software. This is how each device knows what role to play.
What are desktop files?
Desktop files are pretty similar to the systemd files. They define a few characteristics about the application and also have an Exec command (similar to ExecStart). We also use ansible to template them. Take Launcher.Desktop for example:
Exec=/usr/bin/java -cp "/opt/eer-{{ version }}/libs/*" {{ entry_point }}
--default=/opt/eer-{{ version }}/defaultConfig.yml
--config=/home/{{ ansible_user }}/config.yml
// which gets transformed into:
Exec=/usr/bin/java -cp "/opt/eer-9.0.0/libs/*" com.easternedgerobotics.rov.Topside
--default=/opt/eer-9.0.0/defaultConfig.yml
--config=/home/eedge/config.ymlThe file we use to create the commands are a little more complicated. Look at eer-command-vehicle:
{% for host in groups['rasprime'] %}
sshpass -p raspberry ssh pi@{{ host }} "sudo $COMMAND"
{% endfor %}
{% for host in groups['picamera'] %}
sshpass -p raspberry ssh pi@{{ host }} "sudo $COMMAND"
{% endfor %}This is grabbing information from the hosts file to create multiple lines in the output. This transforms into:
sshpass -p raspberry ssh pi@192.168.88.4 "sudo $COMMAND"
sshpass -p raspberry ssh pi@192.168.88.5 "sudo $COMMAND"
sshpass -p raspberry ssh pi@192.168.88.6 "sudo $COMMAND"Which is then called by the desktop scripts, eg Poweroff.desktop:
Exec=eer-command-vehicle poweroffThe $COMMAND variable in this case gets set to poweroff
Moving the configs:
An easy way to move the configs would be to use an scp call
Exec=eer-command-vehicle "scp eedge@192.168.88.2:~/config.yml ~/config.yml"
//transforms into
sshpass -p raspberry ssh pi@192.168.88.X "sudo scp eedge@192.168.88.2:~/config.yml ~/config.yml"We then need to reset the control software. To do this we need to ask systemd to reset it, as systemd is what manages our application. To do this we need to make a call to systemctl
Exec=eer-command-vehicle "systemctl restart eer"
//transforms into
sshpass -p raspberry ssh pi@192.168.88.X "sudo systemctl restart eer"Now the tricky part is running two commands from the one desktop file. Normally a desktop file is only allowed to run a single command, but in our case we need to run two. There's a few ways we can go about this, but I'm going to leave it to you to mess around with and research.
We're also going to need to deploy this file onto the topside.. this means you'll have to update the playbooks/topside.yml file to get it onto the eedge desktop.
This is a lot of info that I wrote fairly quickly. Feel free to ask any questions, or for clarification!!