Install Sage 5.3 on Debian Squeeze + InitScript

One virtual machine on our private network runs an instance of Sage, which is an open-source alternative to Matlab, Maple or Mathematica. In fact it’s a very powerful framwork using Python as primary language for describing (for example) mathematical, algorithmic or topological problems. It comes handy for practices at university in algorithms or cryptography courses and there’s already a lot of sage related documentation and material outthere.
Still, there’s one problem with distribution packaging to solve to make Sage available to a broader audience. Because Sage consists of various Python libraries and toolkits, which are packed with Sage, it’s difficult to maintain and distribute it, especially if you don’t want to serve one monolithic program instead of seperating the libs as dependency.
Nevertheless, installing Sage (even as a daemon) is easy and here’s a short how-to for Debian Squeeze:

useradd sage
mkdir /home/sage /usr/local/sage # Home-Dir contains all preferences and project-files of Sage
chown -R sage:sage /usr/local/sage /home/sage
su sage
cd /usr/local/sage
aria2c "http://www.sagemath.org/mirror/src/meta/sage-5.3.tar.torrent"
tar xvf sage-5.3.tar --strip-components=1
export MAKE="make -j4"
make
mkdir /var/log/sage
chown -R sage:sage /var/log/sage
./sage -upgrade
./sage
sage: optional_packages()
sage: install_package('openmpi-XXX')
sage: install_package('mpi4py-YYY')
#!/bin/bash

### BEGIN INIT INFO
# Provides:          sage
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts sage-mathematics server
# Description:       starts sage-mathematics server using start-stop-daemon
### END INIT INFO

# configuration
SAGE_HOME="/usr/local/sage"
SAGE_OPTS="-notebook interface=10.25.0.105 port=8081"
SAGE_LOG="/var/log/sage/sage.log"
# commands
USER="sage"
NAME="sage"

sage_start() {
        echo "Starting Sage..."
        start-stop-daemon --start --background --chuid "$USER" --chdir "$SAGE_HOME" --exec $SAGE_HOME/sage -- $SAGE_OPTS # -- $SAGE_LOG
}
sage_stop() {
        echo "Stopping Sage..."
        kill `ls "/home/$USER/.sage/temp/application/"`
}
case $1 in
        start)
                sage_start
                ;;
        stop)  
                sage_stop
                ;;
        restart)
                sage_stop
                sleep 5
                sage_start
                ;;
        *)
                echo "Use: $0 {start|stop|restart}"
                exit 1
                ;;
esac
exit 0

Adjust the variable SAGE_OPTS for the parameters passed to Sage. In most cases “-notebook” should be enough, if you only want to use Sage locally. The sage_stop function is a bit hacky but it works for me.
To autostart the daemon at boot time, run:

chmod +x /etc/init.d/sage
update-rc.d sage defaults 95
/etc/init.d/sage start

You can access Sage with your browser (considering default settings) on http://127.0.0.1:8080.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

* Checkbox GDPR is required

*

I agree

Software
Virtual 3D online exhibition with MapBox GL JS

For my last semester in university (summer semester 2018) at the KIT, I was part of a project to create an “online art exhibition”. We planned to produce different media formats in smaller groups. One for video, another for text and promotion and one for the online presence. I’ve figured …

Software
Host your own Mapbox GL JS vector tiles map

I’ve done some research recently on how I could host my own online map viewer with a MapBox GL JS instance, an excellent and modern open-source alternative for Google Maps. The server should also serve own preprocessed map data from OpenStreetmap planet extracts. No external or third-party service will be …

Software
1
Easily setup Signal 2FA on Nextcloud 14

Two-factor authentication (short 2FA) is an important security concept to secure unauthorized access to your web applications. Popular online services like Google Mail, Instagram or Facebook already provide this mechanism to secure user accounts with an additional one-time token. Considering someone is able to obtain your username and password combination, …