Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to update & restart a Node app with Mercurial following a push? (Equivalent of git post-receive in hg)

How to update & restart a Node app with Mercurial following a push? (Equivalent of git post-receive in hg)

Problem

I've worked with Git to accomplish this before, but require Mercurial for another project. My Git recipe included a post-receive hook that looked like the following:

#!/bin/sh
GIT_WORK_TREE=/home/ec2-user/www
export GIT_WORK_TREE
git checkout -f

Which would refresh my working app directory every time I pushed to the remote repo on my server. I'd then run my app with Node-supervisor: supervisor server.js, which would watch for file changes and restart Node following a git push / file change.

My question is what's the best way to accomplish this with Mercurial. I've looked into the changegroup hook as a similar alternative, but I can't find any example hooks. Thanks!


Update: My Implementation

Per answer & comment below, I went with the changegroup hook. Specifically, in myrepo/.hg/hgrc I used:

[hooks]
changegroup = hg update && /path/to/restart/script.sh

I went with a basic shell script to restart Node vs. installing node-supervisor per above, for this project. It looks like this:

#!/bin/sh
echo "Restarting Server" >> /logpath/server.log
sudo pkill -x node
sudo node server.js >> /logpath/server.log &
echo "Changegroup Hook Executed, Server Restarted"
exit 0

I have only one Node process running, so pkill (all) works for me. I'm also running the server.js straight out of my repo directory.

Problem courtesy of: Wes Johnson

Solution

Try the Hooks part of the Red Bean book. Especially scrolling down to the Hooks Reference portion may be of use, e.g.:

changegroup—after remote changesets added

Solution courtesy of: Amber

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How to update & restart a Node app with Mercurial following a push? (Equivalent of git post-receive in hg)

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×