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 have a /ect/init/application.conf file that looks something like...

start on filesystem and net-device-up IFACE!=lo
stop on runlevel [016]
respawn

export NODE_ENV=production

chdir /home/richie/application
exec /home/richie/.nvm/v0.10.26/bin/node server/app >> /var/log/node.log 2>&1

It is meant to run a Node.js application in production mode. However, when I run the application as a service:

sudo service application start

It outputs this data in the log when I output my environment variables:

{ UPSTART_INSTANCE: '',
  UPSTART_JOB: 'application',
  TERM: 'linux',
  PATH: '/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin',
  PWD: '/home/richie/application' }

As you can see, NODE_ENV does not exist in the list of environment variables. Any idea why my exported environment variable would be ignored? I also have added into my /etc/environment file:

NODE_ENV=production

Thanks in advance!

share|improve this question
    
Looks like I should have used env NODE_ENV=production instead of export NODE_ENV=production –  richie Mar 28 at 18:09

1 Answer 1

up vote 0 down vote accepted

"You're doing it wrong". In an upstart job, variables aren't set with export, but with env. So change your declaration to

env NODE_ENV=production

Things should work then.

Do note that upstart jobs are not shell scripts. They follow a declarative syntax. They can contain shell scripts but these have to be enclosed in script..end script (also, see similar syntax for pre-start and post-start scripts).

http://upstart.ubuntu.com/getting-started.html

share|improve this answer

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.