Basically title. Is there a way? Or a hacky way, whatever. There's no "ConditionPermissions=", "ConditionOwnership=" or something like that, as far as I can see.
- Can you elaborate on your use case?Haxiel– Haxiel2021-08-19 13:41:24 +00:00Commented Aug 19, 2021 at 13:41
- Purely my interest, to be frank. You can make sure the permissions are correct using ExecStartPre=chmod / chown, but I want to know if it's possible to check and prevent the service from starting.centosuser– centosuser2021-08-19 15:35:15 +00:00Commented Aug 19, 2021 at 15:35
1 Answer
If you want to check some file permissions or ownership before starting a systemd service, you can run a script inside the systemd unit file like this example, where I'm checking if a file has different permissions than 644.
[Service] ExecStartPre=/bin/bash -xc 'stat -c %a "myfile" != '644' && exit 1 || exit 0' If ExecStartPre returns an error, then the rest of the startup process is aborted.
Usually this approach is not considered safe, and the best way to do it is to ensure that the permissions are correct by setting them up, instead of doing checks with some conditions.