Setup as a systemd service
Rahil Bhimjiani edited on Feb 22, 2024.
These instructions require you to have compiled the vaultwarden binary. If you generated a docker image, you may want to look at Running with systemd-docker
Setup
Making vaultwarden start on system startup and use the other facilities of systemd (e.g. isolation, logging,...) requires a .service file. The following is a usable starting point:
Change all paths to match your installation (WorkingDirectory and ReadWritePaths should be the same),
name this file vaultwarden.service and put it into /etc/systemd/system.
If you have to change an existing systemd file (which was provided to you by the package you installed), you can add your changes by using
To make systemd aware of your new file or any changes you made, run
Usage
To start this "service", run
To enable autostart, run
In the same way you can stop, restart and disable the service.
Updating vaultwarden
After compiling the new version of vaultwarden, you can copy the compiled (new) binary and replace the existing (old) binary and then restart the service:
Uninstalling vaultwarden
Before doing anything else, you should stop and disable the service:
Then you can delete the binary, the environment file, the web-vault folder (if installed) and the user data (if necessary). Remember to also remove specially created users,groups and firewall rules (if needed) and the systemd file.
After removing the systemd file you should make systemd aware of it via:
Logging and status view
If you want to see the logging output, run
or to see a more concise state of the service, run
Troubleshooting
Sandboxing options with older systemd versions
In RHEL 7 (and debian 8), the used systemd does not support some of the used isolation options. (#445,#363) This can result in one of the following errors:
or
To work around this you can comment out some or all of these settings by putting a # in front of the lines containing
PrivateTmp, PrivateDevices, ProtectHome, ProtectSystem and ReadWritePaths. While commenting out all of them will probably work, it's not recommended as these are security measures which are good to have. To see which options your systemd supports, look at the output of
to determine your systemd version and compare with systemd/NEWS.md.
After editing your .service file, don't forget to
before (re-)starting your service.
Service fails to start
The following error shows in the systemd journal (journalctl -eu vaultwarden.service):
This is known to occur when vaultwarden is running inside a container (LXC, et al) or natively. The parameter LimitNPROC=64 in the service file prevents the service from starting. Commenting out that particular parameter results in the service starting correctly.
Note: A systemd override file will not work, the line must be commented out/removed. The easiest way to do this is via
then reloading the daemon & restarting.
Environment variables are not loaded
Please note that systemd does not support comments in the same line as a variable in the EnvironmentFile=/etc/vaultwarden.env file (see #1607). In this environment file example the variable WEBSOCKET_ENABLED will not be loaded.
If you want same-line comments consider using /var/lib/vaultwarden/.env instead (which will also get rid of the .env file missing INFO on startup).
More information
For more information on .service files, see the manpages of systemd.service and (for the security configuration) systemd.exec