Repository navigation
Expand file tree
/
Copy pathstart_server.sh
More file actions
executable file
·147 lines (112 loc) · 4.25 KB
/
Copy pathstart_server.sh
File metadata and controls
executable file
·147 lines (112 loc) · 4.25 KB
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
#!/bin/bash
# ===== CONFIGURATION =====
PROTON_DIR="$HOME/.steam/steam/steamapps/common/Proton 9.0 (Beta)"
PROTON_RUN="$PROTON_DIR/proton"
SERVER_DIR="$HOME/.steam/steam/steamapps/common/DayZServer"
SERVER_EXE="DayZServer_x64.exe"
SCRIPT_DIR="$SERVER_DIR/script_server_linux"
MOD_ID_FILE="mod_ids.txt"
SERVER_MODS='-serverMod=servermod'
SERVER_PORT='-port=2302'
SERVER_CPU='-cpuCount=2'
SERVER_OTHERS='-dologs -adminlog -netlog -freezecheck'
CONFIG="-config=serverDZ.cfg"
PROFILES="-profiles=profiles"
# ===== PREPARE MOD LIST =====
MODS_SUBDIR="mods/"
if [ ! -f "$SCRIPT_DIR/$MOD_ID_FILE" ]; then
echo "❌ File mod_ids.txt not found!"
exit 1
fi
MODS_ID=$(<"$SCRIPT_DIR/$MOD_ID_FILE")
MODS_ID="${MODS_ID//\"/}" # Remove quotes
MODS_ID="${MODS_ID// /}" # Remove spaces
MODS_ID="${MODS_ID//$'\n'/}" # Remove newlines
MODS_ID="${MODS_ID//$'\t'/}" # (Optional) Remove tabs
MODS_PARAM_TEMP=""
IFS=';' read -ra IDS <<< "$MODS_ID"
for id in "${IDS[@]}"; do
MODS_PARAM_TEMP+="${MODS_SUBDIR}${id};"
done
if [[ -z "$MODS_PARAM_TEMP" ]]; then
echo "⚠️ No mod was loaded, check the mod_ids.txt file"
exit 1
fi
# ===== Remove last semicolon =====
MODS_PARAM_TEMP="${MODS_PARAM_TEMP::-1}"
MODS="-mod=${MODS_PARAM_TEMP}"
echo "✅ All mods have been formatted."
# ===== PREFIX AND REQUIRED VARIABLES =====
STEAM_COMPAT_DATA_PATH="$HOME/.steam/steam/steamapps/compatdata"
STEAM_COMPAT_CLIENT_INSTALL_PATH="$HOME/.steam/steam"
export STEAM_COMPAT_DATA_PATH
export STEAM_COMPAT_CLIENT_INSTALL_PATH
# ===== CLEANUP LOGS =====
echo "🧹 Deleting .RPT, .log and .mdmp files in: $SERVER_DIR/profiles"
rm -f "$SERVER_DIR"/profiles/*.RPT "$SERVER_DIR"/profiles/*.ADM "$SERVER_DIR"/profiles/*.log "$SERVER_DIR"/profiles/*.mdmp
rm -f "$SERVER_DIR"/profiles/WebApiLog/*.log "$SERVER_DIR"/profiles/LBmaster/Data/Core/Players/*.json "$SERVER_DIR"/profiles/ExpansionMod/Logs/*.log "$SERVER_DIR"/profiles/EventManagerLog/*.log "$SERVER_DIR"/profiles/CBD_LootSystem/Logging/Logs/*.log "$SERVER_DIR"/profiles/BXDCarLock/CarLockLogging/Logs/*.log
rm -rf "$SERVER_DIR"/profiles/CodeLock/Logs
echo "✅ Cleanup completed."
# ===== EXECUTION =====
cd "$SERVER_DIR" || { echo "❌ Could not enter server directory."; exit 1; }
echo "🚀 Starting DayZ server with Proton..."
"$PROTON_RUN" run "./$SERVER_EXE" $CONFIG $PROFILES "$MODS" "$SERVER_MODS" "$SERVER_PORT" "$SERVER_CPU" "$SERVER_OTHERS" &
SERVER_LAUNCH_PID=$!
if ! kill -0 "$SERVER_LAUNCH_PID" 2>/dev/null; then
echo "❌ Failed to start server with Proton."
exit 1
fi
# Wait a bit for the process to start
sleep 5
# Capture all real process PIDs (children of Proton)
SERVER_PIDS=$(pgrep -u "$USER" -f "$SERVER_EXE")
# Check if PID was successfully captured
if [[ -n "$SERVER_PIDS" ]]; then
echo "✅ Server started with PIDs: $SERVER_PIDS"
else
echo "❌ Could not capture the server PID."
fi
# ===== TIME UNTIL NEXT RESTART =====
# Get current hour and minute
nowHour=$((10#$(date +%H)))
nowMin=$((10#$(date +%M)))
echo "Current time: $nowHour:$nowMin"
# Convert current time to minutes since midnight
totalNowMins=$((nowHour * 60 + nowMin))
echo "Minutes since midnight: $totalNowMins"
# Restart interval (every 6 hours = 360 minutes)
interval=360
# Calculate next restart time in minutes since midnight
nextRestart=$(( (totalNowMins / interval + 1) * interval ))
# Adjust for end of day (1440 minutes)
if [ "$nextRestart" -ge 1440 ]; then
nextRestart=1440
echo "Adjusting to midnight restart: $nextRestart"
fi
# Calculate remaining minutes until next restart
waitMins=$((nextRestart - totalNowMins))
echo "Remaining minutes: $waitMins"
# Convert to seconds
waitSecs=$((waitMins * 60))
echo "Next restart in $waitMins minutes ($waitSecs seconds)."
# Wait until next restart
sleep "$waitSecs"
# Shutdown processes (adjust based on real process name)
echo "Shutting down server..."
if [[ -n "$SERVER_PIDS" ]]; then
echo "🛑 Shutting down the following PIDs: $SERVER_PIDS"
kill $SERVER_PIDS
sleep 2
for pid in $SERVER_PIDS; do
if ps -p "$pid" > /dev/null; then
kill -9 "$pid"
fi
done
else
echo "⚠️ No server process found to terminate."
fi
echo "$(date +%T) Server restarting..."
# Wait 10 seconds before restarting
sleep 10
# ===== Restart =====
exec "$SCRIPT_DIR/start_server.sh"