In systemd is there a mechanism or a configuration file which will set defaults for the systemd execution environment configuration for ALL services? Including user created ones.
For example if we want to have all systemd services use specific values for RestrictAddressFamilies or Personality or PrivateTmp then right now we have to go and modify each and every service file. That is hardly optimal. But if there is a configuration file or some setting somewhere maintained so that all systemd services use the the configuration/setting thus maintained then that would be great.
You could create the directory /etc/systemd/system/service.d and drop in a file in there (.conf) with your configuration options.
You can use top-level drop-in files to affect all units of the same type. For example, a drop-in file in /etc/systemd/system/service.d/ affects all .service units.
Sorry for such a late response. My previous laptop had clonked.
Does this mean that for system provided services, it is not recommended to modify the unit file directly, rather create a drop-in_files instead? Using the command systemctl edit *unit* --drop-in=*drop_in_name*
And for putting in drop-in-file in the systemd service.d directory what will be the command?
I don’t know if i would say not recommended, if you know what you are doing there should be no problem, but update will probably reset it and in case you get a problem it would be WAY easier to edit/delete one or two drop-in files rather than searching all your services for what you changed.
What I wanted to know whether it has a similar layout as other unit files? So for example can i simply copy the file /etc/systemd/system/bluetooth.target.wants/bluetooth.service into the /etc/systemd/system/service.d directory, delete all the keys that I do not want to change and then retain only the keys I want to change?
Just use systemctl edit <unit>. That will automatically create an override file and puts it in the right place. That (small) override config will then always be merged with the (full) file provided by the system, therefore if the system file gets updated your override will stay in place.
That’s a good way to do it, @Schlaefer give the easiest and safest way, but sometime you prefer to have one modification in one file and another modification in another file, with systemctl edit, it’s only one file.
Last time, I didn’t copy the service file, I just created a new file.