configure monitrc to monitor node js app process, can't find node app pidfile running with screen ec2 linux

StackOverflow https://stackoverflow.com/questions/13201570

質問

I run my app.js (node js application) via screen on my ec2 linux instance. I'm trying to config my monitrc file and I need the app pidfile. It's not in : /var/run (and there isn't a /var/www)

Would really appreciate it if someone has any idea where the pidfile is or how can I find it out..
Thank you!

役に立ちましたか?

解決 2

seems like there isn't a pid file created so I used forever-monitor in order to restart my app.js script in case of an error. Looks like it is working. What you need to do is npm install forever and write server.js :

var forever = require('forever'),
    child = new(forever.Monitor)('app.js', {
        'silent': false,
        'pidFile': '/var/run/app.pid',
        'watch': false,
        'options': ['8383'],  // Additional arguments to pass to the script,
        'sourceDir': '.', // Directory that the source script is in
        'watchDirectory': '.',     // Top-level directory to watch from.
        'watchIgnoreDotFiles': true, // whether to ignore dot files
        'watchIgnorePatterns': [], // array of glob patterns to ignore, merged with contents of watchDirectory + '/.foreverignore' file
        'logFile': 'logs/forever.log', // Path to log output from forever process (when daemonized)
        'outFile': 'logs/forever.out', // Path to log output from child stdout
        'errFile': 'logs/forever.err'
    });
child.start();
forever.startServer(child);

and then run it with - node server.js (I run it from ~/nodejs directory) Still the pid file that supposed to be in /var/run isn't there, weird but I don't need monit anymore. I still don't understand why I should additionally use upstart (like all the posts related suggested) anyhow when I tried to run upstart it didn't work

他のヒント

in your app you can get the current pid number with process.pid so

var fs = require('fs');
fs.writeFile("/tmp/pidfile", process.pid);

and you get a pidfile in tmp

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top