How to Create Auto-Restart Script for MU Server
Learn to build batch scripts and scheduled tasks to automatically restart your MU Online server after crashes or on a fixed daily schedule.
Why Automate Server Restarts
A MU Online private server runs several processes simultaneously — ConnectServer, DataServer, GameServer, and EventServer — and any one of them can crash or terminate unexpectedly due to memory leaks, database errors, or connection spikes. Without automation, the server stays offline until an administrator notices and acts manually.
This tutorial covers two complementary approaches:
- Watchdog Script: monitors processes in real time and restarts them immediately after a crash
- Task Scheduler: restarts all services at a scheduled time, such as during off-peak hours
MU Server Directory Structure
Before creating the scripts, confirm your server's directory layout:
C:\MuServer\
├── ConnectServer\
│ └── ConnectServer.exe
├── DataServer\
│ └── DataServer.exe
├── GameServer\
│ └── GameServer.exe
├── EventServer\
│ └── EventServer.exe
└── Scripts\
├── start_all.bat
├── stop_all.bat
└── watchdog.bat
Create the Scripts\ directory if it does not exist:
mkdir C:\MuServer\Scripts
Part 1 — Full Startup Script
Step 1: Create the start script
Create the file C:\MuServer\Scripts\start_all.bat:
@echo off
title ViciadosMU - Starting Server
cd /d C:\MuServer
echo [%date% %time%] Starting ConnectServer... >> C:\MuServer\Scripts\startup.log
start "ConnectServer" /D "C:\MuServer\ConnectServer\" ConnectServer.exe
timeout /t 5 /nobreak > nul
echo [%date% %time%] Starting DataServer... >> C:\MuServer\Scripts\startup.log
start "DataServer" /D "C:\MuServer\DataServer\" DataServer.exe
timeout /t 8 /nobreak > nul
echo [%date% %time%] Starting GameServer... >> C:\MuServer\Scripts\startup.log
start "GameServer" /D "C:\MuServer\GameServer\" GameServer.exe
timeout /t 10 /nobreak > nul
echo [%date% %time%] Starting EventServer... >> C:\MuServer\Scripts\startup.log
start "EventServer" /D "C:\MuServer\EventServer\" EventServer.exe
echo [%date% %time%] All processes started. >> C:\MuServer\Scripts\startup.log
timeout /t delays are critical. The DataServer must establish its SQL Server connection before the GameServer launches. Reduce the values only if the database is on the same machine and the hardware is fast enough.Step 2: Create the shutdown script
Create the file C:\MuServer\Scripts\stop_all.bat:
@echo off
title ViciadosMU - Stopping Server
echo [%date% %time%] Initiating shutdown... >> C:\MuServer\Scripts\startup.log
taskkill /F /IM EventServer.exe /T 2>nul
timeout /t 3 /nobreak > nul
taskkill /F /IM GameServer.exe /T 2>nul
timeout /t 3 /nobreak > nul
taskkill /F /IM DataServer.exe /T 2>nul
timeout /t 3 /nobreak > nul
taskkill /F /IM ConnectServer.exe /T 2>nul
echo [%date% %time%] Shutdown complete. >> C:\MuServer\Scripts\startup.log
The shutdown order is the reverse of startup: EventServer → GameServer → DataServer → ConnectServer. This avoids abrupt disconnection errors in the database.
Part 2 — Watchdog Script (Real-Time Monitoring)
The watchdog continuously checks whether each process is running and restarts any that have stopped unexpectedly.
Step 3: Create watchdog.bat
Create the file C:\MuServer\Scripts\watchdog.bat:
@echo off
title ViciadosMU - Watchdog Active
set LOGFILE=C:\MuServer\Scripts\watchdog.log
set INTERVAL=30
:LOOP
echo [%date% %time%] Checking processes... >> %LOGFILE%
:: Check ConnectServer
tasklist /FI "IMAGENAME eq ConnectServer.exe" 2>nul | find /I "ConnectServer.exe" > nul
if errorlevel 1 (
echo [%date% %time%] WARNING: ConnectServer.exe not found. Restarting... >> %LOGFILE%
start "ConnectServer" /D "C:\MuServer\ConnectServer\" ConnectServer.exe
timeout /t 5 /nobreak > nul
)
:: Check DataServer
tasklist /FI "IMAGENAME eq DataServer.exe" 2>nul | find /I "DataServer.exe" > nul
if errorlevel 1 (
echo [%date% %time%] WARNING: DataServer.exe not found. Restarting... >> %LOGFILE%
start "DataServer" /D "C:\MuServer\DataServer\" DataServer.exe
timeout /t 8 /nobreak > nul
)
:: Check GameServer
tasklist /FI "IMAGENAME eq GameServer.exe" 2>nul | find /I "GameServer.exe" > nul
if errorlevel 1 (
echo [%date% %time%] WARNING: GameServer.exe not found. Restarting... >> %LOGFILE%
start "GameServer" /D "C:\MuServer\GameServer\" GameServer.exe
timeout /t 10 /nobreak > nul
)
:: Check EventServer
tasklist /FI "IMAGENAME eq EventServer.exe" 2>nul | find /I "EventServer.exe" > nul
if errorlevel 1 (
echo [%date% %time%] WARNING: EventServer.exe not found. Restarting... >> %LOGFILE%
start "EventServer" /D "C:\MuServer\EventServer\" EventServer.exe
)
timeout /t %INTERVAL% /nobreak > nul
goto LOOP
stop_all.bat from inside the watchdog.Part 3 — Scheduled Restart via Task Scheduler
For servers that benefit from a daily scheduled restart — for example at 04:00 for memory cleanup and maintenance:
Step 4: Create the scheduled restart script
Create C:\MuServer\Scripts\scheduled_restart.bat:
@echo off
title ViciadosMU - Scheduled Restart
set LOGFILE=C:\MuServer\Scripts\scheduled.log
echo [%date% %time%] Starting scheduled restart... >> %LOGFILE%
:: Stop all processes
call C:\MuServer\Scripts\stop_all.bat
timeout /t 15 /nobreak > nul
:: Delete log files older than 7 days
forfiles /p C:\MuServer\Scripts\ /m *.log /d -7 /c "cmd /c del @path" 2>nul
:: Restart all processes
call C:\MuServer\Scripts\start_all.bat
echo [%date% %time%] Scheduled restart complete. >> %LOGFILE%
Step 5: Register tasks in the Windows Task Scheduler
Run the following commands in an elevated Command Prompt (Run as Administrator):
:: Create daily restart task at 04:00
schtasks /create /tn "MuServer_DailyRestart" /tr "C:\MuServer\Scripts\scheduled_restart.bat" /sc daily /st 04:00 /ru SYSTEM /f
:: Create watchdog startup task (runs on every system boot)
schtasks /create /tn "MuServer_Watchdog" /tr "C:\MuServer\Scripts\watchdog.bat" /sc onstart /delay 0002:00 /ru SYSTEM /f
/delay 0002:00) on the watchdog task ensures SQL Server is fully initialized before monitoring begins. Increase to 0003:00 on servers where SQL Server is installed on an HDD rather than an SSD.Step 6: Verify the created tasks
schtasks /query /tn "MuServer_DailyRestart" /fo LIST
schtasks /query /tn "MuServer_Watchdog" /fo LIST
Both tasks should show Status: Ready in the output.
Part 4 — Crash Logging in SQL Server
To maintain a restart history in the database and identify instability patterns over time:
Step 7: Create the log table
USE MuOnline
GO
CREATE TABLE T_ServerRestartLog (
LogID INT IDENTITY(1,1) PRIMARY KEY,
RestartTime DATETIME DEFAULT GETDATE(),
ProcessName NVARCHAR(50) NOT NULL,
RestartType NVARCHAR(20) NOT NULL, -- 'CRASH', 'SCHEDULED', 'MANUAL'
Notes NVARCHAR(255) NULL
)
GO
CREATE INDEX IX_ServerRestartLog_Time
ON T_ServerRestartLog (RestartTime DESC)
GO
Step 8: Integrate sqlcmd into the watchdog
Inside each restart block in watchdog.bat, add a sqlcmd call immediately after the start command:
:: GameServer block as example:
if errorlevel 1 (
echo [%date% %time%] WARNING: GameServer.exe not found. Restarting... >> %LOGFILE%
start "GameServer" /D "C:\MuServer\GameServer\" GameServer.exe
sqlcmd -S localhost -d MuOnline -E -Q "INSERT INTO T_ServerRestartLog (ProcessName, RestartType) VALUES ('GameServer', 'CRASH')"
timeout /t 10 /nobreak > nul
)
-E for Windows Integrated Authentication, or replace with -U sa -P YourPassword for SQL Server Authentication. In production, store credentials in Windows environment variables rather than in plain text inside .bat files.To query the crash history for the last 24 hours:
SELECT ProcessName, RestartType, RestartTime
FROM MuOnline..T_ServerRestartLog
WHERE RestartTime >= DATEADD(HOUR, -24, GETDATE())
ORDER BY RestartTime DESC
Troubleshooting
Process restarts but closes immediately: Check the executable's own error log. GameServer.exe writes to C:\MuServer\GameServer\Log\. Database connection failures are the most common cause — verify the connection string in C:\MuServer\GameServer\Data\GameServerInfo.ini, specifically ServerAddress, ServerPort, and DbName.
Watchdog does not detect that the process has stopped: Confirm the exact executable name with tasklist | findstr /I "server". Some builds use different names such as MuGameServer.exe or gs.exe. Update the script to match what you find.
Task Scheduler does not run the script: The SYSTEM account needs read and write access to C:\MuServer\. Fix the permissions with:
icacls C:\MuServer /grant "NT AUTHORITY\SYSTEM:(OI)(CI)F" /T
Watchdog log file grows indefinitely: Use daily log rotation by embedding the date in the filename:
set LOGFILE=C:\MuServer\Scripts\watchdog_%date:~6,4%%date:~3,2%%date:~0,2%.log
GameServer fails to connect to the database after an automatic restart: SQL Server may not have finished starting. Increase the boot delay from 0002:00 to 0005:00 and add a service check before launching the MU processes:
:WAIT_SQL
sc query MSSQLSERVER | find "RUNNING" > nul
if errorlevel 1 (
timeout /t 10 /nobreak > nul
goto WAIT_SQL
)
call C:\MuServer\Scripts\start_all.bat
Perguntas frequentes
Can the script restart only one specific component, such as the GameServer?
Yes. Create a separate .bat file for each process and point the watchdog monitoring at only the desired executable, such as GameServer.exe. Each component can have its own independent watchdog loop.
How do I prevent the script from restarting the server during an active Castle Siege?
Add a SQL check before the restart: SELECT SiegeState FROM MuOnline..T_CastleSiegeState. If it returns 1, the script waits and checks again in 5 minutes using timeout /t 300 before proceeding.
Is the Windows Task Scheduler reliable enough to keep the server up 24/7?
For production environments, combine the Task Scheduler with a continuously looping watchdog script. The Task Scheduler alone only restarts at fixed times and cannot detect crashes in real time.
What is the recommended minimum interval between watchdog checks?
30 seconds is the practical minimum. Shorter intervals waste CPU for no benefit. For high-traffic servers, use 60 seconds and pair it with e-mail alerts via blat.exe or a similar tool.