2013/08/22

Sage(math) in the Amazon Web Service

A few days a go a new version of Sage has been released, the 5.11.

When I was doing a coursera's High Performance Scientific Computing, I've learn how to have a small machine in the Amazon Web Services. In particular I've set up, as the course shows but was just one of the options I would do, an Ubuntu 13.04 Amazon Machine Image (It look that the ami I used is no longer available).

With this very small virtual machine (64bits, Up to 2 EC2 Compute Units (for short periodic bursts), 613 MiB memory, 8GB Hard disk, I/O Performance: Low). And for the first year the service is for free.

What to do with a machine in the cloud? Lets be sage...

There is a easy way to have your sage installation and someone else will maintain the sagemath package. With 3 commands you can have an installation in your ubuntu.

The thing I did by hand was and script to insert this as a service in the init.d:
#!/bin/bash
# configuration
SAGE_OPTS="-notebook interface='' secure=True"
SAGE_LOG="/var/log/sage/sage.log"
SAGE_USER='ubuntu' #default in aws machine
# commands
CMD_ECHO="/bin/echo"
CMD_GREP="/bin/grep"
CMD_SLEEP="/bin/sleep"
CMD_KILLALL="/usr/bin/killall"
sage_start() {
        $CMD_ECHO "Starting Sage..."
        (su - $SAGE_USER -c "sage $SAGE_OPTS" 2&>1 ) >> $SAGE_LOG &
}
sage_stop() {
        $CMD_ECHO "Stopping Sage..."
        # CAUTION : maybe you kill something important in your server
        #$CMD_KILLALL python
        ps -ef |grep "sage -notebook" |grep -v grep|awk '{print $2}' |xargs kill -9
}
case $1 in
        start)
                sage_start
                ;;
        stop)
                sage_stop
                ;;
        restart)
                sage_stop
                $CMD_SLEEP 5
                sage_start
                ;;
        *)
                $CMD_ECHO "Use: $0 {start|stop|restart}"
                exit 1
                ;;
esac
exit 0

After that, a simple:
$ /etc/init.d/sage_daemon start
is enough to have the notebook  up and running. Perhaps you would prefer to insert it to the boot process
$ sudo update-rc.d sage_daemon defaults 95
(this is only an example)

Best of all is that since I installed it (it was version 5.9) to the current 5.11, those two updates have been as simple as:
$ sudo apt-get dist-upgrade


Incredible, I'm really happy with this, the only point I'm missing is to have those binaries also available for debian's installations.

No comments: