The ways to start Direwolf at boot, as provided in the manual, are quite archaic and hacky. Let’s see how we can do this in a more modern way using systemd.
Why I don’t like the solution provided in the manual
In the paragraph “5.9 Automatic Start Up After Reboot” the direwolf manual suggests using /etc/rc.local to start direwolf on boot. rc.local is an ancient way to do stuff on boot. However it has several drawbacks:
- No logging
- You are not sure when it is called i.e. if all the system resources you need are already available
- AFAIK it has been deprecated since debian 9 (yet it is still working if you create it manually)
- No way to restart direwolf automatically if, for whatever reason, it fails
To address the latter problem the manual suggests to configure (dw-start.sh) a shell script as a cron job. Executing the script every minute. This will force direwolf to restart endlessly until by banging the shell script every minute! But what if for some reason I really want to stop direwolf for a while? It’s impossible as the script will restart it right away… Not good…
Why it is better to do it using systemd?
- Start and stop direwolf whenever I want
- I can add other services which rely on direwolf and have them started after direwolf
- Automatically restart direwolf when it fails
- It is the way of doing such things on a modern Linux distro
Doing it the SystemD way
Using direwolf directly as a systemd (Type=simple) resulted in a strange effect: the service was never going out of the start phase, thus i decided to rely on tmux. Using tmux also brings the ability to observe what direwolf is doing at any moment, even with the fancy colored output!
Install tmux
Code language: Bash (bash)sudo apt install tmux
Now we can create our systemd unit: create the following file /etc/systemd/system/direwolf.service you will need to adapt the command line to fit your own needs i.e. path to your config file
[Unit]
Description=Direwolf
After=network.target
[Service]
Type=forking
#Modify the end of the line below to fit your own needs i.e path to your configuration file
ExecStart=/usr/bin/tmux new-session -d -s direwolf '/usr/local/bin/direwolf -c /home/pi/direwolf.conf'
Restart=always
[Install]
WantedBy=default.target
Code language: Makefile (makefile)
Next step enable the service
sudo systemctl enable direwolf.service
Code language: Bash (bash)
If everything went OK you can now start the service using
Code language: Bash (bash)sudo systemctl start direwolf.service
To stop it
Code language: Bash (bash)sudo systemctl stop direwolf.service
Request its status
sudo systemctl status direwolf.service
Code language: CSS (css)
To attach to the tmux terminal in order to watch direwolf do its thing
sudo tmux attach -t direwolf
Conclusion
That’s it! We have direwolf running as a systemd service. There are a couple of things that could be improved though, but I leave them for later as I am so far happy wiht how it is working.
- Do not run as root user
- Templated systemd unit in order to specify the config file.