# Restart Script Setup

OperateMyServer performs clean shutdowns but **does not restart the server automatically**.\
To enable auto-restart after scheduled or triggered stops, you need to run your server using a **looping start 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 server
* Waits for it to exit
* Reads the shutdown reason from `stop_cause.json`
* Restarts the server unless the reason was `"STOP"`

***

### Step-by-Step

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`, `mods/`, etc.
4. **Launch the server using this script** instead of running `forge.jar` or any standard `.bat/.sh` file

> These scripts will automatically restart the server unless a clean `"STOP"` was requested by OMS.

***

### 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` - full JVM/Forge arguments
* 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/operatemyserver-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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://conboi.gitbook.io/oms-wiki/addons/operatemyserver-addon/scheduled-restart/restart-script-setup.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
