Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve environment when restarting #116

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

Preserve environment when restarting #116

simenbrekken opened this issue Sep 18, 2011 · 7 comments

Comments

@simenbrekken
Copy link

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
Copy link
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
Copy link
Author

I corrected the obvious(?) typo.

@indexzero
Copy link
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
Copy link
Member

Published in npm as forever@0.7.1

@Californian
Copy link

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
Copy link

👍 to @Californian

Or simply allow refreshing env vars on forever restart

@maaaikoool
Copy link

+1 to @Californian

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

No branches or pull requests

5 participants