FS#23273 - [sage-mathematics] Maybe we should have /etc/rc.d/sage that starts 'sage -notebook'?

Attached to Project: Community Packages
Opened by Andrzej Giniewicz (Giniu) - Monday, 14 March 2011, 19:59 GMT
Last edited by Thomas Dziedzic (tomd123) - Wednesday, 03 August 2011, 15:00 GMT
Task Type Feature Request
Category Upstream Bugs
Status Closed
Assigned To Thomas Dziedzic (tomd123)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 2
Private No

Details

In multiple cases one would like to start sage server together with system, especially if it's running on dedicated machine. How about creating standard /etc/rc.d/sage to bring the server up and including it in the package?
This task depends upon

Closed by  Thomas Dziedzic (tomd123)
Wednesday, 03 August 2011, 15:00 GMT
Reason for closing:  Upstream
Additional comments about closing:  reopen when upstream decides to implement the feature request
Comment by Thomas Dziedzic (tomd123) - Tuesday, 15 March 2011, 23:53 GMT
I like this idea, I'll try to get something done today so you can test it.
Comment by Thomas Dziedzic (tomd123) - Wednesday, 16 March 2011, 00:05 GMT
I would like to get your opinion on this, but should I create a new user then named "sage" and run the daemon as that user?
I don't exactly know if running sage with root permissions would be a smart thing to do.
Comment by Andrzej Giniewicz (Giniu) - Wednesday, 16 March 2011, 04:52 GMT
I think we should avoid running as root at all cost. At least I know that on some platforms sage install (so maybe also update/rebuild) can sometimes try writing to absolute paths. It's known bug - http://trac.sagemath.org/sage_trac/ticket/9551 - so the separate user way is I believe best (and one that that makes it easier to control the rights). Also remember, that this would allow for python instance running as root, so access to all files would be granted to all that login trough web interface.
Comment by Thomas Dziedzic (tomd123) - Sunday, 20 March 2011, 20:37 GMT
I don't know how well this is going to work out, I have the following sequence of commands:

I created the sagemath user by running:
useradd -r -c 'Sage daemon' -d /opt/sage -s /bin/false sagemath

I then ran:
sudo -u sagemath sh -c "[ -d /opt/sage/.sage/ ] && export HOME=/opt/sage && HOME=/opt/sage /opt/sage/sage -notebook"

And I got the message:
----------------------------------------------------------------------
| Sage Version 4.6.2, Release Date: 2011-02-25 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------

Please wait while the Sage Notebook server starts...
Traceback (most recent call last):
File "/opt/sage/local/bin/sage-notebook", line 9, in <module>
from sage.server.notebook.all import notebook
File "/opt/sage/local/lib/python2.6/site-packages/sage/server/notebook/all.py", line 22, in <module>
from sagenb.notebook.all import *
File "/opt/sage/devel/sagenb/sagenb/notebook/all.py", line 16, in <module>
from notebook_object import notebook, inotebook
File "/opt/sage/devel/sagenb/sagenb/notebook/notebook_object.py", line 17, in <module>
import notebook as _notebook
File "/opt/sage/devel/sagenb/sagenb/notebook/notebook.py", line 35, in <module>
from sagenb.misc.misc import (pad_zeros, cputime, tmp_dir, load, save,
File "/opt/sage/devel/sagenb/sagenb/misc/misc.py", line 13, in <module>
from pkg_resources import resource_filename
File "/opt/sage/local/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg/pkg_resources.py", line 2553, in <module>
File "/opt/sage/local/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg/pkg_resources.py", line 384, in __init__
File "/opt/sage/local/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg/pkg_resources.py", line 399, in add_entry
File "/opt/sage/local/lib/python2.6/site-packages/setuptools-0.6c9-py2.6.egg/pkg_resources.py", line 1659, in find_on_path
OSError: [Errno 13] Permission denied: '/home/tom'

If this requires upstream patching, then this should be submitted to upstream as a feature request for a daemon mode, or make it play nice with user variables instead.
Any ideas?
Comment by Andrzej Giniewicz (Giniu) - Sunday, 20 March 2011, 20:47 GMT
maybe try running notebook with parameters like

sage -notebook directory=/opt/sage/notebook open_viewer=False

or something like that? All options are listed under documentation for notebook function.
Comment by Andrzej Giniewicz (Giniu) - Sunday, 20 March 2011, 20:55 GMT
The problem might be with first run, because user have to specify the password automatically, probably it should be run once in sage.install so user is asked for pass, but user will have to close the window then.
Comment by Thomas Dziedzic (tomd123) - Sunday, 20 March 2011, 20:57 GMT
nvm, got it to run using:
sudo -u sagemath sh -c 'export HOME=/opt/sage && [ -d $HOME/.sage/ ] && cd $HOME && /opt/sage/sage -notebook'
Comment by Thomas Dziedzic (tomd123) - Sunday, 20 March 2011, 20:59 GMT
Yup, I already check if it has been run before by [ -d $HOME/.sage/ ] :) thanks

Shorter command that works:
sudo -u sagemath sh -c '[ -d $HOME/.sage/ ] && cd $HOME && /opt/sage/sage -notebook'
Comment by Thomas Dziedzic (tomd123) - Sunday, 20 March 2011, 21:14 GMT
so it seems you can't start sage in the background without creating some custom run script:
http://trac.sagemath.org/sage_trac/ticket/381 - SAGE daemon mode
http://trac.sagemath.org/sage_trac/ticket/7893 - Sage server launching script

Maybe upstream needs someone to shake them awake to get this implemented? It seems people have posted patches, but the bugs have gone stagnant.
Comment by Andrzej Giniewicz (Giniu) - Sunday, 20 March 2011, 21:21 GMT
Thanks for links, I will test the scripts and maybe review the ticket if it works, it should remind others about it
Comment by Thomas Dziedzic (tomd123) - Sunday, 20 March 2011, 23:24 GMT
I already talked to some people in #sagemath and they also agreed it seems like an easy feature to implement.
Hopefully us bothering them will produce some nice results for 4.7 :)

Testing the scripts would be awesome, showing that others are interested in the feature!
Comment by Thomas Dziedzic (tomd123) - Monday, 21 March 2011, 03:56 GMT
Marking as an upstream bug since the progress of this depends on upstream bugs.
Comment by Thomas Dziedzic (tomd123) - Tuesday, 22 March 2011, 09:15 GMT
For reference, also attaching my sage daemon script. It needs a way to put sage to the background.
   sage (0.7 KiB)
Comment by Thomas Dziedzic (tomd123) - Wednesday, 03 August 2011, 14:59 GMT
unfortunately, this bug depends on an upstream bug report which isn't getting any attention.
Please reopen this bug once upstream implements the following reports:

http://trac.sagemath.org/sage_trac/ticket/381
http://trac.sagemath.org/sage_trac/ticket/7893

Closing

Loading...