-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinuxStats.dpr
68 lines (62 loc) · 1.8 KB
/
LinuxStats.dpr
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
program LinuxStats;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Linux.Utils in 'Linux.Utils.pas',
Posix.Daemon in 'Posix.Daemon.pas',
Posix.Syslog in 'Posix.Syslog.pas',
Stats.Config in 'Stats.Config.pas',
Stats.Types in 'Stats.Types.pas',
Stats.SystemInfo in 'Stats.SystemInfo.pas',
Linux.ServerModule in 'Linux.ServerModule.pas' {ServerModule: TDataModule},
Stats.Disk in 'Stats.Disk.pas',
Stats.Memory in 'Stats.Memory.pas',
Stats.OS in 'Stats.OS.pas',
Stats.CPU in 'Stats.CPU.pas';
var
Server : TServerModule;
begin
try
FormatSettings.DecimalSeparator := ',';
FormatSettings.ThousandSeparator := '.';
FormatSettings.DateSeparator := '/';
FormatSettings.ShortDateFormat := 'd/M/yyyy';
FormatSettings.ShortTimeFormat := 'hh:nn:ss';
Server := TServerModule.Create(nil);
try
if FindCmdLineSwitch('DAEMON',['-'],true) then
begin
TPosixDaemon.Setup(procedure(ASignal: TPosixSignal)
begin
case ASignal of
TPosixSignal.Termination:
begin
//Forçar o Stop quando receber o sinal de finalização para liberar a porta usada pelo HTTP
Server.Stop;
end;
TPosixSignal.Reload:
begin
//-1 para forçar a pegar a porta do json de configuração
Server.ConfigurePort(-1);
end;
end;
end);
Server.ConfigurePort(-1);
Server.Start;
end else begin
Server.ConfigurePort;
while true do
begin
sleep(1000);
end;
end;
TPosixDaemon.Run(1000);
finally
Server.Free;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.