forked from svenvc/pharo-server-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpharo-ctl.sh
More file actions
executable file
·150 lines (130 loc) · 2.95 KB
/
pharo-ctl.sh
File metadata and controls
executable file
·150 lines (130 loc) · 2.95 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/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"
# If needed, modify VM version here
vm_version_short=8
# Some magick to switch VM options by version
# See https://stackoverflow.com/a/18124325
vm_version="$vm_version_short.0"
vm_options_8="--vm-display-null"
vm_options_9="--headless"
vm_options_10="--headless"
vm_options_11="--headless"
vm_options_var=vm_options_$vm_version_short
vm_options=${!vm_options_var}
vm_home=$(/usr/bin/realpath $script_home/../lib/$vm_version)
# Using lower level script to make sure 'ps' lists only 1 process
vm=$vm_home/pharo-vm/pharo
function start() {
echo Starting $script in background
if [ -e "$pid_file" ]; then
rm -f $pid_file
fi
echo $vm $vm_options $image $st_file
$vm $vm_options $image $st_file 2>&1 >/dev/null &
echo $! >$pid_file
}
function run() {
echo Running $script in foreground
echo $vm $vm_options $image $st_file
$vm $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