Sage: Ticket #381: Sage daemon mode
https://trac.sagemath.org/ticket/381
<pre class="wiki">On May 28, 5:11 pm, Marshall Hampton <hampto...@gmail.com> wrote:
> This is more of a unixy process control question but I am applying it
> to sage.
>
> I would like to start a notebook on my office machine while I am at a
> conference. I tried logging in with ssh, starting the notebook,
> suspending it with ctrl-z, and then putting the suspended process in
> the background with bg. This didn't really work, although I could
> still restart the notebook server with a browser. I could figure this
> out eventually but I am hoping someone reading this list already knows
> how to do this.
There are several options:
1) use screen - see www.gnu.org/software/screen/
2) use nohup - see man nohup
3) use disown - see http://www.faqs.org/docs/bashman/bashref_79.html
All have their specific advantages, I would just go with screen.
It might be worthwhile to offer an option for SAGE to demonize itself.
Cheers,
Michael Abshoff
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/381
Trac 1.1.6wasMon, 28 May 2007 22:43:58 GMT
https://trac.sagemath.org/ticket/381#comment:1
https://trac.sagemath.org/ticket/381#comment:1
<pre class="wiki">
Well, the idea is to detach the running SAGE instance from the shell
to let it run in the background until it is killed or the system is
rebooted.
There is more than one way to do it: For a good C example see
http://www.enderunix.org/docs/eng/daemon.php - for a python example
see http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012
The python example could be more or less copied (I guess because I am
not a python expert), but it should be done very early in the SAGE
startup as far as I can tell. Writing a little C wrapper that just
does
i=fork();
if (i<0) exit(1); /* fork error */
if (i>0) exit(0); /* parent exits */
/* child (daemon) continues */
execv("./sage");
might be easier.
</pre>
TicketmabshoffThu, 23 Aug 2007 11:20:35 GMTstatus, owner changed; milestone set
https://trac.sagemath.org/ticket/381#comment:2
https://trac.sagemath.org/ticket/381#comment:2
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>assigned</em>
</li>
<li><strong>owner</strong>
changed from <em>was</em> to <em>mabshoff</em>
</li>
<li><strong>milestone</strong>
set to <em>sage-2.8.2</em>
</li>
</ul>
TicketmabshoffThu, 23 Aug 2007 11:20:50 GMTmilestone changed
https://trac.sagemath.org/ticket/381#comment:3
https://trac.sagemath.org/ticket/381#comment:3
<ul>
<li><strong>milestone</strong>
changed from <em>sage-2.8.2</em> to <em>sage-2.9</em>
</li>
</ul>
TicketkleeSun, 17 Oct 2010 04:39:32 GMTupstream set
https://trac.sagemath.org/ticket/381#comment:4
https://trac.sagemath.org/ticket/381#comment:4
<ul>
<li><strong>upstream</strong>
set to <em>N/A</em>
</li>
</ul>
<p>
Look at <a class="closed ticket" href="https://trac.sagemath.org/ticket/7893" title="task: Sage server launching script (closed: fixed)">#7893</a> (<a class="ext-link" href="http://trac.sagemath.org/sage_trac/ticket/7893"><span class="icon"></span>http://trac.sagemath.org/sage_trac/ticket/7893</a>).
</p>
<p>
It would be good to incorporate the idea of the example to the script in the previous ticket.
</p>
TicketleifSun, 02 Dec 2012 16:06:16 GMT
https://trac.sagemath.org/ticket/381#comment:5
https://trac.sagemath.org/ticket/381#comment:5
<p>
Ping.
</p>
<p>
The Sage Installation Guide currently lacks this topic. (There's only a reference from the <a class="ext-link" href="http://wiki.sagemath.org/faq#Other_questions"><span class="icon"></span>online FAQ</a> to <em>this</em> ticket.)
</p>
TicketleifSun, 02 Dec 2012 16:10:36 GMTsummary changed; keywords set
https://trac.sagemath.org/ticket/381#comment:6
https://trac.sagemath.org/ticket/381#comment:6
<ul>
<li><strong>keywords</strong>
<em>Sage</em> <em>server</em> <em>background</em> <em>process</em> <em>service</em> added
</li>
<li><strong>summary</strong>
changed from <em>SAGE daemon mode</em> to <em>Sage daemon mode</em>
</li>
</ul>
TicketjdemeyerThu, 13 Jun 2013 12:23:41 GMT
https://trac.sagemath.org/ticket/381#comment:7
https://trac.sagemath.org/ticket/381#comment:7
<p>
What's wrong with nohup? It does exactly what you want, why add a Sage option to emulate nohup?
</p>
TicketwasThu, 13 Jun 2013 16:49:35 GMT
https://trac.sagemath.org/ticket/381#comment:8
https://trac.sagemath.org/ticket/381#comment:8
<p>
I think nohup doesn't daemonize. There is a long list of things that should happen when a process is damonized:
</p>
<blockquote>
<p>
<a class="ext-link" href="http://en.wikipedia.org/wiki/Daemon_(computing"><span class="icon"></span>http://en.wikipedia.org/wiki/Daemon_(computing</a>)
</p>
</blockquote>
<p>
The right way to solve this problem would almost certainly involve including this Python module: <a class="ext-link" href="https://pypi.python.org/pypi/python-daemon/"><span class="icon"></span>https://pypi.python.org/pypi/python-daemon/</a>
</p>
TicketjdemeyerThu, 13 Jun 2013 18:16:40 GMT
https://trac.sagemath.org/ticket/381#comment:9
https://trac.sagemath.org/ticket/381#comment:9
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/381#comment:8" title="Comment 8">was</a>:
</p>
<blockquote class="citation">
<p>
I think nohup doesn't daemonize.
</p>
</blockquote>
<p>
True, <code>nohup</code> itself doesn't daemonize. But normally you would do
</p>
<pre class="wiki">$ nohup sage -n &
</pre><p>
It's the <code>&</code> at the end which does the "daemonization".
</p>
<blockquote class="citation">
<p>
There is a long list of things that should happen when a process is damonized:
</p>
<blockquote>
<p>
<a class="ext-link" href="http://en.wikipedia.org/wiki/Daemon_(computing"><span class="icon"></span>http://en.wikipedia.org/wiki/Daemon_(computing</a>)
</p>
</blockquote>
</blockquote>
<p>
This refers to traditional Unix daemons, which would be quite different from a Sage "daemon" started by an ordinary user.
</p>
<p>
So it's not clear to me what would be needed for a Sage daemon which is not covered by
</p>
<pre class="wiki">$ nohup sage &
</pre>
TicketwasThu, 13 Jun 2013 18:25:14 GMT
https://trac.sagemath.org/ticket/381#comment:10
https://trac.sagemath.org/ticket/381#comment:10
<blockquote class="citation">
<p>
This refers to traditional Unix daemons, which would be quite different from a Sage "daemon" started by an ordinary user.
</p>
</blockquote>
<p>
I think traditional daemonization is the right way to solve this problem. Moreover, it would be a useful step for making it easy to run a sage server as part of the usual system-wide daemons on Unix.
</p>
TicketjdemeyerThu, 13 Jun 2013 18:30:26 GMT
https://trac.sagemath.org/ticket/381#comment:11
https://trac.sagemath.org/ticket/381#comment:11
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/381#comment:10" title="Comment 10">was</a>:
</p>
<blockquote class="citation">
<p>
it would be a useful step for making it easy to run a sage server as part of the usual system-wide daemons on Unix.
</p>
</blockquote>
<p>
Which is <a class="closed ticket" href="https://trac.sagemath.org/ticket/7893" title="task: Sage server launching script (closed: fixed)">#7893</a>, this ticket seems to be about single-user use.
</p>
TicketleifThu, 13 Jun 2013 18:51:27 GMT
https://trac.sagemath.org/ticket/381#comment:12
https://trac.sagemath.org/ticket/381#comment:12
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/381#comment:9" title="Comment 9">jdemeyer</a>:
</p>
<blockquote class="citation">
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/381#comment:8" title="Comment 8">was</a>:
</p>
<blockquote class="citation">
<p>
I think nohup doesn't daemonize.
</p>
</blockquote>
<p>
True, <code>nohup</code> itself doesn't daemonize. But normally you would do
</p>
<pre class="wiki">$ nohup sage -n &
</pre><p>
It's the <code>&</code> at the end which does the "daemonization".
</p>
<blockquote class="citation">
<p>
There is a long list of things that should happen when a process is damonized:
</p>
<blockquote>
<p>
<a class="ext-link" href="http://en.wikipedia.org/wiki/Daemon_(computing"><span class="icon"></span>http://en.wikipedia.org/wiki/Daemon_(computing</a>)
</p>
</blockquote>
</blockquote>
<p>
This refers to traditional Unix daemons, which would be quite different from a Sage "daemon" started by an ordinary user.
</p>
<p>
So it's not clear to me what would be needed for a Sage daemon which is not covered by
</p>
<pre class="wiki">$ nohup sage &
</pre></blockquote>
<p>
Well, you'd at least also have to <code>>/dev/null</code>.
</p>
<p>
Inherited file descriptors other than 0, 1 and 2 are left untouched.
</p>
<p>
<code>nohup</code> doesn't change the working directory, nor e.g. modify the umask.
</p>
<p>
The background process doesn't get adopted by <code>init</code> until you logout, and similar process group specific stuff I think.
</p>
<p>
(...)
</p>
TicketjdemeyerTue, 13 Aug 2013 15:35:53 GMTmilestone changed
https://trac.sagemath.org/ticket/381#comment:13
https://trac.sagemath.org/ticket/381#comment:13
<ul>
<li><strong>milestone</strong>
changed from <em>sage-5.11</em> to <em>sage-5.12</em>
</li>
</ul>
Ticketvbraun_spamThu, 30 Jan 2014 21:20:52 GMTmilestone changed
https://trac.sagemath.org/ticket/381#comment:14
https://trac.sagemath.org/ticket/381#comment:14
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.1</em> to <em>sage-6.2</em>
</li>
</ul>
Ticketvbraun_spamTue, 06 May 2014 15:20:58 GMTmilestone changed
https://trac.sagemath.org/ticket/381#comment:15
https://trac.sagemath.org/ticket/381#comment:15
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.2</em> to <em>sage-6.3</em>
</li>
</ul>
Ticketvbraun_spamSun, 10 Aug 2014 16:51:03 GMTmilestone changed
https://trac.sagemath.org/ticket/381#comment:16
https://trac.sagemath.org/ticket/381#comment:16
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.3</em> to <em>sage-6.4</em>
</li>
</ul>
TicketkleeWed, 23 Mar 2016 04:38:48 GMTstatus, milestone changed
https://trac.sagemath.org/ticket/381#comment:17
https://trac.sagemath.org/ticket/381#comment:17
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
<li><strong>milestone</strong>
changed from <em>sage-6.4</em> to <em>sage-duplicate/invalid/wontfix</em>
</li>
</ul>
<p>
The problem that this ticket deals with is nowadays solved by using the OS tools such as Upstart in Ubuntu for example. So I think there needs no further discussion on this matter.
</p>
TicketchapotonSat, 16 Apr 2016 18:35:46 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/381#comment:18
https://trac.sagemath.org/ticket/381#comment:18
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>reviewer</strong>
set to <em>Frédéric Chapoton</em>
</li>
</ul>
TicketvbraunSun, 12 Jun 2016 12:02:30 GMTstatus changed; resolution set
https://trac.sagemath.org/ticket/381#comment:19
https://trac.sagemath.org/ticket/381#comment:19
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
</ul>
Ticket