nodemon cannot run in background with nohup? #296

Closed
leoliaolei opened this Issue Feb 14, 2014 · 32 comments

Comments

I use nohup nodemon server.js &. It seems nodemon is killed soon.

Owner

remy commented Feb 18, 2014

Is killed, as in, dies? Or does it linger, then restart? I could do with a bit more information. Perhaps some help debugging?

I run nodemon, everything is fine as below.

    [root@vm dms]# nodemon server/server.js
    19 Feb 02:53:23 - [nodemon] v1.0.14
    19 Feb 02:53:23 - [nodemon] to restart at any time, enter `rs`
    19 Feb 02:53:23 - [nodemon] watching: *.*
    19 Feb 02:53:23 - [nodemon] starting `node server/server.js`

But nohup not work.

    [root@vm dms]#
    [root@vm dms]# nohup nodemon server/server.js &
    [1] 19973
    [root@vm dms]# nohup: ignoring input and appending output to `nohup.out'
    [1]+  Exit 1                  nohup nodemon server/server.js

Here is the log of nohup.out

    [root@vm dms]# cat nohup.out
    -----------------------------------------
    Update available: 1.0.15 (current: 1.0.14)
    Run npm update -g nodemon to update
    -----------------------------------------
    19 Feb 02:53:53 - [nodemon] v1.0.14
    19 Feb 02:53:53 - [nodemon] to restart at any time, enter `rs`
    19 Feb 02:53:53 - [nodemon] watching: *.*
    19 Feb 02:53:53 - [nodemon] starting `node server/server.js`
    exception in nodemon killing node
    Error: EBADF, read

    If appropriate, please file an error:
    http://github.com/remy/nodemon/issues/new

On Wed, Feb 19, 2014 at 4:48 AM, Remy Sharp notifications@github.comwrote:

Is killed, as in, dies? Or does it linger, then restart? I could do with a
bit more information. Perhaps some help debugging?


Reply to this email directly or view it on GitHubhttps://github.com/remy/nodemon/issues/296#issuecomment-35431654
.

I'm also facing the same issue. I tried to run nodemon in verbose mode but it didn't help much. Here's what happens when I try to run nodemon with nohup :

work:/workspace/discovery-logging > nohup nodemon --verbose serve.js &
[1] 22313
work:
/workspace/discovery-logging > nohup: ignoring input and appending output to `nohup.out'

[1] + exit 1 nohup nodemon --verbose serve.js

work:/workspace/discovery-logging >
work:
/workspace/discovery-logging > cat nohup.out
5 Mar 04:27:30 - [nodemon] v1.0.15
5 Mar 04:27:30 - [nodemon] to restart at any time, enter rs
5 Mar 04:27:30 - [nodemon] ignoring: /home/user/workspace/discovery-logging/.git//* node_modules//node_modules
5 Mar 04:27:30 - [nodemon] watching: .
5 Mar 04:27:30 - [nodemon] watching extensions: js
5 Mar 04:27:30 - [nodemon] starting node serve.js
5 Mar 04:27:30 - [nodemon] child pid: 22319
exception in nodemon killing node
Error: EBADF, read

If appropriate, please file an error: http://github.com/remy/nodemon/issues/new

5 Mar 04:27:30 - [nodemon] exiting

Owner

remy commented Apr 24, 2014

Can someone run the exact same command, but add --dump and then post the output here?

-----------------------------------------
Update available: 1.0.17 (current: 1.0.15)
Run npm update -g nodemon to update
-----------------------------------------
25 Apr 13:41:14 - [nodemon] v1.0.15
25 Apr 13:41:14 - [nodemon] to restart at any time, enter `rs`
25 Apr 13:41:14 - [nodemon] ignoring: /home/aamir/workspace/saiku-ui/.git/**/* node_modules/**/node_modules
25 Apr 13:41:14 - [nodemon] watching: *.*
25 Apr 13:41:14 - [nodemon] watching extensions: js
--------------

{ run: false,
  system: 
   { cwd: '/home/aamir/workspace/saiku-ui',
     useFind: false,
     useWatch: true,
     useWatchFile: false },
  required: false,
  dirs: [ '/home/aamir/workspace/saiku-ui' ],
  timeout: 1000,
  options: 
   { scriptPosition: 1,
     dump: true,
     verbose: true,
     script: 'serve.js',
     args: [],
     ignore: 
      [ '.git',
        'node_modules/**/node_modules',
        re: /\.git|node_modules/.*.*/node_modules/ ],
     watch: [ '*.*', re: /.*\..*/ ],
     restartable: 'rs',
     execMap: { py: 'python', rb: 'ruby' },
     stdin: true,
     stdout: true,
     execOptions: 
      { script: 'serve.js',
        exec: 'node',
        nodeArgs: undefined,
        ext: 'js',
        env: {},
        execArgs: [] },
     ext: 'js',
     monitor: 
      [ '*.*',
        '!/home/aamir/workspace/saiku-ui/.git/**/*',
        '!node_modules/**/node_modules' ] },
  load: [Function],
  reset: [Function: reset],
  lastStarted: 0,
  loaded: [],
  command: 
   { raw: { executable: 'node', args: [ 'serve.js' ] },
     string: 'node serve.js' } }

--------------
OS: linux ia32
node: v0.10.26
nodemon: v1.0.15
cwd: /home/aamir/workspace/saiku-ui
command: node /usr/bin/nodemon --dump --verbose serve.js
--------------
25 Apr 13:41:14 - [nodemon] exiting
-bash-4.1# nohup nodemon --dump server/server.js &
[1] 30753
-bash-4.1# nohup: ignoring input and appending output to `nohup.out'

