-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
58 lines (50 loc) · 1.74 KB
/
Copy pathapp.js
File metadata and controls
58 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var express = require('express');
var os = require('os');
var networkInterfaces = os.networkInterfaces();
var ip = networkInterfaces['eth0'][0]['address']
var fs = require("fs");
var port = 8080;
var greeting = process.env.GREETING || 'Hello';
var who = process.env.WHO || 'World';
var healthy=true;
var app = express();
app.get('/hello', function (req, res) {
console.log('saying hello')
res.send(greeting + ' ' + who + ' from container ' + os.hostname() + ' with Ip address ' + ip);
});
app.get('/file', function(req, res) {
console.log('reading config file')
if (fs.existsSync('/tmp/hello/hello.conf')) {
var file = fs.readFileSync("/tmp/hello/hello.conf").toString();}
else {
var file = "--No config file--";}
res.send(file + " from Container " + os.hostname() + '\n');
});
app.get('/imageversion', function(req, res) {
console.log('getting base image version')
if (fs.existsSync('/etc/imageversion')) {
var imageversion = fs.readFileSync("/etc/imageversion").toString();}
else {
var imageversion = 'not set';}
res.send('Image version : ' + imageversion + '\n');
});
app.get('/healthz', function (req, res) {
if(healthy)
res.send('OK');
else
res.status(404).send('NOT OK');
});
app.get('/kill', function (req, res) {
console.log('setting unhealthy')
healthy=false;
res.send('Killed ' + os.hostname());
});
app.get('/', function(req, res) {
res.send('<a href="/imageversion">/imageversion</a> <br> <a href="/healthz">/healthz</a> <br> <a href="/hello">/hello</a> <br> <a href="/file">/file</a> <br> <a href="/kill">/kill</a>');
});
app.listen(port, ip);
console.log('Server running on http://%s:%s', ip, port);
process.on('SIGTERM', function () {
console.log('Cleanup.....');
process.exit();
});