Opened 13 years ago

Closed 6 years ago

#7893 closed task (fixed)

Sage server launching script

Reported by: Kwankyu Lee Owned by: Kwankyu Lee
Priority: trivial Milestone: sage-duplicate/invalid/wontfix
Component: packages: experimental Keywords: service daemon mode background
Cc: Merged in:
Authors: Kwankyu Lee Reviewers: Frédéric Chapoton
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description (last modified by Kwankyu Lee)

Many users seem to write individually scripts starting and stopping a Sage server. It would be good that there is a place where these efforts can be combined.

Attachments (3)

sage-notebook-server (1.0 KB) - added by Christopher Schwan 12 years ago.
Runscript starting the Notebook server on Gentoo
sage-server (4.6 KB) - added by Kwankyu Lee 10 years ago.
revised for Sage 5.4; removed "upgrade" command
sage-server.zip (2.6 KB) - added by Kwankyu Lee 10 years ago.
revised for Sage 5.4; removed "upgrade" command

Download all attachments as: .zip

Change History (16)

comment:1 Changed 13 years ago by Kwankyu Lee

Description: modified (diff)
Owner: changed from tbd to Kwankyu Lee

comment:2 Changed 13 years ago by Kwankyu Lee

Anybody is welcome to upload an improved version of the script!

comment:3 Changed 12 years ago by Kwankyu Lee

I revised the script according Donald Alan Morrison's comments: 

1) The stop_server function does not do error checking to ensure that
the pid contained in the pid file actually corresponds to a server
process: http://trac.sagemath.org/sage_trac/attachment/ticket/7893/sage-server

30      def stop_server():
31          try:
32              # if sage notebook server is running, "twist.pid" is
created
33              file = open(os.environ['HOME'] + '/.sage/
sage_notebook.sagenb/twistd.pid', 'r')
34              pid = file.readline()
35              file.close()
36              print "Stopping sage server..."
37              os.system('kill -INT ' + pid)
38          except IOError:
39              print "No sage server running."

Given the frequency of reboots for most users, and the cost to the
user of killing a random process, it would be good to error check
against the actual running process name.

2) It would be good to add some code that waits for SIG_TERM to
complete, then optionally sends SIG_KILL.  One can't assume SIG_TERM
will be handled correctly by the server, especially if it's in a bad
state.

3) The script should verify the completion of #2, then delete the pid
files.

-Don

comment:4 Changed 12 years ago by Jeroen Demeyer

Using "screen" is not very portable, so I would avoid that.

comment:5 Changed 12 years ago by Jeroen Demeyer

Typo: twist.pid -> twistd.pid

comment:6 Changed 12 years ago by Kwankyu Lee

Further revised according to the comment :

Line 50 "blocks" (waits syncronously without checking status); also
half of a second may not be long enough if all memory was used up and
there was excessive paging in/out from the swap file.  One alternative
method is to check for the existence of the pid file periodically for
a longer period (possibly parameterized), and if it is deleted,
recheck that the twistd process has indeed exited else send SIGKILL.

Otherwise, good refactor. :-)

-Don

comment:7 Changed 12 years ago by Christopher Schwan

Look at http://trac.sagemath.org/sage_trac/ticket/381 for a similar effort. On Gentoo I automatically start the Notebook with a runscript - I find it very useful because the only thing I have to do is to open a browser and type in the Notebook's address. It is also possible to access the server from a different PC. To make it a more secure it is run as a different user.

I just added a patch which lets one specify the location of twistd's PID file: http://trac.sagemath.org/sage_trac/ticket/10131 - this might be of interest.

Changed 12 years ago by Christopher Schwan

Attachment: sage-notebook-server added

Runscript starting the Notebook server on Gentoo

comment:8 Changed 12 years ago by Christopher Schwan

It should be easy to port the runscript e.g. to debian - as far as I know Debian also has runscript/start-stop-daemon.

comment:9 Changed 10 years ago by Leif Leonhardy

Ping. Shouldn't something like this get shipped with Sage?

Also, the Sage Installation Guide lacks this topic. (There's a reference from the online FAQ to #381 though.)

comment:10 Changed 10 years ago by Leif Leonhardy

Keywords: service daemon mode background added

Changed 10 years ago by Kwankyu Lee

Attachment: sage-server added

revised for Sage 5.4; removed "upgrade" command

Changed 10 years ago by Kwankyu Lee

Attachment: sage-server.zip added

revised for Sage 5.4; removed "upgrade" command

comment:11 Changed 7 years ago by Kwankyu Lee

Milestone: sage-duplicate/invalid/wontfix
Status: newneeds_review

Nowadays the goal of the script can be achieved easily on the OS level using tools such as Upstart in Ubuntu. Even I, the writer of the scipt, ceased using it long time ago.

comment:12 Changed 6 years ago by Frédéric Chapoton

Reviewers: Frédéric Chapoton
Status: needs_reviewpositive_review

ok, then let us close that.

comment:13 Changed 6 years ago by Volker Braun

Resolution: fixed
Status: positive_reviewclosed
Note: See TracTickets for help on using tickets.