Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an ArchLinux with systemd, and I've created my own service. The configuration service at /etc/systemd/system/myservice.service looks like this:

  [Unit]
  Description=My Daemon

  [Service]
  ExecStart=/bin/myforegroundcmd

  [Install]
  WantedBy=multi-user.target

Now I want to have an environment variable set for the /bin/myforegroundcmd. How do I do that?

share|improve this question

3 Answers

up vote 2 down vote accepted

The recommended way to do this is to create a file /etc/sysconfig/myservice which contains your variables, and then load them with EnvironmentFile.

For complete details, see Fedora's documentation on how to write a systemd script.

share|improve this answer
I guess the sysconfig path is specific to Fedora but the question is about Arch Linux. The answer by paluh is more interesting I think – Ludovic Kuty Apr 27 at 8:49

http://0pointer.de/public/systemd-man/systemd.exec.html - you have two options (one already pointed by Michael):

Environment=

and

EnvironmentFile=
share|improve this answer

What about just putting the environment variable inside the myforegroundcmd script?

share|improve this answer
well, the whole point of having environment variables is to have them outside my binary, so that I can get different behavior in different installations... – lfagundes Aug 1 '12 at 20:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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