Bitwarden @ Debian 12 – starting it via systemd
(Docker based installation of Bitwarden)

Recently I was setting my my own, personal, Bitwarden server. The last step, that left, was to configure systemd service in order to make sure my Bitwarden installation starts up whenever machine is rebooted.

I have spent few hours to solve this issue due to mysterious error inside /var/log/syslog:

dockerd[636]: ... level=warning msg="Error getting v2 registry: 
  Get \"https://registry-1.docker.io/v2/\": 
  dial tcp: lookup registry-1.docker.io on 10.0.0.1:53: 
  dial udp 10.0.0.1:53: connect: network is unreachable"

The problem was that the service was working perfectly fine when started manually. Whenever I called

> systemctl start bitwarden
> systemctl stop bitwarden

everything was working as expected. Even though it was looking fine, server startup was failing whenever system was rebooted. It turned out, this is an issue with network being not quite really alive. It seems like dependency on network.target (this is implied by docker.service) was not enough. Eventually, my service looks like this:

[Unit]
Description=Bitwarden service

Requires=docker.service
After=docker.service

StartLimitInterval=100                       # I want to retry only few times. If it fails
StartLimitBurst=5                            # to start too many times, something is probably broken

[Service]
User=bitwrdn
Group=docker
Type=oneshot                                 # we are using a script that starts everything and quits
RemainAfterExit=true                         # we want to mark service live after return 0
ExecStart=/opt/bitwarden/bitwarden.sh start
ExecStop=/opt/bitwarden/bitwarden.sh stop
Restart=on-failure                           # these two lines makes it really work
RestartSec=10                                # it looks like dependency on docker.service is not enough

[Install]
WantedBy=multi-user.target

Eventually, I am able to run Bitwarden each time machine is restarted. BTW, there is another approach here: https://gitlab.com/ggeurts/extend-network-online.target – haven’t tried this one yet, even though it looks promising.