Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

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? I really don't want to have to hardcode this stuff!

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The problem is your use of "[[". Upstart runs all scripts via /bin/sh. See:

If you look at the jobs log, you should see a (shell) error there:

sudo cat /var/log/upstart/your-job.log

share|improve this answer
    
thanks you solved my problem! –  techjacker Mar 25 '13 at 18:16
add comment

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.