listen only 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=3 \
34          -o 127.0.0.1 \
35          -p 5003 -D \
36          --disable-keepalive \
37          -a bin/app.pl --pid $starmanpid
38      echo "...done"
39 }
40
41 stop_starman() {
42     echo -n "Trying to kill starman..."
43     if [ -f "$starmanpid" ]; then 
44         kill $(cat $starmanpid)
45         sleep 2
46         echo "...done"
47     else
48         echo "no pid found, sorry"
49     fi
50 }
51
52 if [ "$1" == "" ]; then
53     echo "Usage: $0 [ --start | --stop ]"
54     exit
55 fi
56
57 case $1 in
58     --start)
59         start_starman
60         ;;
61     --stop)
62         stop_starman
63         ;;
64     --restart)
65         stop_starman
66         start_starman
67         ;;
68     *)
69         echo "uh?"
70         echo "Usage: $0 [ --start | --stop | --restart ]"
71         exit 1
72         ;;
73 esac
74