Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

-

  • Loading branch information...
commit 44990c0654ccd6249c47f1c0b8a4ae567c78e4ca 1 parent d679607
authored February 28, 2012
7  cfg.json-example
... ...
@@ -1,10 +1,9 @@
1 1
 {
2 2
 	"logLevel": 2,
3 3
 	"port": 80,
4  
-	"host": "1.2.3.100",
  4
+	"host": "127.0.0.1",
5 5
 	"forks":{
6  
-		"foo.sleepless.com":		{ "host":"1.2.3.4",		"port":2900 },
7  
-		"sleepless.com":			{ "host":"1.2.3.100",	"port":8080 },
8  
-		"default":					{ "host":"1.2.3.100",	"port":8080 }
  6
+		"localhost":			{ "host":"sleepless.com",	"port":8080 },
  7
+		"default":				{ "host":"sleepless.com",	"port":80 }
9 8
 	}
10 9
 }
12  forker.js
@@ -24,7 +24,7 @@ var net = require("net")
24 24
 var http = require("http")
25 25
 var fs = require("fs")
26 26
 var util = require("util"), insp = util.inspect
27  
-var log5 = require("log5"), log = log5.mkLog("fork:")
  27
+var log5 = require("log5"), log = log5.mkLog("forker:")
28 28
 
29 29
 var j2o = function(j) { try { return JSON.parse(j) } catch(e) { return null } }
30 30
 var o2j = function(o) { return JSON.stringify(o) }
@@ -45,6 +45,7 @@ var cfg = defaultConfig = {
45 45
 	}
46 46
 }
47 47
 
  48
+var root = process.getuid() == 0;
48 49
 var seq = 0
49 50
 
50 51
 function pi10(s) {
@@ -124,15 +125,18 @@ var start = function(e, s) {
124 125
 	server = http.createServer()
125 126
 
126 127
 	server.on("error", function(e) {
127  
-		log(1, "ERROR "+e.stack)
  128
+		if(!root && cfg.port < 1024)
  129
+			log(1, "Configured to listen on port "+cfg.port+" but user not root")
  130
+		else 
  131
+			log(1, "ERROR "+e.stack)
128 132
 	})
129 133
 
130 134
 	server.on("request", request)
131 135
 
132  
-	log(2, ""+cfg.host+":"+cfg.port)
  136
+	log(2, cfg.host+":"+cfg.port)
133 137
 	server.listen(cfg.port, cfg.host, function() {
134 138
 
135  
-		if(process.getuid() == 0) {
  139
+		if(root) {
136 140
 			try {
137 141
 				process.setgid('nobody')
138 142
 				process.setuid('nobody')
2  package.json
... ...
@@ -1,6 +1,6 @@
1 1
 {
2 2
 	"name": "forker",
3  
-	"version": "2.0.1",
  3
+	"version": "2.0.2",
4 4
 	"description": "A forking HTTP proxy (you heard me)",
5 5
 	"author": "Joe Hitchens <joe@sleepless.com>",
6 6
 	"homepage": "https://github.com/sleeplessinc/forker",
2  start
... ...
@@ -1,11 +1,11 @@
1 1
 #!/bin/bash
2 2
 
3 3
 
  4
+touch "PID"
4 5
 pid=`cat PID`
5 6
 if [ -d "/proc/$pid" ] ; then
6 7
 	echo "Already running" 
7 8
 else
8  
-	ulimit -n 100000
9 9
 	node > log.txt forker.js &
10 10
 fi
11 11
 

0 notes on commit 44990c0

Please sign in to comment.
Something went wrong with that request. Please try again.