Opened 11 years ago
Closed 5 years ago
#7893 closed task (fixed)
Sage server launching script
Reported by: | klee | Owned by: | klee |
---|---|---|---|
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: |
Description (last modified by )
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)
Change History (16)
comment:1 Changed 11 years ago by
- Description modified (diff)
- Owner changed from tbd to klee
comment:2 Changed 11 years ago by
comment:3 Changed 11 years ago by
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 11 years ago by
Using "screen" is not very portable, so I would avoid that.
comment:5 Changed 11 years ago by
Typo: twist.pid -> twistd.pid
comment:6 Changed 11 years ago by
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 11 years ago by
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.
comment:8 Changed 11 years ago by
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 8 years ago by
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 8 years ago by
- Keywords service daemon mode background added
comment:11 Changed 5 years ago by
- Milestone set to sage-duplicate/invalid/wontfix
- Status changed from new to needs_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 5 years ago by
- Reviewers set to Frédéric Chapoton
- Status changed from needs_review to positive_review
ok, then let us close that.
comment:13 Changed 5 years ago by
- Resolution set to fixed
- Status changed from positive_review to closed
Anybody is welcome to upload an improved version of the script!