<div class="gmail_quote">On Mon, Mar 7, 2011 at 12:39 AM, Bas van Dijk <span dir="ltr">&lt;<a href="mailto:v.dijk.bas@gmail.com">v.dijk.bas@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Sterling, Gregory, Brandon and David thanks for your suggestions.<br>
<div class="im"><br>
On 6 March 2011 05:38, David Anderson &lt;<a href="mailto:dave@natulte.net">dave@natulte.net</a>&gt; wrote:<br>
&gt; I humbly recommend doing such daemonizations from outside your program.<br>
&gt; Programs that daemonize on startup make it very difficult to monitor them by<br>
&gt; direct means, instead forcing you to rely on PID files and other mechanisms<br>
&gt; which may not always be available or fresh.<br>
<br>
</div>Agreed, I already noticed that debugging is a bit harder since I have<br>
no stdout and stderr anymore.<br>
<div class="im"><br>
&gt; For reference, Upstart, the new PID 1 on Ubuntu and friends, has a horrible<br>
&gt; hack[1] built in specifically to keep track of processes that &quot;helpfully&quot;<br>
&gt; daemonize themselves, so that it can offer additional services like<br>
&gt; restarting crashed services or notifying the owner of a problem.<br>
&gt; As has been pointed out elsewhere on thread, there are plenty of standalone<br>
&gt; programs that implement daemonization if you end up not using service<br>
&gt; management software to do it for you.<br>
<br>
</div>I plan to run the daemon on a Ubuntu server. Do you know if Upstart is<br>
able to daemonize a process?<br></blockquote><div><br></div><div>It&#39;s perfectly simple. In fact, it&#39;s the default assumption of Upstart that your program doesn&#39;t daemonize, and that Upstart should help it. You have to specify if your program violates that assumption.</div>
<div><br></div><div>Here&#39;s a sample file. It specifies a service that; should run whenever the main runlevels are entered (i.e. basic system init like mounting filesystems is done, but no other guarantee); stops when the system leaves those runlevels; runs a binary that does not fork or daemonize; respawns the service if the process should die for any reason; can be manually stopped and restarted by the admin if he feels like it.</div>
<div><br></div><div>$ cat /etc/init/demo.conf</div><div>description &quot;Demo service that doesn&#39;t daemonize by itself&quot;</div><div>start on runlevel [2345]</div><div>stop on runlevel [!2345]</div><div>respawn</div>
<div>exec /path/to/binary</div><div>$ sudo start demo</div><div>demo start/running, process 27469</div><div>$ sudo stop demo</div><div>demo stop/waiting</div><div>$ sudo status demo</div><div>demo stop/waiting </div><div>
$</div><div><br></div><div>Hope this helps. The upstart configuration format is a little sparsely documented, when I wrote scripts for it, I used the existing files in /etc/init as a rough guide.</div><div><br></div><div>
- Dave</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<br>
Regards,<br>
<font color="#888888"><br>
Bas<br>
</font></blockquote></div><br>