-
Notifications
You must be signed in to change notification settings - Fork 0
/
daemons.htm
68 lines (56 loc) · 7.43 KB
/
daemons.htm
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf8" />
<title>How to install daemons?</title>
</head>
<body><a href="https://github.com/ArsenShnurkov/gentoo-mono-handbook"><img alt="Fork me on GitHub" id="forkme" src="images/forkme.png" align="right" width="100" /></a>
<table><tr><td valign="top">
<h1>How to install daemons?</h1>
</td><td valign="top">
<a href="index.htm">Gentoo Mono Handbook</a>
<br />
<a href="service.htm">services</a>
</td></tr></table>
<font style="color:red">we don't know</font>
<br />
<br />
<a href="http://stackoverflow.com/questions/186493/how-do-i-code-a-mono-daemon">http://stackoverflow.com/questions/186493/how-do-i-code-a-mono-daemon</a>
<br />
You should implement a service and use mono-service.
<br />
<br />
<br />
<a href="http://stackoverflow.com/questions/3660039/success-with-start-stop-daemon-and-mono-service2">http://stackoverflow.com/questions/3660039/success-with-start-stop-daemon-and-mono-service2</a>
<br />
We had a lot of issues with mono-service and ended up implementing our own "service" code in our app. Nothing hard, just grabbing some <a href="signals.htm">signals</a>:</p>
<pre style="" class="default prettyprint prettyprinted"><code><span class="typ">UnixSignal</span><span class="pln"> intr </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">UnixSignal</span><span class="pln"> </span><span class="pun">(</span><span class="typ">Signum</span><span class="pun">.</span><span class="pln">SIGINT</span><span class="pun">);</span><span class="pln">
</span><span class="typ">UnixSignal</span><span class="pln"> term </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">UnixSignal</span><span class="pln"> </span><span class="pun">(</span><span class="typ">Signum</span><span class="pun">.</span><span class="pln">SIGTERM</span><span class="pun">);</span><span class="pln">
</span><span class="typ">UnixSignal</span><span class="pln"> hup </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">UnixSignal</span><span class="pln"> </span><span class="pun">(</span><span class="typ">Signum</span><span class="pun">.</span><span class="pln">SIGHUP</span><span class="pun">);</span><span class="pln">
</span><span class="typ">UnixSignal</span><span class="pln"> usr2 </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">UnixSignal</span><span class="pln"> </span><span class="pun">(</span><span class="typ">Signum</span><span class="pun">.</span><span class="pln">SIGUSR2</span><span class="pun">);</span><span class="pln">
</span><span class="typ">UnixSignal</span><span class="pun">[]</span><span class="pln"> signals </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">new</span><span class="pln"> </span><span class="typ">UnixSignal</span><span class="pun">[]</span><span class="pln"> </span><span class="pun">{</span><span class="pln"> intr</span><span class="pun">,</span><span class="pln"> term</span><span class="pun">,</span><span class="pln"> hup</span><span class="pun">,</span><span class="pln"> usr2 </span><span class="pun">};</span><span class="pln">
</span><span class="kwd">for</span><span class="pln"> </span><span class="pun">(</span><span class="kwd">bool</span><span class="pln"> running </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">true</span><span class="pun">;</span><span class="pln"> running</span><span class="pun">;</span><span class="pln"> </span><span class="pun">)</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
</span><span class="kwd">int</span><span class="pln"> idx </span><span class="pun">=</span><span class="pln"> </span><span class="typ">UnixSignal</span><span class="pun">.</span><span class="typ">WaitAny</span><span class="pun">(</span><span class="pln">signals</span><span class="pun">);</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">idx </span><span class="pun"><</span><span class="pln"> </span><span class="lit">0</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> idx </span><span class="pun">>=</span><span class="pln"> signals</span><span class="pun">.</span><span class="typ">Length</span><span class="pun">)</span><span class="pln"> </span><span class="kwd">continue</span><span class="pun">;</span><span class="pln">
log</span><span class="pun">.</span><span class="typ">Debug</span><span class="pun">(</span><span class="str">"daemon: received signal "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> signals</span><span class="pun">[</span><span class="pln">idx</span><span class="pun">].</span><span class="typ">Signum</span><span class="pun">.</span><span class="typ">ToString</span><span class="pun">());</span><span class="pln">
</span><span class="kwd">if</span><span class="pln"> </span><span class="pun">((</span><span class="pln">intr</span><span class="pun">.</span><span class="typ">IsSet</span><span class="pln"> </span><span class="pun">||</span><span class="pln"> term</span><span class="pun">.</span><span class="typ">IsSet</span><span class="pun">))</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
intr</span><span class="pun">.</span><span class="typ">Reset</span><span class="pln"> </span><span class="pun">();</span><span class="pln">
term</span><span class="pun">.</span><span class="typ">Reset</span><span class="pln"> </span><span class="pun">();</span><span class="pln">
log</span><span class="pun">.</span><span class="typ">Debug</span><span class="pun">(</span><span class="str">"daemon: stopping..."</span><span class="pun">);</span><span class="pln">
running </span><span class="pun">=</span><span class="pln"> </span><span class="kwd">false</span><span class="pun">;</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">hup</span><span class="pun">.</span><span class="typ">IsSet</span><span class="pun">)</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
</span><span class="com">// Ignore. Could be used to reload configuration.</span><span class="pln">
hup</span><span class="pun">.</span><span class="typ">Reset</span><span class="pun">();</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="kwd">else</span><span class="pln"> </span><span class="kwd">if</span><span class="pln"> </span><span class="pun">(</span><span class="pln">usr2</span><span class="pun">.</span><span class="typ">IsSet</span><span class="pun">)</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
usr2</span><span class="pun">.</span><span class="typ">Reset</span><span class="pun">();</span><span class="pln">
</span><span class="com">// do something</span><span class="pln">
</span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span></code></pre>
</body>
</html>