[1]+  Done                    nohup nodemon --dump server/server.js

-bash-4.1# cat nohup.out

-----------------------------------------
Update available: 1.0.17 (current: 1.0.14)
Run npm update -g nodemon to update
-----------------------------------------
25 Apr 18:47:03 - [nodemon] v1.0.14
25 Apr 18:47:03 - [nodemon] to restart at any time, enter `rs`
25 Apr 18:47:03 - [nodemon] watching: *.*
--------------
{ run: false,
  system: 
   { cwd: '/www/app/dms',
     useFind: false,
     useWatch: true,
     useWatchFile: false },
  required: false,
  dirs: [ '/www/app/dms' ],
  timeout: 1000,
  options: 
   { scriptPosition: 1,
     dump: true,
     script: 'server/server.js',
     args: [ 'server/server.js' ],
     ignore: 
      [ '.git',
        'node_modules/**/node_modules',
        re: /\.git|node_modules/.*.*/node_modules/ ],
     watch: [ '*.*', re: /.*\..*/ ],
     restartable: 'rs',
     execMap: { py: 'python', rb: 'ruby' },
     stdin: true,
     verbose: false,
     stdout: true,
     execOptions: 
      { script: 'server/server.js',
        exec: 'node',
        nodeArgs: undefined,
        ext: 'js',
        env: {},
        execArgs: [] },
     ext: 'js',
     monitor: [ '*.*', '!.git', '!node_modules/**/node_modules' ] },
  load: [Function],
  reset: [Function: reset],
  lastStarted: 0,
  loaded: [],
  command: 
   { raw: 
      { executable: 'node',
        args: [ 'server/server.js', 'server/server.js' ] },
     string: 'node server/server.js server/server.js' } }
--------------
OS: linux ia32
node: v0.10.25
nodemon: v1.0.14
cwd: /www/app/dms
command: node /usr/local/bin/nodemon --dump server/server.js
--------------

sparkit commented May 6, 2014

I had same issue. Here is my work around
Created a shell script exec.sh

cd source
nodemon app.js

Then execute the script with nohup

nohup exec.sh
Owner

remy commented May 6, 2014

Cheers for the tip. I've not had a chance to play with this yet (am on
paternity leave), but I'll take a look too. I suspect there's some kind of
signalling going weird here.

On Tuesday, May 6, 2014, Sriraman notifications@github.com wrote:

I had same issue. Here is my work around
Created a shell script exec.sh

cd source
nodemon app.js

Then execute the script with nohup

nohup exec.sh


Reply to this email directly or view it on GitHubhttps://github.com/remy/nodemon/issues/296#issuecomment-42283303
.

— Remy

@remy remy added help wanted and removed needs more info labels May 10, 2014

beetaa commented Jun 27, 2014

@sparkit noop, the ways produce the same error...

beetaa commented Jun 27, 2014

this may be help: nohup nodemon app.js </dev/null &

details: #98

nvcken commented Jul 8, 2014

I have same problem, how can make it work, please help

sparkit commented Jul 8, 2014

@nvcken
Did you tried the solution I posted ?

nvcken commented Jul 8, 2014

I has try nohup nodemon </dev/null &
But not work, I got log

