How to Correctly Edit systemd’s .service File So That It Does Not Get Overwritten During the Future Upgrades.

Hello beautiful peoples!


Couple of years ago I ran into this issue where amavis service kept crashing on me and that has caused issues with my e-mail server. Solution was found so why am I writing about it? What seems to be the problem? Well… IF I only edited the amavis.service file, reloaded the daemon and restarted the service my solution would work. Temporarily. It would work until one of the future amavisd-new package upgrades overwrites my change and then amavis would crash again and my e-mail server would be dead for few hours… Don’t ask me how I know… Traumatic events… Emotional damage… 😉 Anyroad… How to make this change permanent so that I don’t have to worry about it in the future? Use systemctl edit as root.

sudo systemctl edit amavis

Replace amavis with the name of the service that You’re trying to modify.

You will be presented with something similar to this:


Make the necessary changes in the correct place:


As You can see – there is a section at the top of the file that You need to place the changes in.

Placing changes in the wrong section of the file and saving them will result in error:

Editing “/etc/systemd/system/amavis.service.d/override.conf” canceled: temporary file is empty.


Service file contains sections. They are clearly marked with the square brackets [ and ]. My change falls into the [Service] section. As You can see I added that in my edit. IF You won’t add the correct section when creating override.conf your changes will be ignored and when you’ll query the status of the service You will see something similar to this:

Jul 19 11:57:04 mail.andrzejl.eu systemd[1]: /etc/systemd/system/amavis.service.d/override.conf:1: Assignment outside of section. Ignoring.

So You have edited the file:


IF You made a mistake and You do NOT want to save the file press + and then press .

To save the file press + and confirm with and then .


Now reload the daemon and restart your service

sudo systemctl daemon-reload
sudo systemctl restart amavis


You can now check the status and the modifications of the .service file. Run the following commands:

systemctl status --no-pager amavis

systemctl cat amavis


As You can see the service is active, running and no changes were ignored AND the override.conf is listed below the amavis.service file.

I hope this helps!

Catch you on the flip side,

AndrzejL

Avatar photo

AndrzejL

“Some men just want to watch the world burn.”

Leave a Reply

Your email address will not be published. Required fields are marked *