Created
June 15, 2012 19:02
-
-
Save mitchallen/2938195 to your computer and use it in GitHub Desktop.
Example git post-receive hook - assumes you have a node.js app setup as a service that can be stopped and started. See the comments for usage.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "Stopping service" | |
sudo stop myapp | |
echo "Deploying to test ..." | |
_TREE=/export/home/MY-USER/test | |
GIT_WORK_TREE=$_TREE git checkout -f | |
cd $_TREE | |
pwd | |
echo "Installing dependencies" | |
npm install | |
ls -la $_TREE | |
echo "Starting service" | |
sudo start myapp | |
echo "Deployment finished." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
These instructions are for RHEL6
On your server edit /etc/sudoers and make sure this line is commented out (precede with a '#') - else you'll get an error from the sudo commands in the gist:
To setup the repo on your server do the following:
Use your favorite Linux text editor to create a file with the contents of this gist (change the value of $_TREE to suit your preferred deployment location):
Setup the folder to deploy to after a git push to the server (assumes full path maps to $_TREE in gist):
On your original source client git project add your server / repo as a remote (substituting USER and SERVER):
Dependencies:
If you don't plan to include a package.json file in the root of your project with dependencies or plan to push your local node_modules folder to the server, remove these two lines:
You may have to push your node_modules folder to the server if a firewall prevents npm from being able to contact the remote registry from the server.
References: