2

I put the following in my /etc/init/myjob.conf file but it doesn't seem to work

env PATH=$PATH:/mnt/data/src
env PYTHONPATH=$PYTHONPATH:/mnt/progs/link

Is it possible to somehow append to an environmental variable.

1
  • What do you mean by "it doesn't seem to work"? If you explain to us what you are trying to do, we might be able to help you better.
    – edwin
    Jul 12, 2014 at 3:23

4 Answers 4

2

You can't append variables inside an upstart script, you need to use an external file and source it inside a script section:

create a /etc/default/myjob file with content like:

env PATH=$PATH:/mnt/data/src
env PYTHONPATH=$PYTHONPATH:/mnt/progs/link
export PATH
export PYTHONPATH

then in /etc/init/myjob.conf source it where you need it

script 
    . /etc/default/myjob
    exec command
end script

while this would look unnecessary complicated it is actually correct because an init script file is supposed to change between packages version while /etc/default/appname are configuration files and aren't overwritten by default

1

You add them as env VAR=foo in your upstart config file:

http://upstart.ubuntu.com/cookbook/#environment-variables

0

You can put the following into your /etc/environment file:

PATH="/mnt/data/src:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

PYTHONPATH="/mnt/progs/link"

Of course, this method won't "append", but it shouldn't be necessary due to this are the main environment variables, and other applications should append to them.

-2

export PATH=~/bin:"$PATH"

You should add this in ~/.bashrc file to work at every user session.

You should restart to see it working or try . .bashrc command to work without restart.

1
  • 1
    What does this have to do with upstart and why is it accepted?
    – user301031
    Jun 21, 2017 at 11:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .