forked from svenvc/pharo-server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pharo-ctl.sh
executable file
·136 lines (118 loc) · 2.49 KB
/
pharo-ctl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
function usage() {
cat <<END
Usage: $0 <script> <command> <image>
manage a Pharo server
Naming
script is used as unique identifier
script.st must exist and is the Pharo startup script
script.pid will be used to hold the process id
image.image is the Pharo image that will be started
Commands:
start start the server in background
stop stop the server
restart restart the server
run run the server in foreground
pid print the process id
END
exit 1
}
script_home=$(dirname $0)
script_home=$(cd $script_home && pwd)
script=$1
command=$2
image=$3
echo Executing $0 $script $command $image
echo Working directory $script_home
if [ "$#" -ne 3 ]; then
usage
fi
image="$script_home/$image.image"
if [ ! -e "$image" ]; then
echo $image not found
exit 1
fi
st_file="$script_home/$script.st"
if [ ! -e "$st_file" ]; then
echo $st_file not found
exit 1
fi
pid_file="$script_home/$script.pid"
vm=$script_home/../bin/pharo-vm/pharo
options="--nodisplay"
function start() {
echo Starting $script in background
if [ -e "$pid_file" ]; then
rm -f $pid_file
fi
echo $vm $options $image $st_file
$vm $options $image $st_file 2>&1 >/dev/null &
echo $! >$pid_file
}
function run() {
echo Running $script in foreground
echo $vm $options $image $st_file
$vm $options $image $st_file
}
function stop() {
echo Stopping $script
if [ -e "$pid_file" ]; then
pid=`cat $pid_file`
echo Killing $pid
kill $pid
rm -f $pid_file
else
echo Pid file not found: $pid_file
echo Searching in process list for $script
pids=`ps ax | grep $script | grep -v grep | grep -v $0 | awk '{print $1}'`
if [ -z "$pids" ]; then
echo No pids found!
else
for p in $pids; do
if [ $p != "$pid" ]; then
echo Killing $p
kill $p
fi
done
fi
fi
}
function restart() {
echo Restarting $script
stop
start
}
function printpid() {
if [ -e $pid_file ]; then
cat $pid_file
else
echo Pid file not found: $pid_file
echo Searching in process list for $script
pids=`ps ax | grep $script | grep -v grep | grep -v $0 | awk '{print $1}'`
if [ -z "$pids" ]; then
echo No pids found!
else
echo $pids
fi
fi
}
case $command in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
run)
run
;;
pid)
printpid
;;
*)
usage
;;
esac