> For the complete documentation index, see [llms.txt](https://conboi.gitbook.io/oms-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://conboi.gitbook.io/oms-wiki/addons/operate-my-server-addon/scheduled-restart/restart-script-setup.md).

# Restart Script Setup

Operate My Server performs controlled shutdowns and records whether the server should be started again, but it cannot relaunch the Java process by itself.\
To enable automatic restarts after scheduled or triggered stops, run your server using the provided **OMS restart script**.

This page provides working examples for both [**Windows**](#windows-script-start_oms.cmd) and [**Linux**](#linux-script-start_oms.sh) environments.

***

### Overview

Each script:

* Starts the Minecraft server process
* Waits for the process to exit
* Reads the latest stop entry from `oms/oms/common/stop_cause.json`
* Starts the server again only when `shouldRestart` is `true`

***

### How it works

OMS writes a stop entry before a controlled shutdown:

```json
{
  "reason": "oms:scheduled",
  "message": "Server stopping as scheduled",
  "shouldRestart": true,
  "time": "2026-08-11T12:00:00Z"
}
```

If no stop entry is available, the script assumes the server exited unexpectedly and starts it again.

### Setup

1. **Copy or download the script** matching your OS - [**Windows**](#windows-script-start_oms.cmd) or [**Linux**](#linux-script-start_oms.sh)
2. **Save the script file**:
   * `start_oms.cmd` for **Windows**
   * `start_oms.sh` for **Linux**
3. **Place the script in your server root directory** - alongside `run.bat`, `run.sh`, `mods/`, and the Forge files.
4. **Launch the server using the OMS restart script** instead of your normal Forge start command or standard startup script.

> `StopReason.shouldRestart` tells the restart script whether the server should be launched again after shutdown.

***

### Configuration Section

Before using the script, adjust these values:

**Windows**

```bat
set "JAVA_EXE=java"
set "JAVA_ARGS=@user_jvm_args.txt @libraries/net/minecraftforge/forge/<version>/win_args.txt"
```

**Linux**

```bash
JAVA_EXE="java"
JAVA_ARGS="@user_jvm_args.txt @libraries/net/minecraftforge/forge/<version>/unix_args.txt"
```

* `JAVA_EXE` - path to your Java executable
* `JAVA_ARGS` - JVM and Forge launch arguments used to start the server
* Replace `<version>` with your Forge version, e.g. `1.20.1-47.4.0`

***

### Windows Script (`start_oms.cmd`)

{% @github-files/github-code-block url="<https://github.com/c0nnor263/OperateMyServer/blob/main/feature/scheduled-restart/scripts/windows/start_oms.cmd>" %}

***

### Linux Script (`start_oms.sh`)

> Make sure to give execute permission:\
> `chmod +x start_oms.sh`

{% @github-files/github-code-block url="<https://github.com/c0nnor263/OperateMyServer/blob/main/feature/scheduled-restart/scripts/linux/start_oms.sh>" %}

***

### Related

* [**Scheduled Restart**](/oms-wiki/addons/operate-my-server-addon/scheduled-restart.md)
* [**Stop Reasons**](/oms-wiki/developer-guide/runtime-infrastructure/stop-reasons.md)
* [**Lifecycle Events**](/oms-wiki/developer-guide/core-architecture/events/lifecycle-events.md)
