Here are the instructions to run the Dragonfly App positioning at computer’s start-up in a “forever” manner (meaning that in the rare eventuality that Dragonfly crashes, it is automatically restarted and only a clean termination can avoid the automatic re-start) on Ubuntu.
Step 1 – Auto start the positioning and auto re-start Dragonfly in case of crashes
These are the steps to create a script that automatically starts the positioning when the Dragonfly App is launched and automatically re-start the Dragonfly App in case of crashes.
- Install cURL with this command!
sudo apt install curl
- Go to Dragonfly’s root directory, where
dfja-2.4.0.21-dist.jar
resides. - Create a file called
start-forever-navigation.sh:
touch start-forever-navigation.sh
- Fill it with the following content:
#!/bin/bash
function start_dragonfly() {
dragonfly_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $dragonfly_dir
java -jar dfja-2.4.0.21-dist.jar &
dragonfly_pid=$!
while [[ -z `curl -s localhost:5000/api/v1/utils/status -X GET | grep "\"state\": 1"` ]]; do
sleep 1
done
curl -s -o /dev/null localhost:5000/api/v1/maps/MAP_NAME -X GET
sleep 7
curl -s -o /dev/null localhost:5000/api/v1/positioning/start -X PUT
wait $dragonfly_pid
return $?
}
until start_dragonfly; do
echo "Server 'Dragonfly' crashed with exit code $?. Respawning.." >&2
sleep 1
done
- Make the script executable:
chmod +x start-forever-navigation.sh
Step 2 – Launch Dragonfly automatically at start-up
These are the steps to automatically launch the Dragonfly App at computer’s start-up.
- Run the following command to open the crontab editor. NOTE: at first start, you may be asked for a text editor, please select
nano
as it is the easiest to use:
crontab -e
- Add the following line:
@reboot /home/path_to_the_directory_where_the_start_forever_navigation_resides/start-
forever-navigation.sh
- Save with
Ctrl+O
and quit withCtrl+X
.