Opened 12 years ago

Closed 3 years ago

#381 closed enhancement (fixed)

Sage daemon mode

Reported by: was Owned by: mabshoff
Priority: minor Milestone: sage-duplicate/invalid/wontfix
Component: user interface Keywords: Sage server background process service
Cc: Merged in:
Authors: Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

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

Change History (19)

comment:1 Changed 12 years ago by was


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.

comment:2 Changed 12 years ago by mabshoff

  • Milestone set to sage-2.8.2
  • Owner changed from was to mabshoff
  • Status changed from new to assigned

comment:3 Changed 12 years ago by mabshoff

  • Milestone changed from sage-2.8.2 to sage-2.9

comment:4 Changed 9 years ago by klee

  • Report Upstream set to N/A

Look at #7893 (http://trac.sagemath.org/sage_trac/ticket/7893).

It would be good to incorporate the idea of the example to the script in the previous ticket.

Last edited 7 years ago by leif (previous) (diff)

comment:5 Changed 7 years ago by leif

Ping.

The Sage Installation Guide currently lacks this topic. (There's only a reference from the online FAQ to this ticket.)

comment:6 Changed 7 years ago by leif

  • Keywords Sage server background process service added
  • Summary changed from SAGE daemon mode to Sage daemon mode

comment:7 Changed 6 years ago by jdemeyer

What's wrong with nohup? It does exactly what you want, why add a Sage option to emulate nohup?

comment:8 follow-up: Changed 6 years ago by was

I think nohup doesn't daemonize. There is a long list of things that should happen when a process is damonized:

http://en.wikipedia.org/wiki/Daemon_(computing)

The right way to solve this problem would almost certainly involve including this Python module: https://pypi.python.org/pypi/python-daemon/

comment:9 in reply to: ↑ 8 ; follow-up: Changed 6 years ago by jdemeyer

Replying to was:

I think nohup doesn't daemonize.

True, nohup itself doesn't daemonize. But normally you would do

$ nohup sage -n &

It's the & at the end which does the "daemonization".

There is a long list of things that should happen when a process is damonized:

http://en.wikipedia.org/wiki/Daemon_(computing)

This refers to traditional Unix daemons, which would be quite different from a Sage "daemon" started by an ordinary user.

So it's not clear to me what would be needed for a Sage daemon which is not covered by

$ nohup sage &

comment:10 follow-up: Changed 6 years ago by was

This refers to traditional Unix daemons, which would be quite different from a Sage "daemon" started by an ordinary user.

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.

comment:11 in reply to: ↑ 10 Changed 6 years ago by jdemeyer

Replying to was:

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.

Which is #7893, this ticket seems to be about single-user use.

comment:12 in reply to: ↑ 9 Changed 6 years ago by leif

Replying to jdemeyer:

Replying to was:

I think nohup doesn't daemonize.

True, nohup itself doesn't daemonize. But normally you would do

$ nohup sage -n &

It's the & at the end which does the "daemonization".

There is a long list of things that should happen when a process is damonized:

http://en.wikipedia.org/wiki/Daemon_(computing)

This refers to traditional Unix daemons, which would be quite different from a Sage "daemon" started by an ordinary user.

So it's not clear to me what would be needed for a Sage daemon which is not covered by

$ nohup sage &

Well, you'd at least also have to >/dev/null.

Inherited file descriptors other than 0, 1 and 2 are left untouched.

nohup doesn't change the working directory, nor e.g. modify the umask.

The background process doesn't get adopted by init until you logout, and similar process group specific stuff I think.

(...)

comment:13 Changed 6 years ago by jdemeyer

  • Milestone changed from sage-5.11 to sage-5.12

comment:14 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.1 to sage-6.2

comment:15 Changed 6 years ago by vbraun_spam

  • Milestone changed from sage-6.2 to sage-6.3

comment:16 Changed 5 years ago by vbraun_spam

  • Milestone changed from sage-6.3 to sage-6.4

comment:17 Changed 4 years ago by klee

  • Milestone changed from sage-6.4 to sage-duplicate/invalid/wontfix
  • Status changed from new to needs_review

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.

comment:18 Changed 4 years ago by chapoton

  • Reviewers set to Frédéric Chapoton
  • Status changed from needs_review to positive_review

comment:19 Changed 3 years ago by vbraun

  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.