3

I am a little confused about how runtime parameters are normally supplied to a systemd service. The general idea I have is that the following happens:

There is a file that contains the environment variable settings, e.g., /etc/sysconfig/mydaemon

Then there is the unit file, e.g., mydaemon.service (not sure where this is located)

Inside of the unit file is a line such as the following:

EnvironmentFile=-/etc/sysconfig/mydaemon

When the service is started, the settings file is opened then each setting is supplied to main as argc/argv. Is that right?

  • See this blog post for a start. A service file doesn't accept arguments to my knowledge. You must pass the service file variable options contained in the file referenced by the EnvironmentFile – eyoung100 Sep 17 '14 at 20:39
  • I did actually read that blog before I posted. It does not make everything clear. For example, it does no explain how the service code accesses the options settings, among other things. – Tyler Durden Sep 17 '14 at 20:55
  • 1
    Also, just as an aside, why is there a dash in the EnvironmentFile setting shown above? – Tyler Durden Sep 17 '14 at 20:56
  • Look at the section under Configuration. That file snippet is a plain .conf file stored in /etc You can write to and store variables in that file then pass the filename in the EnvironmentFile line. To actually pass the values use the ExecFile line and pass the options through string expansion. – eyoung100 Sep 17 '14 at 21:04
  • 5
    Re: Dash. From the systemd.exec man page: The argument passed should be an absolute filename or wildcard expression, optionally prefixed with "-", which indicates that if the file does not exist, it will not be read and no error or warning message is logged. – eyoung100 Sep 17 '14 at 21:07
2

The EnvironmentFile option should be set to the full path of the file containing any necessary environment variables needed for proper operation of the executable.

Arguments to the executable can be included in the "ExecStart" parameter. This mechanic is separate and distinct from the "EnvironmentFile" option. You can find more documentation at http://www.freedesktop.org/software/systemd/man/systemd.service.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.