forked from nivin-studio/go-zero-mall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnivin
44 lines (39 loc) · 1.02 KB
/
nivin
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
#!/bin/bash
Green="\033[32m"
Red="\033[31m"
GreenBG="\033[42;37m"
RedBG="\033[41;37m"
Font="\033[0m"
OK="${Green}[OK]${Font}"
Error="${Red}[错误]${Font}"
check_screen() {
screen -v &> /dev/null
if [ $? -ne 0 ]; then
echo -e "${Error} ${RedBG} 未安装 screen!${Font}"
exit 1
fi
}
check_screen
if [ $# -gt 0 ]; then
if [[ "$1" == "init" ]] || [[ "$1" == "install" ]]; then
go mod tidy
elif [[ "$1" == "start" ]]; then
shift 1
cmd="cd service/$2/$1 && go run $2.go -f etc/$2.yaml\n"
screen -S $1$2 -X quit
screen -dmS $1$2
screen -S $1$2 -p 0 -X stuff "$cmd"
screen -ls
echo -e "${OK} ${GreenBG} $2 $1 服务已启动! ${Font}"
elif [[ "$1" == "stop" ]]; then
shift 1
screen -S $1$2 -X quit
screen -ls
echo -e "${OK} ${GreenBG} $2 $1 服务已暂停! ${Font}"
elif [[ "$1" == "info" ]]; then
shift 1
screen -r $1$2
elif [[ "$1" == "ls" ]]; then
screen -ls
fi
fi