0

I am cloning my repo and running my nodejs application using puppet. please find the code below:

package { 'git':
  ensure => 'latest',
}

vcsrepo { "/nodejs-helloworld":
  ensure   => latest,
  provider => git,
  require  => [ Package["git"] ],
  source   => "git@gitlab.abc.dev.net:hello-world/nodejs-helloworld.git",
  revision => 'master',
  before   => Exec['/usr/local/bin/npm install;/usr/local/bin/npm start'],
}

exec { '/usr/local/bin/npm install;/usr/local/bin/npm start':
  cwd         => '/nodejs-helloworld',
  subscribe   => Vcsrepo['/nodejs-helloworld'],
  refreshonly => true,
}

My repository is cloned, my application is running fine, and npm test also works. Everything works fine. However, I get an exec command time out error.

Error log:

[root@ip-*******/]# puppet agent -t
Info: Retrieving pluginfacts
Info: Retrieving plugin
Info: Loading facts
Info: Caching catalog for ip-**************
Info: Applying configuration version '1474433486'
Notice: /Stage[main]/Main/Exec[install-node-version-manager-global]/returns: executed successfully
Notice: /Stage[main]/Main/Exec[install-node-version-manager-latest]/returns: executed successfully
Notice: /Stage[main]/Main/Vcsrepo[/nodejs-helloworld]/ensure: Creating repository from latest
Notice: /Stage[main]/Main/Vcsrepo[/nodejs-helloworld]/ensure: created
Info: /Stage[main]/Main/Vcsrepo[/nodejs-helloworld]: Scheduling refresh of Exec[/usr/local/bin/npm install;/usr/local/bin/npm start]
Error: /Stage[main]/Main/Exec[/usr/local/bin/npm install;/usr/local/bin/npm start]: Failed to call refresh: Command exceeded timeout
Error: /Stage[main]/Main/Exec[/usr/local/bin/npm install;/usr/local/bin/npm start]: Command exceeded timeout
Notice: Finished catalog run in 302.86 seconds

As you can see here, even though I get an exec command timeout error, my app is running and npm test works.

 [root@ip-********* nodejs-helloworld]# netstat -anp 2> /dev/null | grep :3000
    tcp6       0      0 :::3000                 :::*                    LISTEN      17630/node
 [root@ip-********* nodejs-helloworld]# npm test

    > nodejs-helloworld@1.0.0 test /nodejs-helloworld
    > mocha



      Test HelloWorld
        ✓ Should have the root route (46ms)
        ✓ Should have a hello world response


      2 passing (66ms)

Can anyone please tell me how to avoid the exec command timeout error?

Matthew Schuchard
  • 25,172
  • 3
  • 47
  • 67
nad87563
  • 3,672
  • 7
  • 32
  • 54
  • You should really add a `logoutput` to the `exec` resource to see what is going on that may cause a timeout and then report back. – Matthew Schuchard Sep 21 '16 at 23:20
  • exec { '/usr/local/bin/npm install;/usr/local/bin/npm start': command => '/usr/local/bin/npm install;/usr/local/bin/npm start', cwd => '/nodejs-helloworld', logoutput => true, subscribe => Vcsrepo['/nodejs-helloworld'], refreshonly => true, } – nad87563 Sep 21 '16 at 23:47
  • getting the same error connection time out as mentioned in error log. – nad87563 Sep 21 '16 at 23:49
  • [root@ip-******** nodejs-helloworld]# npm start > nodejs-helloworld@1.0.0 start /nodejs-helloworld > node index.js HelloWorld running on 3000 ^Z [1]+ Stopped npm start But i dont wana stop it. so i usually open another terminal and do 'npm test' I guess when i do the same using puppet it keeps waiting after doing 'npm start'. – nad87563 Sep 22 '16 at 00:06
  • So nothing is being output to stdout or stderr during that exec? – Matthew Schuchard Sep 22 '16 at 01:22
  • No what i mentioned in question same error "Error: /Stage[main]/Main/Exec[/usr/local/bin/npm install;/usr/local/bin/npm start]: Failed to call refresh: Command exceeded timeout Error: /Stage[main]/Main/Exec[/usr/local/bin/npm install;/usr/local/bin/npm start]: Command exceeded timeout" – nad87563 Sep 22 '16 at 03:34
  • Does the `npm start` command properly background itself when run from the console? – Felix Frank Sep 25 '16 at 22:44

1 Answers1

0

If I'm not wrong what seems to be the problem is that, when you run npm start, it runs your application but it doesn't exit, and you don't want that because you want to keep your application running, however puppet expects it to exit at some point.

What you should do instead is to make the exec resource start your application in the background. You can have a look at this question where the answers describe various tools to easily achieve this.

Farid Nouri Neshat
  • 29,438
  • 6
  • 74
  • 115