1

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!

1
  • Looks like I should have used env NODE_ENV=production instead of export NODE_ENV=production
    – richie
    Mar 28, 2014 at 18:09

1 Answer 1

2

"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

You must log in to answer this question.

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