-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·69 lines (58 loc) · 1.66 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
#!/bin/bash
SERVER_IP=$(ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n 1)
# start services
function start_services() {
nohup bin/stored --grpc-addr $SERVER_IP:9082 &
sleep 1
nohup bin/ctld --stored-addr $SERVER_IP:9082 --grpc-addr $SERVER_IP:9083 &
sleep 1
nohup bin/apid --ctld-addr $SERVER_IP:9083 --http-addr $SERVER_IP:9084 &
sleep 1
ps -ef | grep $SERVER_IP | grep bin
echo "Services are started"
}
# stop services
function stop_services() {
ps -ef | grep $SERVER_IP | grep bin | awk '{print $2}' | xargs kill
ps -ef | grep $SERVER_IP | grep bin
echo "Services are stopped"
}
# status services
function status_services() {
ps -ef | grep $SERVER_IP | grep bin
}
# test add user
function test_add_user() {
curl -XPOST -H "Content-Type: application/json" -d '{"email":"test@live.cn", "username":"test"}' http://$SERVER_IP:9084/user
}
# test delete user
function test_delete_user() {
curl -XDELETE http://$SERVER_IP:9084/user/$1
}
# if the `logs` directory does not exist, create it
if [ ! -d "logs" ]; then
mkdir logs
fi
# check command
if [ "$1" == "start" ]; then
start_services
elif [ "$1" == "stop" ]; then
stop_services
elif [ "$1" == "restart" ]; then
stop_services
start_services
elif [ "$1" == "status" ]; then
status_services
elif [ "$1" == "test" ]; then
if [ "$2" == "create" ]; then
test_add_user
elif [ "$2" == "delete" ]; then
test_delete_user $3
else
echo "Usage: $0 test {create|delete}"
exit 1
fi
else
echo "Usage: $0 {start|stop|restart|status}"
exit 1
fi