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
Hacking replay gain audio normalization into Jellyfin

There is already a feature request for audio normalization in Jellyfin media server. This is important if you want to listen to your music collection while always having the same loudness level. Usually, in different recordings or music genres some tracks are louder and others are more quiet. The standard …

Software
Importing playlists to Jellyfin media server

In the following post I would like to describe a way to import music playlists to Jellyfin media server, for example in case you want to migrate them from a former Plex or Emby installation. Usually, Jellyfin is already able to detect playlist files within the media library. Unfortunately my …

Software
Jellyfin media server on Archlinux ARM

In this post, I want to share some insights on building Jellyfin media server for Archlinux ARM. The PKGBUILD for Jellyfin one can find on the AUR, is specifically made for 64 bit architectures. Nevertheless Microsoft released the dotnet runtime, which Jellyfin relies on instead of Mono, also for Linux …