Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7061753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:30:44+00:00 2026-05-28T04:30:44+00:00

I have an Upstart script for my server that looks like this: description myapp

  • 0

I have an Upstart script for my server that looks like this:

description "myapp node.js server"

start on runlevel [2345]
stop on shutdown

env NODE_ENV=production
env CUSTOM=somevalue
exec sudo -u nodejs /usr/local/bin/node /opt/myapp/app.js >> /var/log/nodejs/myapp.log 2>&1

post-start script
    NODE_PID=`status myapp | egrep -oi '([0-9]+)$' | head -n1` 
    echo $NODE_PID > /var/run/nodejs/myapp.pid
end script

However, the app doesn’t see NODE_ENV set to production. In fact, if I console.log(process.env) within the app, I don’t see NODE_ENV or CUSTOM. Any ideas what’s happening?

By the way, NODE_ENV=production node app.js works just fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:30:45+00:00Added an answer on May 28, 2026 at 4:30 am

    From the sudo man page (Ubuntu version of sudo)

    There are two distinct ways to deal with environment variables. By default, the env_reset sudoers
    option is enabled. This causes commands to be executed with a minimal environment containing TERM,
    PATH, HOME, SHELL, LOGNAME, USER and USERNAME in addition to variables from the invoking process
    permitted by the env_check and env_keep sudoers options. There is effectively a whitelist for
    environment variables.

    Sudo is resetting the environment. This is a frustrating aspect of using su and sudo in upstart or init scripts. Recent versions of upstart support specifying uid/gid without the use of sudo via the setuid/setgid directives as in the example below. Also note the use of chdir.

    start on filesystem and started networking
    respawn
    chdir /var/www/yourapp
    setuid yourapp
    setgid yourapp
    env NODE_ENV=production
    env PATH=/usr/local/bin:/usr/bin:/bin
    env CUSTOM=somevalue
    exec /usr/local/bin/node app.js | /usr/bin/multilog s1024000 /var/log/yourapp 2>&1
    

    For older versions of upstart, here’s what I used to do to work around it.

    description "start and stop the example.com node.js server"
    
    start on filesystem and started networking
    respawn
    
    chdir /path/to/your/code
    exec su -c 'PATH=$PWD/node/bin NODE_ENV=$(cat node_env.txt) ./node/bin/node app/server.js' www-data  >> tmp/stdout.log 2>&1
    

    Note that I just put a node_env.txt file in my app root that sets production mode, because I hate environment variables. You can just do NODE_ENV=production right there if you prefer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an upstart script in order to daemonize juggernaut (a node.js app)
I have written a logging application in Python that is meant to start at
I have posted this to ServerFault, but the Node.js community seems tiny there, so
I'm using upstart v1.4 to start my application server, it's called unicorn . The
I'm configuring my server to run node.js as a daemon. I've setup Upstart to
Have some dates in my local Oracle 11g database that are in this format:
hope you can help me. I have html markup like this: <a href=error.htm class=button
I have an Ubuntu Oneiric server that runs several instances of ffmpeg (each one
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.