8 Jul 15:00:57 - �[33m[nodemon] v1.2.0�[39m
8 Jul 15:00:57 - �[33m[nodemon] to restart at any time, enter rs�[39m
8 Jul 15:00:57 - �[33m[nodemon] watching: _._�[39m
8 Jul 15:00:57 - �[32m[nodemon] starting node ./bin/www�[39m
events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at exports._errnoException (util.js:742:11)
at Server._listen2 (net.js:1126:14)
at listen (net.js:1148:10)
at Server.listen (net.js:1223:5)
at Server.listen (/var/www/appota_inside/node_modules/livereload/lib/livereload.js:69:28)
at Object.exports.createServer (/var/www/appota_inside/node_modules/livereload/lib/livereload.js:201:12)
at Object. (/var/www/appota_inside/app.js:28:21)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:349:32)
8 Jul 15:00:58 - �[31m[nodemon] app crashed - waiting for file changes before starting...�[39m

nvcken commented Jul 8, 2014

@sparkit
I has try as your guide. But not work
I got this log

8 Jul 15:06:49 - �[33m[nodemon] v1.2.0�[39m
8 Jul 15:06:49 - �[33m[nodemon] to restart at any time, enter rs�[39m
8 Jul 15:06:49 - �[33m[nodemon] watching: _._�[39m
8 Jul 15:06:49 - �[32m[nodemon] starting node ./bin/www�[39m
exception in nodemon killing node
Error: EBADF, read
at Error (native)


If appropriate, please file an error with the output from:
$ node /usr/local/bin/nodemon --dump

At http://github.com/remy/nodemon/issues/new

nvcken commented Jul 8, 2014

@sparkit
I use nohup ./exec.sh, because nohup exec.sh not work, because it show "nohup: cannot run command `exec.sh': No such file or directory"

sparkit commented Jul 8, 2014

Have added permission +x for exec.sh ?
try giving full path nohup

nvcken commented Jul 8, 2014

I has added +x permission for exec.sh.
Could you please explain how give full path nohup, thanks

sparkit commented Jul 8, 2014

Will look something like
nohup /home/nvcken/myapp/exec.sh

On Tue, Jul 8, 2014 at 1:48 PM, nvcken notifications@github.com wrote:

I has added +x permission for exec.sh.
Could you explain how give full path nohup, thanks


Reply to this email directly or view it on GitHub
#296 (comment).

nvcken commented Jul 8, 2014

I get nohup nodemon work, now.
But It seem occur error when file js change, nodemon auto restart but

8 Jul 15:39:02 - �[32m[nodemon] restarting due to changes...�[39m
8 Jul 15:39:03 - �[32m[nodemon] starting node ./bin/www�[39m
8 Jul 15:39:03 - �[32m[nodemon] starting node ./bin/www�[39m
events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE

I lookup grep node, has a node process with listening port 35729 running.
If I kill it, nodemon start ok.
What happen ?

sparkit commented Jul 8, 2014

Could you please paste here

a) nohup command you are running
b) Your exec.sh

Thanks

On Tue, Jul 8, 2014 at 2:15 PM, nvcken notifications@github.com wrote:

I got nohup nodemon work, now.
But It seem occur error when file js change, nodemon auto restart but

8 Jul 15:39:02 - [32m[nodemon] restarting due to changes...[39m
8 Jul 15:39:03 - [32m[nodemon] starting node ./bin/www[39m
8 Jul 15:39:03 - [32m[nodemon] starting node ./bin/www[39m

events.js:85
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE

I lookup grep node, has a node process with listen port 35729 running.
If I kill it, nodemon start ok.
What happen ?


Reply to this email directly or view it on GitHub
#296 (comment).

nvcken commented Jul 8, 2014

I use only command below
nohup nodemon </dev/null &

Thanks

I added an issue to nodejs, because I was having the same issue when binding to stdin. It might be related this issue, too.

joyent/node#8410

@remy I bet if you remove these lines, it will work without issues using nohup :)

https://github.com/remy/nodemon/blob/master/lib/nodemon.js#L106

nswish commented Jul 8, 2015

nohup nodemon app.js </dev/null &
works for me!
thanks!

nohup nodemon app.js </dev/null &
works for me too!
Thank you very much ;-)

MahdiPishguy commented Jul 25, 2016

i can put it to background, but after close ssh connection, nodemon stopped, because after connecet to ssh again i dont have any package on background

Last login: Mon Jul 25 10:01:35 2016 from 46.224.238.119 hello@ubuntu:~$ fg -bash: fg: current: no such job

Another possible solution:

nohup nodemon -I app.js

The -I switch prevents nodemon from attempting to use STDIN, which isn't allowed under nohup as there's no input stream.

FND added a commit to complate/complate-sample-express that referenced this issue Aug 3, 2017

barraponto commented Oct 12, 2017

@Fistynuts interesting -- but I don't see the -I option when I run nodemon --help. Doc issue?
Never mind, my eyes deceived me.

@barraponto please use tmux terminal emulator and run nodejs application inside that

stale bot commented Dec 12, 2017

This issue has been automatically marked as idle and stale because it hasn't had any recent activity. It will be automtically closed if no further activity occurs. If you think this is wrong, or the problem still persists, just pop a reply in the comments and @remy will (try!) to follow up.
Thank you for contributing <3

@stale stale bot added the wontfix label Dec 12, 2017

@leoliaolei you can use nodemon with tmux

@stale stale bot removed the wontfix label Dec 12, 2017

@remy Feel free to close this issue, the -I switch fixes it.

Owner

remy commented Dec 12, 2017

I've got an faq item to merge, so I'll add this to the FAQ too.

👍

@remy remy closed this Dec 12, 2017

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