Listen to 5005 on localhost
[amuse-wiki:amuse-wiki.git] / AmuseWiki / start-app.sh
1 #!/bin/bash
2
3 sleeptime=300
4
5 set -e
6
7 if [ $UID -eq 0 ]; then
8     echo "You're an idiot if you are running this as root"
9     exit 60
10 fi
11
12 cd $(dirname $0)
13
14 basedir=$(pwd)
15 vardir=$basedir/var
16
17 mkdir -p $vardir
18
19 starmanpid="$vardir/starman.pid"
20
21 start_starman() {
22     if [ -f "$starmanpid" ]; then
23         if kill -0 $(cat $starmanpid) >/dev/null 2>&1 ; then
24             echo "Starman is running, nothing to do"
25             exit
26         else
27             rm -f "$starmanpid"
28         fi
29     fi
30     echo -n "Starman is starting..."
31      plackup -E production \
32          -s Starman \
33          --workers=2 \
34          -o 127.0.0.1 \
35          -p 5005 -D \
36          -a bin/app.pl --pid $starmanpid
37      echo "...done"
38 }
39
40 stop_starman() {
41     echo -n "Trying to kill starman..."
42     if [ -f "$starmanpid" ]; then
43         starmanprocid=$(cat $starmanpid)
44         kill -QUIT $starmanprocid
45         while kill -0 $starmanprocid  >/dev/null 2>&1 ; do
46             sleep 1
47             echo -n "."
48         done
49         echo "...done"
50     else
51         echo "no pid found, sorry"
52     fi
53 }
54
55 if [ "$1" == "" ]; then
56     echo "Usage: $0 [ --start | --stop ]"
57     exit
58 fi
59
60 case $1 in
61     --start)
62         start_starman
63         ;;
64     --stop)
65         stop_starman
66         ;;
67     --restart)
68         stop_starman
69         start_starman
70         ;;
71     *)
72         echo "uh?"
73         echo "Usage: $0 [ --start | --stop | --restart ]"
74         exit 1
75         ;;
76 esac
77