Skip to content

maintc/wipe-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

16 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงน Wipe CLI

Mainloot Logo

CI Status Go Coverage GitHub Release Platform

Automated Rust game server management powered by Google Calendar schedules.

๐Ÿ“– What It Does

โš ๏ธ Note: This tool is designed for Linux servers only. Windows is not supported.

๐Ÿ’ก Tip: Pairs well with WipeCal - a Carbon plugin that uses the same calendar URL to notify players of approaching restarts/wipes and display upcoming events in-game.

Server owners can schedule restart and wipe events in Google Calendar. This tool:

  • ๐Ÿ“… Monitors multiple Google Calendar iCal feeds (one per server)
  • ๐Ÿ” Detects upcoming events within a configurable time window (default: 24 hours)
  • ๐Ÿ”„ Auto-installs and updates Rust server files (/opt/rust/{branch}) and Carbon mod (/opt/carbon/{branch})
  • โšก Executes restart/wipe operations at scheduled times via customizable shell scripts
  • ๐Ÿ“Š Aggregates events across multiple servers (e.g., restart 3 servers simultaneously)
  • ๐Ÿ“ฃ Discord webhook notifications for events, updates, and errors
  • ๐Ÿ—บ๏ธ Custom map generation workflows via generate-maps.sh

โš ๏ธ Event Priority: If a server has both a restart and wipe event at the same time, it's treated as a wipe.

๐Ÿ—๏ธ Architecture

This project consists of two main components:

  1. wipe ๐Ÿ–ฅ๏ธ - CLI tool for managing server configurations
  2. wiped ๐Ÿค– - Long-running daemon that monitors calendars and schedules tasks

The two components communicate via a shared configuration file stored at ~/.config/wiped/config.yaml.

โš™๏ธ Event Execution Flow

When a restart or wipe event occurs:

  1. ๐Ÿ›‘ Stop servers โ†’ Calls /opt/wiped/stop-servers.sh with server paths
  2. ๐Ÿ“ฆ Update Rust & Carbon โ†’ Syncs from /opt/rust/{branch} and /opt/carbon/{branch} (parallel)
  3. ๐Ÿงน Wipe data (wipes only) โ†’ Deletes map, save, and blueprint files (see below)
  4. ๐Ÿ”ง Run hook โ†’ Calls /opt/wiped/pre-start-hook.sh with all server paths
  5. โ–ถ๏ธ Start servers โ†’ Calls /opt/wiped/start-servers.sh with server paths

All scripts receive server paths as arguments, allowing you to integrate with your existing infrastructure.

Files deleted during wipes (from server/{identity}/ directory):

  • *.map - Map files
  • *.sav* - Save files
  • player.states.*.db* - Player state databases
  • sv.files.*.db* - Server file databases
  • player.blueprints.* - Blueprints (only if wipe_blueprints: true)

Project Structure

wipe-cli/
โ”œโ”€โ”€ cmd/
โ”‚   โ”œโ”€โ”€ wipe/          # CLI tool entry point
โ”‚   โ””โ”€โ”€ wiped/         # Daemon entry point
โ”œโ”€โ”€ internal/
โ”‚   โ”œโ”€โ”€ calendar/      # iCal parsing and event detection
โ”‚   โ”œโ”€โ”€ carbon/        # Carbon mod installation and updates
โ”‚   โ”œโ”€โ”€ config/        # Shared configuration management
โ”‚   โ”œโ”€โ”€ daemon/        # Daemon logic
โ”‚   โ”œโ”€โ”€ discord/       # Discord webhook notifications
โ”‚   โ”œโ”€โ”€ executor/      # Event execution and script management
โ”‚   โ”œโ”€โ”€ scheduler/     # Event scheduling and grouping
โ”‚   โ””โ”€โ”€ steamcmd/      # Rust server installation via SteamCMD
โ”œโ”€โ”€ systemd/
โ”‚   โ””โ”€โ”€ wiped.service  # systemd service file
โ”œโ”€โ”€ go.mod
โ”œโ”€โ”€ Makefile
โ””โ”€โ”€ README.md

๐Ÿ”จ Building

make build

This creates binaries in the build/ directory.

๐Ÿš€ Installation

make install

This will:

  • โœ… Install wipe and wiped binaries to /usr/local/bin/
  • โœ… Install the systemd service file
  • โœ… Reload systemd

After installation, enable and start the service:

sudo systemctl enable wiped@$USER.service
sudo systemctl start wiped@$USER.service

Note: The service uses wiped@{username}.service format - replace $USER with your actual username if needed. The daemon runs as your user and accesses your ~/.config/wiped/config.yaml.

๐Ÿ“œ Management Scripts

The daemon automatically creates default management scripts in /opt/wiped/ on first run:

  • ๐Ÿ›‘ stop-servers.sh - Called to stop servers before restart/wipe
  • โ–ถ๏ธ start-servers.sh - Called to start servers after restart/wipe
  • ๐Ÿ”ง pre-start-hook.sh - Called after updating Rust & Carbon but before server start
  • ๐Ÿ—บ๏ธ generate-maps.sh - Called by default 22 hours before wipes (if generate_map: true)

โš ๏ธ These are template scripts - you must edit them to match your infrastructure!

Example customization:

# /opt/wiped/stop-servers.sh
#!/bin/bash
SERVER_PATHS="$@"
for SERVER_PATH in $SERVER_PATHS; do
    IDENTITY=$(basename "$SERVER_PATH")
    systemctl stop "rs-${IDENTITY}"
done

You can regenerate all scripts to defaults with:

wipe reset-scripts

This will delete and regenerate all 4 management scripts.

๐Ÿ’ป Usage

๐ŸŽฏ Initial Setup

Add servers to monitor with their calendar URLs:

# Add a server (minimum required flags)
wipe add \
  --path /var/www/servers/us-weekly \
  --calendar https://calendar.google.com/calendar/ical/xxx/basic.ics

# Add a server with all options
wipe add \
  --path /var/www/servers/us-weekly \
  --calendar https://calendar.google.com/calendar/ical/xxx/basic.ics \
  --branch main \
  --wipe-blueprints \
  --generate-map

๐Ÿšฉ Flags:

  • ๐Ÿ“ --path - Full path to Rust server directory (required). Server name is derived from the basename.
  • ๐Ÿ“… --calendar - Google Calendar .ics URL (required)
  • ๐ŸŒฟ --branch - Rust branch: main, staging, etc. (default: main)
  • ๐Ÿงน --wipe-blueprints - Delete blueprints on wipe events (default: false)
  • ๐Ÿ—บ๏ธ --generate-map - Call generate-maps.sh before wipes (default: false)

๐Ÿ’ก Note: The server name is automatically set to the basename of the path. For example, /var/www/servers/us-weekly becomes us-weekly.

๐Ÿ”ง Managing Servers

# List all configured servers
wipe list

# Update server settings (accepts server name or full path)
wipe update us-weekly \
  --calendar https://new-url.com/cal.ics \
  --branch staging \
  --generate-map

# You can also use full path
wipe update /var/www/servers/us-weekly --branch main

# Remove a server (accepts server name or full path)
wipe remove us-weekly
# Or: wipe remove /var/www/servers/us-weekly

โš™๏ธ Configuration

# View current configuration
wipe config

# Set global options
wipe config set --check-interval 30           # How often to check calendars (seconds)
wipe config set --lookahead-hours 24          # How far ahead to schedule events (hours)
wipe config set --event-delay 5               # Delay after event time (seconds)
wipe config set --map-generation-hours 22     # When to generate maps before wipe (hours)
wipe config set --discord-webhook "https://..." # General notifications webhook

๐Ÿ“ข Discord Mentions

Configure user and role IDs to mention in Discord notifications:

# Add Discord users to mention (use Discord user IDs)
wipe mention add-user 123456789012345678
wipe mention add-user 987654321098765432

# Add Discord roles to mention (use Discord role IDs)
wipe mention add-role 111222333444555666
wipe mention add-role 777888999000111222

# Remove users or roles
wipe mention remove-user 123456789012345678
wipe mention remove-role 111222333444555666

# View configured mentions
wipe config

How to get Discord IDs:

  1. Enable Developer Mode in Discord (Settings โ†’ App Settings โ†’ Advanced โ†’ Developer Mode)
  2. Right-click on a user or role and select "Copy ID"

Configured mentions will be included in batch event notifications (start, complete, errors) as cc <@&ROLE_ID> <@USER_ID>.

๐Ÿ› ๏ธ Manual Operations

# Update Rust and Carbon on servers (without stopping/starting)
wipe sync us-weekly eu-monthly
wipe sync us-weekly --force  # Skip confirmation prompt

# Manually call a management script for specific servers
wipe call-script us-weekly us-long --script stop-servers
wipe call-script us-weekly --script start-servers
wipe call-script us-weekly --script generate-maps

# Reset all management scripts to defaults (includes pre-start-hook.sh)
wipe reset-scripts
wipe reset-scripts --force  # Skip confirmation prompt

๐Ÿ“Š Service Management

# Check service status
systemctl status wiped@$USER.service

# View logs
journalctl -u wiped@$USER.service -f

# Restart service
sudo systemctl restart wiped@$USER.service

# Run daemon with custom config path (for testing)
wiped -config /path/to/custom/config.yaml

๐Ÿ“œ Management Scripts

๐Ÿ”ง Pre-Start Hook

The pre-start-hook.sh runs once after all servers are synced but before they start. Use it for:

  • ๐Ÿงน Clearing caches
  • ๐Ÿ”Œ Updating plugins
  • ๐Ÿ’พ Running database migrations
  • ๐Ÿ“ข Sending custom notifications

Example:

#!/bin/bash
SERVER_PATHS="$@"

for SERVER_PATH in $SERVER_PATHS; do
    IDENTITY=$(basename "$SERVER_PATH")
    
    # Update custom configs
    /usr/local/bin/update-configs "$IDENTITY"
done

# Send notification
IDENTITIES=$(echo "$SERVER_PATHS" | xargs -n1 basename | paste -sd,)
curl -X POST "https://api.example.com/notify" -d "servers=$IDENTITIES"

๐Ÿ›‘โ–ถ๏ธ Stop/Start Servers

Customize stop-servers.sh and start-servers.sh to match your infrastructure:

#!/bin/bash
# stop-servers.sh example with systemd
SERVER_PATHS="$@"
for SERVER_PATH in $SERVER_PATHS; do
    IDENTITY=$(basename "$SERVER_PATH")
    systemctl stop "rs-${IDENTITY}"
done

๐Ÿ—บ๏ธ Map Generation

The generate-maps.sh script is called 22 hours before wipes (configurable) for servers with generate_map: true. Customize it to:

  • ๐ŸŽฒ Pick random seeds/sizes
  • ๐ŸŽจ Generate custom maps using rustmaps-cli
  • โš™๏ธ Update server.cfg files
  • ๐Ÿ”„ Handle map pool logic

The script receives server paths and should exit 0 on success.

๐Ÿ”„ Manual Sync

The wipe sync command allows you to manually update Rust and Carbon on specified servers from /opt/rust/{branch} and /opt/carbon/{branch}:

# Update one or more servers
wipe sync us-weekly
wipe sync us-weekly eu-monthly

# Skip confirmation prompt (for automation)
wipe sync us-weekly --force

โš ๏ธ Important notes:

  • โŒ This command does NOT stop or start servers
  • โŒ This command does NOT delete any files (no wipe)
  • โŒ This command does NOT run the pre-start hook
  • โš ๏ธ You should stop servers before updating to avoid issues
  • โœ… This is useful for manual updates outside of scheduled events

๐Ÿ“ Configuration File

Configuration is stored at ~/.config/wiped/config.yaml:

# How far ahead to look for events (in hours)
lookahead_hours: 24

# How often to check calendars (in seconds)
check_interval: 30

# How long to wait after event time before executing (in seconds)
event_delay: 5

# How many hours before a wipe to call generate-maps.sh
map_generation_hours: 22

# Discord webhook URL for notifications
discord_webhook: "https://discord.com/api/webhooks/..."

# Discord user IDs to mention in notifications (optional)
discord_mention_users:
  - "123456789012345678"
  - "987654321098765432"

# Discord role IDs to mention in notifications (optional)
discord_mention_roles:
  - "111222333444555666"
  - "777888999000111222"

# Servers to monitor
servers:
  - name: "us-weekly"
    path: "/var/www/servers/us-weekly"
    calendar_url: "https://calendar.google.com/calendar/ical/xxx/basic.ics"
    branch: "main"
    wipe_blueprints: false
    generate_map: true
    
  - name: "eu-staging"
    path: "/var/www/servers/eu-staging"
    calendar_url: "https://calendar.google.com/calendar/ical/yyy/basic.ics"
    branch: "staging"
    wipe_blueprints: true
    generate_map: false

๐ŸŽฏ Event Detection & Scheduling

๐Ÿ“… Calendar Events

The daemon looks for events with these summaries (case-insensitive, trimmed):

  • ๐Ÿ”„ "restart" - Server restart event
  • ๐Ÿงน "wipe" - Server wipe event

If a server has both a restart and wipe at the same time, only the wipe is executed.

๐Ÿ“Š Event Grouping

Events occurring at the same time are automatically grouped into one unified batch:

  • โšก All servers stop at once (prevents systemd from auto-restarting during updates)
  • ๐Ÿš€ All servers update in parallel (Rust + Carbon synced simultaneously)
  • ๐Ÿงน Wipe-specific cleanup only runs for servers with wipe events
  • ๐Ÿ”ง Pre-start hook runs once for all servers in the batch
  • โœ… All servers start together

Example: 2 servers restarting + 2 servers wiping at 11:00 โ†’ One batch operation

This ensures:

  • No race conditions with systemd auto-restart
  • Minimal downtime
  • Efficient parallel execution

๐Ÿ”„ Update Checking

The daemon checks for Rust and Carbon updates every 2 minutes:

  • ๐ŸŽฎ Rust: Monitors each configured branch via SteamCMD
  • ๐Ÿ”Œ Carbon: Checks GitHub releases for production/staging builds
  • ๐Ÿ“ฆ Updates are automatically installed to /opt/rust/{branch} and /opt/carbon/{branch}
  • ๐Ÿ›ก๏ธ Cascade protection prevents multiple simultaneous updates

๐Ÿ“ข Discord Notifications

The daemon sends webhook notifications for key events:

๐ŸŽฏ Event Operations:

  • Batch Event Starting - When servers begin restart/wipe operations
  • Batch Event Complete - After successful completion
  • Batch Event Failed - If any step fails during execution

๐Ÿ“… Calendar Changes:

  • Calendar Events Added - New events detected in calendars
  • Calendar Events Removed - Events deleted from calendars

๐Ÿ”„ Installation & Updates:

  • Rust Installation Complete - Initial Rust branch installation
  • Rust Update Complete - Rust branch updated to new build
  • Rust Update Available - New Rust build detected (before install)
  • Rust Installation Failed - Rust installation error
  • Carbon Installation Complete - Initial Carbon installation
  • Carbon Update Available - New Carbon version detected
  • Carbon Installation Failed - Carbon installation error

โš™๏ธ Service Management:

  • Wipe Service Started - Daemon startup notification
  • Server Added - Server added to configuration
  • Server Removed - Server removed from configuration
  • Map Generation Failed - generate-maps.sh script error

All notifications include the hostname for easy identification in multi-server environments.

๐Ÿ› ๏ธ Development

Run the CLI locally:

make run-cli

Run the daemon locally:

make run-daemon

Run code quality checks:

make check  # Runs fmt, vet, staticcheck, and deadcode

๐Ÿ—‘๏ธ Uninstallation

make uninstall

This will:

  • ๐Ÿ›‘ Stop the service
  • โŒ Remove binaries from /usr/local/bin/
  • โŒ Remove systemd service file
  • โœ… Config files in ~/.config/wiped/ and scripts in /opt/wiped/ are preserved

๐Ÿ“ฆ Dependencies

  • ๐Ÿ cobra - CLI framework
  • โš™๏ธ viper - Configuration management
  • ๐Ÿ“… golang-ical - iCalendar parsing
  • ๐Ÿ”„ rrule-go - Recurring event support
  • โฐ gocron - Job scheduling and execution

๐Ÿ“„ License

See LICENSE file.


Made with โค๏ธ by mainloot

About

Manages wipes for Rust servers

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project