add local server and reboot functionality
This commit is contained in:
parent
bd9cd4f0e9
commit
593bcd6ed0
3 changed files with 129 additions and 4 deletions
83
bin/ssu
Executable file
83
bin/ssu
Executable file
|
|
@ -0,0 +1,83 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
'use strict'
|
||||
|
||||
var wreck = require('wreck')
|
||||
var argv = process.argv.slice(2)
|
||||
|
||||
var cmd = argv[0]
|
||||
var fingerprint = argv[1]
|
||||
|
||||
if (!cmd || !fingerprint) {
|
||||
console.log('Command line utility for lamassu-server')
|
||||
console.log('\nUsage: ssu reboot <machine-fingerprint>')
|
||||
console.log('This will remotely reboot your lamassu-machine.')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
var opts = {json: true}
|
||||
wreck.get('http://localhost:7070/pid?fingerprint=' + fingerprint, opts, function (err, res, payload) {
|
||||
if (err) {
|
||||
console.log('Please make sure that lamassu-server is running on this box.')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
if (!payload.pid) {
|
||||
console.log('The requested lamassu-machine is not connected.')
|
||||
process.exit(3)
|
||||
}
|
||||
|
||||
var pid = payload.pid
|
||||
|
||||
if (Date.now() - payload.ts > 10000) {
|
||||
console.log('lamassu-machine is not connected to server.')
|
||||
process.exit(6)
|
||||
}
|
||||
|
||||
var opts2 = {
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
payload: JSON.stringify({pid: pid, fingerprint: fingerprint})
|
||||
}
|
||||
|
||||
wreck.post('http://localhost:7070/reboot', opts2, function (err2, res) {
|
||||
if (err2) {
|
||||
console.log('Please make sure that lamassu-server is running on this box.')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
if (res.statusCode !== 200) {
|
||||
console.log('Communication error')
|
||||
return
|
||||
}
|
||||
|
||||
console.log('Rebooting...')
|
||||
|
||||
var ts = null
|
||||
|
||||
setTimeout(function () {
|
||||
if (Date.now() - ts < 10000) {
|
||||
console.log('lamassu-machine did not reboot but is still contacting server.')
|
||||
process.exit(4)
|
||||
}
|
||||
|
||||
console.log('lamassu-machine rebooted but is not coming back up.')
|
||||
process.exit(5)
|
||||
}, 30000)
|
||||
|
||||
setInterval(function () {
|
||||
wreck.get('http://localhost:7070/pid?fingerprint=' + fingerprint, opts, function (err3, res, payload) {
|
||||
if (err3) {
|
||||
console.log('lamassu-server appears to be down.')
|
||||
process.exit(2)
|
||||
}
|
||||
|
||||
ts = payload.ts
|
||||
|
||||
if (payload.pid !== pid) {
|
||||
console.log('lamassu-machine is back up!')
|
||||
process.exit(0)
|
||||
}
|
||||
})
|
||||
}, 5000)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue