Ask Your Question

Guille's profile - activity

2012-03-11 09:58:03 +0200 received badge  Teacher (source)
2012-03-11 09:58:03 +0200 received badge  Necromancer (source)
2012-03-08 15:26:13 +0200 commented answer how to run sage as a service

Oh, I've just forgot the most important command: /etc/init.d/sage_daemon start, and you are ready to go.

2012-03-08 15:21:24 +0200 answered a question how to run sage as a service

Create the file /etc/init.d/sage_daemon (chmod 755) with the following content:

#!/bin/bash
# configuration
SAGE_HOME="/usr/local/install/sage-4.8"
SAGE_OPTS="-notebook interface='' secure=True"
SAGE_LOG="/var/log/sage/sage.log"
# commands
CMD_ECHO="/bin/echo"
CMD_GREP="/bin/grep"
CMD_SLEEP="/bin/sleep"
CMD_KILLALL="/usr/bin/killall"
sage_start() {
        $CMD_ECHO "Starting Sage..."
        $SAGE_HOME/sage $SAGE_OPTS >> $SAGE_LOG 2>&1 &
}
sage_stop() {
        $CMD_ECHO "Stopping Sage..."
        # CAUTION : maybe you kill something important in your server
        $CMD_KILLALL python
}
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

Configure $CMD_* according to your Unix/Linux environment (use "which" command to locate the right paths). In order to automatically start the service (Debian) when the server starts, you should run this command:

/etc/init.d# update-rc.d sage_daemon defaults 95

Hope it'd be useful for other people too.