systemd unit file improvements #418

Open
opened 2025-11-20 05:11:05 -05:00 by saavagebueno · 2 comments
Owner

Originally created by @sebastianschauenburg on GitHub (Aug 12, 2023).

Describe the problem
After a reboot, netbird fails to start using the systemd unit file netbird.service. Example of an error which is visible:

aug 11 12:48:14 hostname systemd[7480]: netbird.service: Failed to set up standard output: No such file or directory

I'm using a Ubuntu 23.04 system with netbird 0.22.3 (installed via apt).

To Reproduce

  1. Set up /var/log as RAM log with (for example) log2ram.
  2. Reboot the system
  3. View the error logs

Expected behavior
No errors and a working netbird interface

Additional context

/var/log/netbird is created at a certain point, but was not synced to the persistent /var/log (if available). So effectively, after a reboot, the /var/log/netbird directory does not exist. This in turn means it cannot be used for stdout and stderr.
I tried creating it with an ExecStartPre using mkdir inside the unit file, but attaching the stdout and stderr apparently happens before that point and as such, errors with:

aug 11 12:49:36 hostname systemd[8997]: netbird.service: Failed at step STDOUT spawning /usr/bin/mkdir: No such file or directory

Proposed solution
Add this to the unit file, which ensures client.log can be created / updated:

ExecStartPre=/usr/bin/mkdir /var/log/netbird

Remove the following lines, since that output should be captured inside of systemd (journalctl) anyway:

StandardOutput=file:/var/log/netbird/netbird.out
StandardError=file:/var/log/netbird/netbird.err
Originally created by @sebastianschauenburg on GitHub (Aug 12, 2023). **Describe the problem** After a reboot, netbird fails to start using the systemd unit file ```netbird.service```. Example of an error which is visible: aug 11 12:48:14 hostname systemd[7480]: netbird.service: Failed to set up standard output: No such file or directory I'm using a Ubuntu 23.04 system with netbird 0.22.3 (installed via apt). **To Reproduce** 1. Set up /var/log as RAM log with (for example) [log2ram](https://github.com/azlux/log2ram). 2. Reboot the system 3. View the error logs **Expected behavior** No errors and a working netbird interface **Additional context** ```/var/log/netbird``` is created at a certain point, but was not synced to the persistent /var/log (if available). So effectively, after a reboot, the ```/var/log/netbird``` directory does not exist. This in turn means it cannot be used for stdout and stderr. I tried creating it with an ```ExecStartPre``` using ```mkdir``` inside the unit file, but attaching the stdout and stderr apparently happens before that point and as such, errors with: aug 11 12:49:36 hostname systemd[8997]: netbird.service: Failed at step STDOUT spawning /usr/bin/mkdir: No such file or directory **Proposed solution** __Add__ this to the unit file, which ensures ```client.log``` can be created / updated: ExecStartPre=/usr/bin/mkdir /var/log/netbird __Remove__ the following lines, since that output should be captured inside of systemd (journalctl) anyway: StandardOutput=file:/var/log/netbird/netbird.out StandardError=file:/var/log/netbird/netbird.err
saavagebueno added the feature-requestsystem-compatibility-issue labels 2025-11-20 05:11:05 -05:00
Author
Owner

@hg commented on GitHub (Nov 22, 2023):

For future reference: the canonical way to fix this is to add:

CacheDirectory=netbird
ConfigurationDirectory=netbird
LogDirectory=netbird
RuntimeDirectory=netbird
StateDirectory=netbird

under the [Service] section.

systemd will then make sure to create the appropriate directories and give your service full access to them before starting the daemon:

  • /var/cache/netbird
  • /etc/netbird
  • /var/log/netbird
  • /var/run/netbird
  • /var/lib/netbird

It's not immediately obvious how to add this to netbird service install since netbird relies on a third-party (not really) package for its service management, and the Option field I see there does not "accept" these keys.

@hg commented on GitHub (Nov 22, 2023): For future reference: the canonical way to fix this is to add: ```ini CacheDirectory=netbird ConfigurationDirectory=netbird LogDirectory=netbird RuntimeDirectory=netbird StateDirectory=netbird ``` under the `[Service]` section. systemd will then make sure to create the appropriate directories and give your service full access to them *before* starting the daemon: - `/var/cache/netbird` - `/etc/netbird` - `/var/log/netbird` - `/var/run/netbird` - `/var/lib/netbird` It's not immediately obvious how to add this to `netbird service install` since netbird relies on a third-party (not really) package for its service management, and the `Option` field I see there does not "accept" these keys.
Author
Owner

@nazarewk commented on GitHub (Feb 13, 2024):

it's LogsDirectory not LogDirectory, also currently only State and Runtime directories are used?

@nazarewk commented on GitHub (Feb 13, 2024): it's `LogsDirectory` not `LogDirectory`, also currently only `State` and `Runtime` directories are used?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SVI/netbird#418