OSC / nginx_stage

[MOVED] Stages & controls the per-user NGINX environment
https://github.com/OSC/ondemand/tree/master/nginx_stage
MIT License
0 stars 1 forks source link

If you drop in a Ruby app and it fails to load, and then you switch to a Node app, it will node load unless tmp/restart is touched OR NGINX is restarted #16

Closed ericfranz closed 7 years ago

ericfranz commented 7 years ago

Not sure if this belongs in this repo or another.

Steps to reproduce:

  1. Build a simple rack app using an account that does not have a rack gem in their home directory and no Gemfile. Create in ~/ondemand/dev/ps a config.ru file with these contents:
# a minimal rack app that displays your running processes on the OOD web host
run Proc.new { |env|
  content = "<h2>Process list generated at: #{Time.now}</h2>"
  content += "<pre>" + `ps ufx` + "</pre>"

  ['200', {'Content-Type' => 'text/html'}, [content]]
}
  1. Accessing the app in your development sandbox should produce a startup error. https://webdev05.osc.edu/pun/dev/ps

  2. Remove all the files in the ps directory. Replace it with a valid node.js app by adding an app.js file with these contents:

// a minimal node app that displays your running processes on the OOD web host
var http = require('http');
var exec = require('child_process').exec;

var server = http.createServer(function (request, response){
    exec('ps ufx', function(error, stdout, stderr){
        response.writeHead(200, {"Content-Type": "text/html"});
        response.write("<h2>" + new Date() + "</h2>");
        response.write("<pre>" + stdout + "</pre>\n");
        response.end();
    });
});
server.listen(3000);
  1. Access the app again. You will still see the rack error even though an app.js app is in its place. This should continue until your PUN is stopped and then you access the URL again.

  2. In the ps directory, mkdir tmp and touch tmp/restart.txt

  3. Access https://webdev05.hpc.osc.edu/pun/dev/ps again. Now it loads properly.

ericfranz commented 7 years ago

Interesting.

  1. Access https://webdev05.hpc.osc.edu/nginx/stop to stop your nginx

  2. In a shell on webdev05 ps fux returns:

    USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    efranz    23908  0.0  0.0 116124  1940 ?        S    14:53   0:00 sshd: efranz@pts/0
    efranz    23909  0.0  0.0 109728  4960 pts/0    Ss   14:53   0:00  \_ -bash
    efranz    28726  0.0  0.0 108328   976 pts/0    R+   15:53   0:00      \_ ps fux
  3. Add the broken ruby app and access https://webdev05.hpc.osc.edu/pun/dev/ps and see the error. Now do a ps:

    USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    efranz    28780  0.0  0.0  91160  2812 ?        S    15:53   0:00 nginx: worker process
    efranz    28762  0.0  0.0 711692  3952 ?        Sl   15:53   0:00 PassengerHelperAgent
    efranz    23908  0.0  0.0 116124  1940 ?        S    14:53   0:00 sshd: efranz@pts/0
    efranz    23909  0.0  0.0 109728  4960 pts/0    Ss   14:53   0:00  \_ -bash
    efranz    28799  0.0  0.0 108320   976 pts/0    R+   15:53   0:00      \_ ps fux
  4. Now remove the config.ru and add the app.js. Access the URL and see the same rack error. Run ps again:

    USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    efranz    28780  0.0  0.0  91160  2848 ?        S    15:53   0:00 nginx: worker process
    efranz    28762  0.0  0.0 711692  4108 ?        Sl   15:53   0:00 PassengerHelperAgent
    efranz    23908  0.0  0.0 116124  1940 ?        S    14:53   0:00 sshd: efranz@pts/0
    efranz    23909  0.0  0.0 109728  4960 pts/0    Ss   14:53   0:00  \_ -bash
    efranz    28839  0.0  0.0 108320   972 pts/0    R+   15:54   0:00      \_ ps fux
  5. Now explicitly kill the PassengerHelperAgent. Then access the app again. Now it works, loading the node app.

    USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    efranz    28780  0.0  0.0  91160  2848 ?        S    15:53   0:00 nginx: worker process
    efranz    28845  0.0  0.0 514236  4960 ?        Sl   15:54   0:00 PassengerHelperAgent
    efranz    23908  0.0  0.0 116124  1940 ?        S    14:53   0:00 sshd: efranz@pts/0
    efranz    23909  0.0  0.0 109728  4964 pts/0    Ss   14:53   0:00  \_ -bash
    efranz    28856  0.0  0.0 108324   980 pts/0    R+   15:54   0:00      \_ ps fux
ericfranz commented 7 years ago

Notice that PassengerHelperAgent restarted automatically after killing it.

nickjer commented 7 years ago

It seems the PassengerHelperAgent (the process that launches the child app processes) caches a given app's passenger_app_type after its first launch (from then on it will try to launch the app with the corresponding executable: ruby, node, python).

The only way to non-destructively update the passenger_app_type that I can tell is by telling it to restart that individual app with the tmp/restart.txt file. Otherwise you need to either kill the PassengerHelperAgent or restart your PUN.