-
Notifications
You must be signed in to change notification settings - Fork 13
/
server
164 lines (135 loc) · 4.1 KB
/
server
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env bash
export LC_ALL=C
B="[40;36m"
W="[40;37m"
G="[40;32m"
R="[40;31m"
Y="[40;33m"
P="[40;35m"
case "$1" in
start)
echo $G"STARTING SERVER!"$W
cd ~/gf_server/TicketServer/
chmod 777 *
./TicketServer -p 7777 &>/dev/null &
sleep 2
cd ~/gf_server/GatewayServer/
chmod 777 *
./GatewayServer &>/dev/null &
sleep 2
cd ~/gf_server/LoginServer/
chmod 777 *
./LoginServer &>/dev/null &
sleep 2
cd ~/gf_server/MissionServer/
chmod 777 *
./MissionServer &>/dev/null &
sleep 2
cd ~/gf_server/WorldServer/
chmod 777 *
./WorldServer &>/dev/null &
sleep 4
cd ~/gf_server/ZoneServer/
chmod 777 *
./ZoneServer &>/dev/null &
freemem=$(free -m | grep "Mem:" | awk '{print $4}')
echo $B"SERVER STARTED! ${Y}Memory Available: ${freemem} MB"${W}
;;
stop)
echo $R"STOPPING SERVER!"$W
killall -9 LoginServer >/dev/null &
sleep 2
killall -9 GatewayServer >/dev/null &
sleep 2
killall -9 TicketServer >/dev/null &
sleep 2
killall -9 MissionServer >/dev/null &
sleep 2
killall -9 WorldServer >/dev/null &
sleep 2
killall -9 ZoneServer >/dev/null &
sleep 2
freemem=$(free -m | grep "Mem:" | awk '{print $4}')
echo $B"SERVER STOPPED! ${Y}Memory Available: ${freemem} MB"${W}
;;
restart)
./server stop
sleep 2
./server start
;;
status)
freemem=$(free -m | grep "Mem:" | awk '{print $4}')
echo $Y"Memory Available: ${freemem} MB"${W}
;;
backup)
echo $P"CREATING BACKUP!"$W
echo "Please Enter PostgreSQL Password:"
read db_pwd
export PGPASSWORD=$db_pwd
folder_name=backup_$(date +%Y_%m_%d_%H_%M_%S)
sudo mkdir -p /root/gf_server/backup/$folder_name
echo "Creating gf_gs backup"
pg_dump -U postgres -Fp gf_gs > /root/gf_server/backup/$folder_name/gf_gs.sql
echo "Creating gf_ls backup"
pg_dump -U postgres -Fp gf_ls > /root/gf_server/backup/$folder_name/gf_ls.sql
echo "Creating gf_ms backup"
pg_dump -U postgres -Fp gf_ms > /root/gf_server/backup/$folder_name/gf_ms.sql
chmod -R 777 /root
echo $B"BACKUP CREATED! > $folder_name"$W
;;
restore)
echo $P"RESTORING BACKUP!"$W
if [ -z "$2" ]; then
echo "Please Use: ./server restore <folder name ex: backup_2023_01_17_02_55_10>"
exit 1
fi
if [ ! -d "/root/gf_server/backup/$2" ]; then
echo "Backup Folder Not Found"
exit 1
fi
if [ $(find /root/gf_server/backup/$2 -name "gf_gs.sql" -o -name "gf_ls.sql" -o -name "gf_ms.sql" | wc -l) -ne 3 ]; then
echo "Some Backup Files 'gf_gs.sql, gf_ls.sql, gf_ms.sql' Not Found!"
exit 1
fi
echo "Please Enter PostgreSQL Password:"
read db_pwd
export PGPASSWORD=$db_pwd
folder_name=$2
echo "Restoring gf_gs backup"
psql -U postgres -c "DROP DATABASE gf_gs;"
psql -U postgres -c "create database gf_gs encoding 'UTF8' template template0;"
psql -U postgres -d gf_gs -f /root/gf_server/backup/$folder_name/gf_gs.sql
echo "Restoring gf_ls backup"
psql -U postgres -c "DROP DATABASE gf_ls;"
psql -U postgres -c "create database gf_ls encoding 'UTF8' template template0;"
psql -U postgres -d gf_ls -f /root/gf_server/backup/$folder_name/gf_ls.sql
echo "Restoring gf_ms backup"
psql -U postgres -c "DROP DATABASE gf_ms;"
psql -U postgres -c "create database gf_ms encoding 'UTF8' template template0;"
psql -U postgres -d gf_ms -f /root/gf_server/backup/$folder_name/gf_ms.sql
chmod -R 777 /root
echo $B"BACKUP RESTORATION DONE! > $folder_name"$W
;;
clear)
echo $P"CLEANING LOGS!"$W
cat /dev/null >/var/log/syslog
cat /dev/null >/var/log/wtmp
cat /dev/null >/var/log/maillog
cat /dev/null >/var/log/messages
cat /dev/null >/var/log/openwebmail.log
cat /dev/null >/var/log/maillog
cat /dev/null >/var/log/secure
find . -name "*.log.*" -type f -print -exec rm -rf {} \;
;;
*)
echo "Usage: $0 {start|stop|restart|status|backup|restore|clear}"
echo "start - Start Sever"
echo "stop - Stop Server"
echo "restart - Restart Server"
echo "status - Show Server Memory Usage"
echo "backup - Create DB backup 'gf_gs, gf_ls, gf_ms'"
echo "restore - Restore Backup |Usage: ./server restore <folder name ex: backup_2023_01_17_02_55_10>"
echo "clear - Clear Server Logs"
exit 1
;;
esac