How do you append to environment variable in Upstart?

5,359

Solution 1

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.

Solution 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

Solution 3

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

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

Share:
5,359

Related videos on Youtube

nickponline
Author by

nickponline

Updated on September 18, 2022

Comments

  • nickponline
    nickponline almost 2 years

    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.

    • edwin
      edwin almost 10 years
      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.
  • kominato
    kominato about 7 years
    What does this have to do with upstart and why is it accepted?