-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
155 additions
and
28 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
;(function(){ | ||
var cluster = require('cluster'); | ||
if(cluster.isMaster){ | ||
return cluster.fork() && cluster.on('exit', function(){ cluster.fork(); require('../lib/crashed'); }); | ||
return cluster.fork() && cluster.on('exit',function(){ cluster.fork(); require('../lib/crashed') }); | ||
} | ||
|
||
var fs = require('fs'); | ||
var config = { | ||
port: process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765, | ||
peers: process.env.PEERS && process.env.PEERS.split(',') || [] | ||
var fs = require('fs'), env = process.env; | ||
var GUN = require('../'); // require('gun'); | ||
var opt = { | ||
port: env.PORT || process.argv[2] || 8765, | ||
peers: env.PEERS && env.PEERS.split(',') || [] | ||
}; | ||
var Gun = require('../'); // require('gun') | ||
|
||
if(process.env.HTTPS_KEY){ | ||
config.key = fs.readFileSync(process.env.HTTPS_KEY); | ||
config.cert = fs.readFileSync(process.env.HTTPS_CERT); | ||
config.server = require('https').createServer(config, Gun.serve(__dirname)); | ||
if(fs.existsSync((opt.home = require('os').homedir())+'/cert.pem')){ | ||
env.HTTPS_KEY = env.HTTPS_KEY || opt.home+'/key.pem'; | ||
env.HTTPS_CERT = env.HTTPS_CERT || opt.home+'/cert.pem'; | ||
} | ||
if(env.HTTPS_KEY){ | ||
opt.port = 443; | ||
opt.key = fs.readFileSync(env.HTTPS_KEY); | ||
opt.cert = fs.readFileSync(env.HTTPS_CERT); | ||
opt.server = require('https').createServer(opt, GUN.serve(__dirname)); | ||
require('http').createServer(function(req, res){ | ||
res.writeHead(301, {"Location": "https://"+req.headers['host']+req.url }); | ||
res.end(); | ||
}).listen(80); | ||
} else { | ||
config.server = require('http').createServer(Gun.serve(__dirname)); | ||
opt.server = require('http').createServer(GUN.serve(__dirname)); | ||
} | ||
|
||
var gun = Gun({web: config.server.listen(config.port), peers: config.peers}); | ||
|
||
console.log('Relay peer started on port ' + config.port + ' with /gun'); | ||
|
||
var gun = GUN({web: opt.server.listen(opt.port), peers: opt.peers}); | ||
console.log('Relay peer started on port ' + opt.port + ' with /gun'); | ||
module.exports = gun; | ||
}()); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/bin/bash | ||
cd ~ | ||
git clone https://github.com/acmesh-official/acme.sh.git | ||
cd ~/acme.sh | ||
./acme.sh --install -m $EMAIL | ||
|
||
bash ~/acme.sh/acme.sh --issue -d $DOMAIN -w $WEB | ||
bash ~/acme.sh/acme.sh --install-cert -d $DOMAIN --key-file ~/key.pem --fullchain-file ~/cert.pem --reloadcmd "service relay force-reload" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[Unit] | ||
Description=GUN relay | ||
Documentation=https://gun.eco | ||
After=network.target | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
|
||
[Service] | ||
Environment=PATH=/usr/bin:/usr/local/bin | ||
LimitNOFILE=infinity | ||
LimitNPROC=infinity | ||
LimitCORE=infinity | ||
StartLimitBurst=999999 | ||
StartLimitIntervalSec=999999 | ||
Restart=always | ||
ExecStart=node examples/http.js 80 | ||
# Environment=NODE_ENV=production | ||
WorkingDirectory= |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module.exports = function(root){ | ||
var mesh = root.opt.mesh, cmd = {}, run = require('child_process').exec, fs = require('fs'), home = require('os').homedir(), examp = require('path').resolve(__dirname, '../examples'); | ||
mesh.hear['service'] = function(msg, peer){ | ||
if(!fs.existsSync('/lib/systemd/system/relay.service')){ | ||
mesh.say({dam: '!', err: "Not serviced."}); | ||
return; | ||
} | ||
try{ (cmd[msg.try]||cmd.any)(msg, peer); }catch(err){ mesh.say({dam: '!', err: "service error: "+err}) } | ||
} | ||
cmd.https = function(msg, peer){ var log; | ||
if(!msg.email || !msg.domain){ | ||
mesh.say({dam: '!', err: 'Domain/email missing, use `location.hostname`!'}); | ||
return; | ||
} | ||
if(fs.existsSync(home+'/cert.pem')){ | ||
mesh.say({dam: '!', err: 'Cert already exists.'}); | ||
return; | ||
} | ||
fs.writeFile(examp+'/../email', msg.email, function(){}); | ||
run("bash "+examp+"/https.sh", {env: {'EMAIL': msg.email, 'WEB': examp, 'DOMAIN': msg.domain}}, function(e, out, err){ | ||
log = "|"+e+"|"+out+"|"+err; | ||
mesh.say({dam: '!', log: ''+log}, peer); | ||
setTimeout(function(){ process.exit() },999); | ||
}); | ||
} | ||
cmd.update = function(msg, peer){ var log, pass; | ||
try{ pass = (''+fs.readFileSync(home+'/pass')).trim() }catch(e){} | ||
if(!pass || (msg.pass||'').trim() != pass){ return } | ||
root.stats.stay.updated = +new Date; | ||
run("bash "+examp+"/install.sh", {env: {VERSION: msg.version||''}}, function(e, out, err){ | ||
log = e+"|"+out+"|"+err; | ||
mesh.say({dam: '!', log: ''+log}, peer); | ||
setTimeout(function(){ process.exit() },999); | ||
}); | ||
} | ||
;(function update(){ var last; | ||
if(!fs.existsSync(home+'/cert.pem')){ return } | ||
setTimeout(update, 1000*60*60*24); | ||
last = root.stats.stay.updated || 0; | ||
if(+new Date - last < 1000*60*60*24*15){ return } | ||
root.stats.stay.updated = +new Date; | ||
run("bash "+examp+"/install.sh", {}, function(){}); | ||
}()); | ||
|
||
cmd.any = function(){}; | ||
|
||
}; |