Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This is on Ubuntu 10.04 LTS

So I've got a gulp script (running through Node) that works great when I execute it manually. It actually runs a "watch" on a directory so that if any of the files change it automatically runs a command. The initial issue I had was if I save a change that has a bug in it, the "watch" crashes.

I thought I could fix this by executing the gulp script through upstart and respawn it if it crashes. But when I run "start gulpwatch" or even "sudo start gulpwatch" it says it starts and gives me a pid but it actually just starts and crashes and doesn't maintain the "watch". This is confirmed in the syslog where I see the lines:

Mar 24 14:19:19 ubuntu init: gulpwatch main process (2653) terminated with status 2
2072 Mar 24 14:19:19 ubuntu init: gulpwatch main process ended, respawning
2073 Mar 24 14:19:19 ubuntu init: gulpwatch main process (2654) terminated with status 2
2074 Mar 24 14:19:19 ubuntu init: gulpwatch main process ended, respawning
2075 Mar 24 14:19:19 ubuntu init: gulpwatch main process (2655) terminated with status 2
2076 Mar 24 14:19:19 ubuntu init: gulpwatch main process ended, respawning
2077 Mar 24 14:19:19 ubuntu init: gulpwatch main process (2656) terminated with status 2
2078 Mar 24 14:19:19 ubuntu init: gulpwatch main process ended, respawning
2079 Mar 24 14:19:19 ubuntu init: gulpwatch main process (2657) terminated with status 2
2080 Mar 24 14:19:19 ubuntu init: gulpwatch main process ended, respawning
2081 Mar 24 14:19:19 ubuntu init: gulpwatch main process (2658) terminated with status 2

Here is my upstart file

/etc/init/gulpwatch.conf
   start on runlevel [2345]
    stop on runlevel [016]
    respawn
    respawn limit 5 10

    exec "cd /opt/lib/vendor/node/;/usr/bin/gulp --gulpfile gulpfile.js"

When I run the two commands listed above "cd /opt/lib/vendor/node/" and "/usr/bin/gulp --gulpfile gulpfile.js" it works perfectly (but of course won't respan if it crashes due to a syntax error in the watch file).

Any idea why my upstart script isn't working??

share|improve this question
    
Is that a stray ' after the gulpfile.js? –  Nattgew Mar 24 at 21:43
    
Yeah it was but that wasn't in my actual code, still not working –  asolberg Mar 24 at 22:12
    
According to the answer here, your exec needs to be inside a script/end script stanza. –  Nattgew Mar 24 at 22:19
    
So I played with it some more, I changed out my gulp command for a simple echo "hello" >> /var/log/test.log command. It does NOT work when I call the command directly with exec but if I put the command in a shell script like /tmp/test.sh and then call exec /tmp/test.sh it DOES work. So if I don't want to make a separate file to run my command is that possible with exec? –  asolberg Mar 24 at 22:42
    
BTW - the script tag didn't seem to have any effect either way –  asolberg Mar 24 at 22:42

1 Answer 1

I figured it out. I needed to run chdir /opt/lib/vendor/node/ and then take that part out of the exec statement. Apparantly exec doesn't run any old shell commands, it only executes scripts (and arguments)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.