-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·95 lines (76 loc) · 2.03 KB
/
run.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
#!/bin/bash
exec_name="mssws_prog"
go_src="main.go"
genindex_script="genindex.sh"
# save result of get_pids
g_pids=()
function f_get_pids() {
g_pids=$(pgrep "${exec_name}")
return 0
}
function f_check_root_rights() {
if (( EUID != 0 )); then
echo "Please run as root to make sure mssws can bind success."
exit
fi
}
function f_run_program() {
# f_check_root_rights
if [ ! -f ${exec_name} ]; then
echo "${exec_name} don't exist, please run 'bash run.sh compile' first."
exit
fi
f_get_pids
for p in "${g_pids[@]}"; do
if [[ "${p}" =~ ^[0-9]+$ ]]; then
echo "kill ${exec_name} [ ${p} ]."
kill "${p}"
fi
done
echo "start run ${exec_name} ..."
nohup ./${exec_name} &>server.log &
f_get_pids
for p in "${g_pids[@]}"; do
if [[ "${p}" =~ ^[0-9]+$ ]]; then
echo "run ${exec_name} [ ${p} ] success ..."
exit 0
fi
done
echo "run ${exec_name} failed ..."
exit -1
}
################################################################################
if [ ! -f ${genindex_script} ]; then
echo "${genindex_script} not exist!"
exit
else
sh ${genindex_script}
echo "generate index page data."
fi
if [ $# = 0 ]; then
echo "compile ${exec_name} ..."
go build -o ${exec_name} ${go_src}
f_run_program
exit
fi
if [ "$1" == "help" ]; then
echo "run.sh Usage"
echo "./run.sh help show run.sh help"
echo "./run.sh kill kill ${exec_name}"
echo "./run.sh compile compile ${exec_name}"
echo "./run.sh restart kill and restart ${exec_name}"
echo "./run.sh compile ${exec_name} and restart ${exec_name}"
elif [ "$1" = "kill" ]; then
f_get_pids
for p in "${g_pids[@]}"; do
echo "kill ${exec_name} [ ${p} ]"
kill "${p}"
done
elif [ "$1" = "compile" ]; then
echo "compile ${exec_name} ..."
go build -o ${exec_name} ${go_src}
elif [ "$1" = "restart" ]; then
f_run_program
else
echo "wrong argument. run 'bash run.sh help' to get more info"
fi