2

I have a systemd service that is making use of DynamicUser and StateDirectory in the unit file, so the service can be restarted freely without losing data. However sometimes I want to completely clean up any persistent data and start it from a blank state, can I do that with some parameters to the systemctl stop command?
EDIT: I'm looking for an official parameter supported by systemctl that will clear all persistent data, not a way to pass arguments to my script.

Qtag
  • 115

2 Answers2

2

From the manual of systemd.exec:

The directories specified with StateDirectory=, CacheDirectory=, LogsDirectory=, ConfigurationDirectory= are not removed when the unit is stopped.

There is no official argument supported by systemd that clears these directories. You can use a script to do that.

Fanatique
  • 5,153
1

You can use systemctl clean:

$ systemctl clean unit-name
Iizuki
  • 121