internal/assets/status.tmpl
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{{ template "header.tmpl" . }}
<div class="row">
<div class="col-md-12">
<table class="table">
<tr>
<th>Name</th>
<th>Started</th>
<th>Actions</th>
</tr>
<tr>
<td><a href="#{{ .Service.Name }}">{{ .Service.Name }}</a></td>
<td>{{ .Service.Started.Format "Mon Jan _2 15:04:05 MST 2006" }}</td>
<td style="display: flex; flex-wrap: wrap; gap: 1em">
{{ if .Service.Stopped }}
<form method="POST" action="/restart">
<input type="hidden" name="xsrftoken" value="{{ .XsrfToken }}">
<input type="hidden" name="path" value="{{ .Service.Name }}">
<input type="hidden" name="supervise" value="once">
<input type="submit" value="▶ run once">
</form>
<form method="POST" action="/restart">
<input type="hidden" name="xsrftoken" value="{{ .XsrfToken }}">
<input type="hidden" name="path" value="{{ .Service.Name }}">
<input type="hidden" name="supervise" value="loop">
<input type="submit" value="🔁 supervise (run in a loop)">
</form>
{{ else }}
<form method="POST" action="/stop">
<input type="hidden" name="xsrftoken" value="{{ .XsrfToken }}">
<input type="hidden" name="path" value="{{ .Service.Name }}">
<input type="submit" value="❌ stop">
</form>
{{ end }}
</td>
</tr>
</table>
{{ if (ne .Service.Diverted "") }}
<p>
Diverted: <code>{{ .Service.Diverted }}</code>
</p>
{{ end }}
<h3>stdout <small><a href="/log?path={{ .Service.Name }}&stream=stdout">raw log</a></small></h3>
<pre id="stdout"></pre>
<h3>stderr <small><a href="/log?path={{ .Service.Name }}&stream=stderr">raw log</a></small></h3>
<pre id="stderr"></pre>
<h3>module info</h3>
<pre>{{ .Service.ModuleInfo }}</pre>
</div>
</div>
{{ template "footer.tmpl" . }}
<script>
function newLogrotate(elt) {
const maxLines = 101;
var lines = 0;
return function (e) {
const line = e.data;
const txt = elt.innerText + line + "\n";
lines += line.split("\n").length;
var toRemove = lines - maxLines;
var i = 0;
while (toRemove-- > 0) {
i = txt.indexOf("\n", i) + 1;
lines--;
}
elt.innerText = txt.slice(i);
};
}
var stderr = new EventSource("/log?path={{ .Service.Name }}&stream=stderr", {
withCredentials: true,
})
stderr.onmessage = newLogrotate(document.getElementById("stderr"));
var stdout = new EventSource("/log?path={{ .Service.Name }}&stream=stdout", {
withCredentials: true,
})
stdout.onmessage = newLogrotate(document.getElementById("stdout"));
window.onbeforeunload = function() {
stderr.close();
stdout.close();
};
</script>