Path: blob/master/src/mac-app/sage-is-running-on-port.sh
8815 views
#!/bin/bash12# sage-is-running-on-port.sh3# Sage4#5# Created by Ivan Andrus on 16/9/10.6# Copyright 2010 __MyCompanyName__. All rights reserved.78WAIT=09if [ "x$1" = "x--wait" ]; then10WAIT=111shift12fi1314# Set the pid file15PID_FILE=${1-~/.sage/sage_notebook.sagenb/sagenb.pid}1617# Check the old pid file in case they are running an older version of Sage18if [ ! -e "$PID_FILE" ] && [ -e ~/.sage/sage_notebook.sagenb/twistd.pid ]; then19PID_FILE=${1-~/.sage/sage_notebook.sagenb/twistd.pid}20fi2122# Wait for a server to start (or at least for a pid file)23while [ "$WAIT" = 1 ] && [ ! -e "$PID_FILE" ]; do24sleep 125# Check the old pid file in case they are running an older version of Sage26if [ ! -e "$PID_FILE" ] && [ -e ~/.sage/sage_notebook.sagenb/twistd.pid ]; then27PID_FILE=${1-~/.sage/sage_notebook.sagenb/twistd.pid}28fi29done3031# If the server is running, get the port for it (I hope this is right)32if [ -e "$PID_FILE" ] && kill -0 $(cat "$PID_FILE") 2>/dev/null; then33grep -Eoe 'port=[0-9]+' ~/.sage/sage_notebook.sagenb/twistedconf.tac | cut -f 2 -d=34exit 035fi3637# It's not running so return failure38echo 039exit 1404142