1 // This file is written in D programming language
2 /**
3 *   Copyright: © 2014 Anton Gushcha
4 *   License: Subject to the terms of the MIT license, as written in the included LICENSE file.
5 *   Authors: NCrashed <ncrashed@gmail.com>
6 */
7 module test02;
8 
9 import std.file;
10 
11 import daemonize.d;
12 
13 version(Server)
14 {
15     alias daemon = Daemon!(
16         "Test2",
17 
18         KeyValueList!(
19             Composition!(Signal.Terminate, Signal.Quit, Signal.Shutdown, Signal.Stop), (shared IDaemonLogger logger, Signal signal)
20             {
21                 write("output.txt", "Test string 1");
22                 return false;
23             },
24             Signal.HangUp, (logger)
25             {
26                 write("output.txt", "Test string 2");
27                 return false;
28             }),
29 
30         (logger, shouldExit) {
31             while(!shouldExit()) {}
32             return 0;
33         }
34     );
35 
36     int main()
37     {
38         return buildDaemon!daemon.run(new shared DloggLogger("logfile.log"));
39     }
40 }
41 else
42 {
43     alias daemon = DaemonClient!(
44         "Test2",
45         Composition!(Signal.Terminate, Signal.Quit, Signal.Shutdown, Signal.Stop),
46         Signal.HangUp
47     );
48 
49     int main()
50     {
51         alias client = buildDaemon!daemon;
52 
53         Signal sig;
54         version(Test1) sig = Signal.Terminate;
55         version(Test2) sig = Signal.Quit;
56         version(Test3) sig = Signal.Shutdown;
57         version(Test4) sig = Signal.Stop;
58         version(Test5) sig = Signal.HangUp;
59 
60         client.sendSignal(new shared DloggLogger("logfile.log"), sig);
61         return 0;
62     }
63 }