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
#!/bin/bash
# 当前系统用户
name='walletdemo'
project='walletdemo'
user=`echo $USER`
pid=`ps -f -u $user | grep $name | grep -v grep | awk '{print $2}'`
echo $pid
echo $user

#判断是否是进程ID,进程ID是数字
if [ -n "$(echo $pid | sed -n "/^[0-9]\+$/p")" ];then
kill -9 $pid
fi

case $1 in
run)
rm -rf $project*
rz
unzip $project.zip
cd $project
go build
./$name server > temp.log 2>&1 &
echo "run success ..."
;;
restart)
cd $project
./$name server > temp.log 2>&1 &
echo "restart success ..."
;;
stop)
echo "stop success ..."
;;
*)
echo "usage: {$0 run|restart|stop}"
;;
esac