Preserve environment when restarting #116

Closed
simenbrekken opened this Issue Sep 18, 2011 · 7 comments

Projects

None yet

5 participants

@simenbrekken

I've just encountered this in production where I'd first start a server with NODE_ENV=production forever start myapp.js and later attempt to restart it using forever restart myapp.js which would result in my restarted server being in development mode.

Perhaps it would be best if the environment each process was started with gets restored when restarting?

@indexzero
foreverjs member

@sbrekken How exactly are you starting your server? If you are running

  $ NODE_ENV=production node myapp.js

Then the process is not managed by forever.

@simenbrekken

I corrected the obvious(?) typo.

@indexzero indexzero closed this in 0d4f68e Oct 9, 2011
@indexzero
foreverjs member

Ahhh ... I see now. I fixed this:

$ NODE_ENV=production forever start examples/env-server.js 
info:   Running action: start
info:   Forever processing file: examples/env-server.js

$ curl http://localhost:8080/
{"NODE_ENV":"production","TERM_PROGRAM":"Apple_Terminal","TERM":"xterm-color","SHELL":"/bin/bash","TMPDIR":"/var/folders/fH/fHuTLtiHGgOZ9Cronn9zME+++TI/-Tmp-/","Apple_PubSub_Socket_Render":"/tmp/launch-bAspNE/Render","TERM_PROGRAM_VERSION":"273.1","OLDPWD":"/Users/Charlie/GitHub","USER":"Charlie","COMMAND_MODE":"unix2003","SSH_AUTH_SOCK":"/tmp/launch-AlvGeu/Listeners","__CF_USER_TEXT_ENCODING":"0x1F5:0:0","PATH":"/usr/src/ImageMagick-6.6.4/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin","PWD":"/Users/Charlie/GitHub/forever","LANG":"en_US.UTF-8","MAGICK_HOME":"/usr/src/ImageMagick-6.6.4","SHLVL":"1","HOME":"/Users/Charlie","DYLD_LIBRARY_PATH":"/usr/src/ImageMagick-6.6.4/lib","LOGNAME":"Charlie","PKG_CONFIG_PATH":"/Users/Charlie/GitHub/kod/deps/libcss/libparserutils/:/Users/Charlie/GitHub/kod/deps/libcss/libwapcaplet/:","DISPLAY":"/tmp/launch-eaFQnj/org.x:0","_":"/usr/local/bin/forever"}

$ forever restart 0
info:   Running action: restart
info:   Forever restarted process(es):
data:       uid  command script                 forever pid   logfile                          uptime       
data:   [0] 8f6x node    examples/env-server.js 24333   24334 /Users/Charlie/.forever/8f6x.log 0:0:0:19.334 

$ forever list
info:   Running action: list
info:   Forever processes running
data:       uid  command script                 forever pid   logfile                          uptime      
data:   [0] nBdW node    examples/env-server.js 24438   24439 /Users/Charlie/.forever/8f6x.log 0:0:0:1.707 

$ curl http://localhost:8080/
{"TERM_PROGRAM":"Apple_Terminal","SHELL":"/bin/bash","TERM":"xterm-color","TMPDIR":"/var/folders/fH/fHuTLtiHGgOZ9Cronn9zME+++TI/-Tmp-/","Apple_PubSub_Socket_Render":"/tmp/launch-bAspNE/Render","TERM_PROGRAM_VERSION":"273.1","USER":"Charlie","COMMAND_MODE":"unix2003","SSH_AUTH_SOCK":"/tmp/launch-AlvGeu/Listeners","__CF_USER_TEXT_ENCODING":"0x1F5:0:0","PATH":"/usr/src/ImageMagick-6.6.4/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin","_":"/usr/local/bin/forever","PWD":"/Users/Charlie/GitHub/forever","LANG":"en_US.UTF-8","NODE_ENV":"production","MAGICK_HOME":"/usr/src/ImageMagick-6.6.4","HOME":"/Users/Charlie","SHLVL":"2","DYLD_LIBRARY_PATH":"/usr/src/ImageMagick-6.6.4/lib","LOGNAME":"Charlie","PKG_CONFIG_PATH":"/Users/Charlie/GitHub/kod/deps/libcss/libparserutils/:/Users/Charlie/GitHub/kod/deps/libcss/libwapcaplet/:","DISPLAY":"/tmp/launch-eaFQnj/org.x:0"}

Environment variable is now still present

@indexzero
foreverjs member

Published in npm as forever@0.7.1

@Californian

Is there any way that this fix can be made compatible with reloading new versions of other environment variables? That is, if you pass in something (like NODE_ENV=production forever start server.js) the variable there (NODE_ENV) is preserved, but all other environment variables are reloaded?

@woozyking

👍 to @Californian

Or simply allow refreshing env vars on forever restart

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment