Question

I'm using node.js for my webserver, and I would like forever (or something like it) to run the server.

I'm also using git to manage the website. I have a bare repository on the server that I can push to/pull from on my local machine. I would like the repository to do three things when I push to it.

  1. CD to my working directory (on the server)
  2. Have the working directory pull from the bare repo
  3. Restart the running webserver.

The following script seems like it's what I should use as a post-receive hook in my bare repo.

cd ~/site
git pull
sudo forever stopall
sudo forever start main.js

However, I don't think it's smart to have the git hook use sudo like that. The script needs elevated to run on port 80.

How should I be doing this? What should my git post-receive look like?

Thanks!

Was it helpful?

Solution

Well, for my particular case, it turns out I shouldn't be running node as a super user for security reasons. I wanted it to be elevated to run on port 80, but it didn't need to be elevated to run on port 8000.

So I forwarded port 80 to port 8000, and now am running node on port 8000. It still works identically to how it did before.

The command that I used in particular to forward port 80 to 8000 is

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top