How Do You Fix a .service File for systemctl Commands to Work?

Problem scenario
You have a bash command that works reliably. But when it is in a .service file (e.g., the ExecStart stanza) the corresponding systemctl command with systemctl start fails. You have tried putting quotes around the arguments in the ExecStart stanza. Using your .service file with systemctl almost works; but there is an unlogged failure that you do not expect. The service (e.g., Logstash or some other service) fails quickly. What should you do when it is calling a reliable bash command?

Possible Solution
If the argument path in ExecStart is like this /full/path/to/ -f /path/to/file.txt do three things: one, remove the quotes. Two, replace -f flag with "--path.settings" (retaining the quotes around the --path.settings). Three, remove the file name file.txt from the second argument but put quotes around the second argument.

It will look like this (with the quotes):
/full/path/to/ "--path.settings" "/path/to/"

Note that the file itself is removed from the second argument. The second argument has the path to the file, but lacks the exact file name.

If the above "Possible solution" does not work you may want to try creating the .service file with a template in an automatic fashion. Creating them by hand manually can be prone to errors.

Leave a comment

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