Skip to main content

Example Commands

Find a few examples of commands for Linux and Windows systems below.

INFO: MacOS Support

The mod is also supported on MacOS but the commands are not provided here. The commands for MacOS are similar to the Linux commands but have to be adjusted. E.g. the systemctl command is not available on MacOS and can be replaced with the launchctl command.

warning

These commands are examples and should be used with caution. They are not meant to be used as is, but rather as a starting point for your own commands.

Linux

Restart Server

config/betterconsolemc-commands_config.properties
SIMPLE 4 0 true restart "sudo systemctl restart minecraft-server.service"

This creates a command /restart that automatically restarts a minecraft server using the systemctl utility. This requires a setup of the service file in /etc/systemd/system/

Example system service file:

/etc/systemd/system/minecraft-server.service
[Unit]
Description=Minecraft Server
After=network.target

[Service]
User=minecraft
WorkingDirectory=/home/minecraft/server
ExecStart=/usr/bin/java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
Restart=on-failure

[Install]
WantedBy=multi-user.target

Update System Packages

danger

This command is a security risk and should not be used on public servers or servers where you don't trust the operators. In Addition running a server with sudo privileges is a security risk in itself and should be avoided at all costs.

config/betterconsolemc-commands_config.properties
SIMPLE 4 0 true update "sudo apt update && sudo apt upgrade --force-yes"

This creates a command /update that automatically updates a linux system. The command is only available to operators, will, at no point, be terminated and can therefore finish with no time limit. This aproach requires the server to be ran with elevated permissions (sudo)

An Example of a system service file for a minecraft server running on linux can be found in the Restart Server section.

Launch Second Minecraft server

config/betterconsolemc-commands_config.properties
SIMPLE 1 300 true start-server "sudo systemctl start minecraft-server.service"

This creates a command /start-server that automatically starts a minecraft server using the systemctl utility. This requires a setup of the service file in /etc/systemd/system/. An example of a service file can be found in the Restart Server section.

Windows

Restart Server

config/betterconsolemc-commands_config.properties
SIMPLE 4 0 true restart "powershell.exe -Command Restart-Service -Name 'minecraft-server'"

This creates a command /restart that automatically restarts a minecraft server using the Restart-Service command in PowerShell. This requires the server to be ran with elevated permissions (Run as Administrator).

Example of a PowerShell script to create a service:

create-service.ps1
$serviceName = "minecraft-server"
$servicePath = "C:\path\to\minecraft_server.jar"
$serviceArgs = "-Xmx1024M -Xms1024M -jar minecraft_server.jar nogui"
$serviceUser
$servicePassword

New-Service -Name $serviceName -BinaryPathName "C:\path\to\java.exe $serviceArgs" -DisplayName $serviceName -StartupType Automatic

The above commands can be saved to a file create-service.ps1 and executed using the following command or executed directly in a PowerShell terminal.

powershell.exe -File create-service.ps1

Update System Packages

danger

This command is a security risk and should not be used on public servers or servers where you don't trust the operators. In Addition running a server with elevated permissions is a security risk in itself and should be avoided at all costs.

config/betterconsolemc-commands_config.properties
SIMPLE 4 0 true update "powershell.exe -Command 'Get-WindowsUpdate -Install -AcceptAll'"

Or to update applications with the winget command line tool:

config/betterconsolemc-commands_config.properties
SIMPLE 4 0 true update "winget upgrade --all"

This creates a command /update that automatically updates a windows system. The command is only available to operators, will, at no point, be terminated and can therefore finish with no time limit. This aproach requires the server to be ran with elevated permissions (Run as Administrator)

Launch Second Minecraft server

config/betterconsolemc-commands_config.properties
SIMPLE 1 300 true start-server "powershell.exe -Command Start-Service -Name 'minecraft-server'"

This creates a command /start-server that automatically starts a minecraft server using the Start-Service command in PowerShell. This requires the server to be ran with elevated permissions (Run as Administrator).

An example of a PowerShell script to create a service can be found in the Restart Server section.