Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm trying to use the variables defined in /etc/environment in an upstart script running on 12.04.

I'm able to export the variable to the child process but for some reason I not able to use them in the Upstart script stanza itself.

This works:

script
    . /etc/environment
    export NODE_ENV
    # node is able to read the NODE_ENV, wonderful!
    /usr/local/bin/node /path/to/app/app.js
end script

But if I try to introduce some conditional logic within the stanza then it will fail:

script

    . /etc/environment
    export NODE_ENV

    # ${NODE_ENV} is not set inside the stanza
    if [[ ${NODE_ENV} = 'production' ]]; then

        # this will never run
        /usr/local/bin/node /path/to/app/app.js
    fi

end script

Any ideas how I can access variables from sourced files inside the stanzas?

share|improve this question

1 Answer 1

up vote 3 down vote accepted

This line:

if [[ ${NODE_ENV} = 'production' ]]; then

is not valid in a POSIX-compliant shell, but does seem to be valid bash. I don't see the shell that upstart uses by default in script stanzas documented anywhere, but it's reasonable to assume that it uses /bin/sh, which is not bash on Debian/Ubuntu systems.

Try:

if [ "${NODE_ENV}" = 'production' ]; then

instead.

share|improve this answer
    
thanks, I tried this but it still doesn't work unfortunately. I took a look at the logs and this is what it's outputting: /proc/self/fd/9: 12: /proc/self/fd/9: [[staging: not found. This seems to indicate it's a problem with the conditional and not the variable to me. Very odd! the TERM env varible = LINUX not xterm if this makes any difference. –  techjacker Mar 25 '13 at 15:54
    
On second try this worked, thank you very much! It turns out that the double brackets were the real problem. –  techjacker Mar 25 '13 at 16:09

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.