Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagesmc
Path: blob/master/src/mac-app/sage-is-running-on-port.sh
8815 views
1
#!/bin/bash
2
3
# sage-is-running-on-port.sh
4
# Sage
5
#
6
# Created by Ivan Andrus on 16/9/10.
7
# Copyright 2010 __MyCompanyName__. All rights reserved.
8
9
WAIT=0
10
if [ "x$1" = "x--wait" ]; then
11
WAIT=1
12
shift
13
fi
14
15
# Set the pid file
16
PID_FILE=${1-~/.sage/sage_notebook.sagenb/sagenb.pid}
17
18
# Check the old pid file in case they are running an older version of Sage
19
if [ ! -e "$PID_FILE" ] && [ -e ~/.sage/sage_notebook.sagenb/twistd.pid ]; then
20
PID_FILE=${1-~/.sage/sage_notebook.sagenb/twistd.pid}
21
fi
22
23
# Wait for a server to start (or at least for a pid file)
24
while [ "$WAIT" = 1 ] && [ ! -e "$PID_FILE" ]; do
25
sleep 1
26
# Check the old pid file in case they are running an older version of Sage
27
if [ ! -e "$PID_FILE" ] && [ -e ~/.sage/sage_notebook.sagenb/twistd.pid ]; then
28
PID_FILE=${1-~/.sage/sage_notebook.sagenb/twistd.pid}
29
fi
30
done
31
32
# If the server is running, get the port for it (I hope this is right)
33
if [ -e "$PID_FILE" ] && kill -0 $(cat "$PID_FILE") 2>/dev/null; then
34
grep -Eoe 'port=[0-9]+' ~/.sage/sage_notebook.sagenb/twistedconf.tac | cut -f 2 -d=
35
exit 0
36
fi
37
38
# It's not running so return failure
39
echo 0
40
exit 1
41
42