feat: add automation features (auto-update, auto-start, scheduled updates)

This commit is contained in:
MrFastwind
2026-07-06 16:10:17 +02:00
parent b853aead8c
commit 149a60c6fb
12 changed files with 325 additions and 30 deletions

View File

@@ -50,6 +50,61 @@ All paths are configurable via environment variables:
| `FRONTEND_DIR` | `../frontend/dist` | Built frontend assets | | `FRONTEND_DIR` | `../frontend/dist` | Built frontend assets |
| `LISTEN` | `:8080` | HTTP listen address | | `LISTEN` | `:8080` | HTTP listen address |
## Automation
The panel can perform automatic operations at startup and on a schedule.
### Startup tasks
Configured in the **Automation** section of the Settings UI:
| Setting | Description |
|---------|-------------|
| **Auto-update server on startup** | Runs `steamcmd +app_update` for the Arma 3 server binary when the web service starts. |
| **Auto-update mods on startup** | Downloads workshop updates for every enabled mod in the active modlist when the web service starts. |
| **Auto-start server on startup** | Restarts the game server if it was running when the web service last stopped. Useful for recovery after host backup cycles or container restarts. |
All startup tasks run asynchronously — the web UI is available immediately.
### Scheduled updates
Set a **cron expression** in the `Scheduled Update` field to run game + mod updates on a recurring schedule (e.g. `"0 4 * * *"` for daily at 4 AM). Leave empty to disable.
The scheduled update runs even if the game server is currently running.
## SteamCMD Authentication
The panel integrates with SteamCMD for server binary updates and workshop mod downloads.
### Anonymous (default)
The `Steam User` field in the settings UI defaults to `anonymous`.
In this mode, **no Steam account is required** — SteamCMD uses `+login anonymous`.
- Workshop mod downloads always use this mode, regardless of the configured user.
- The Arma 3 server binary update is available via `+login anonymous` only if the server files are publicly accessible on that Steam account.
### Authenticated login
To update the Arma 3 server binary (`app_update 233780`) with a real Steam account, set the `Steam User` field to your account name.
The web panel does not pass a password — SteamCMD relies on a **cached session**.
You must authenticate manually once so the login token is persisted:
```bash
# Docker
docker exec -it arma3-web steamcmd +login your_steam_username
```
Enter your password when prompted, including any Steam Guard code if enabled. The session is cached inside the container's filesystem (`~/.steam/`).
> **Note:** SteamCMD sessions may expire. Re-run the login command if the "Update Server" button fails with an authentication error.
### Security
- Steam credentials saved in `data/settings.json` are stored as **plain text**.
- It is recommended to use a **dedicated Steam account** with only the necessary game licenses for automated server management.
## API ## API
REST API at `/api/*` and WebSocket endpoints at `/ws/*`. Key routes: REST API at `/api/*` and WebSocket endpoints at `/ws/*`. Key routes:

View File

@@ -50,6 +50,7 @@ func main() {
modlistMgr := services.NewModlistManager(dataDir) modlistMgr := services.NewModlistManager(dataDir)
process := services.NewProcessManager(serverfileDir, modsDir, cfgDir, profilesDir, settings, modlistMgr, configMgr, streamer) process := services.NewProcessManager(serverfileDir, modsDir, cfgDir, profilesDir, settings, modlistMgr, configMgr, streamer)
steamcmd := services.NewSteamCmdManager(serverfileDir, streamer) steamcmd := services.NewSteamCmdManager(serverfileDir, streamer)
scheduler := services.NewScheduler(settings, modlistMgr, steamcmd)
r := gin.Default() r := gin.Default()
@@ -62,9 +63,58 @@ func main() {
log.Printf("serving frontend from %s", frontendDir) log.Printf("serving frontend from %s", frontendDir)
} }
handler := api.New(settings, configMgr, modlistMgr, process, steamcmd, streamer, serverfileDir, modsDir, cfgDir, profilesDir) handler := api.New(settings, configMgr, modlistMgr, process, steamcmd, scheduler, streamer, serverfileDir, modsDir, cfgDir, profilesDir)
handler.SetupRoutes(r) handler.SetupRoutes(r)
// Startup auto-tasks
s, err := settings.Load()
if err != nil {
log.Printf("startup: load settings: %v", err)
} else {
if s.AutoUpdateOnStartup && s.SteamUser != "" {
go func() {
log.Print("startup: auto-updating gameserver")
if err := steamcmd.UpdateGame(s.SteamBranch, s.SteamUser); err != nil {
log.Printf("startup: auto-update game failed: %v", err)
}
}()
}
if s.AutoUpdateModsOnStartup && s.ActiveModlist != "" {
go func() {
log.Print("startup: auto-updating mods")
ml, err := modlistMgr.Get(s.ActiveModlist)
if err != nil {
log.Printf("startup: load modlist for auto-update: %v", err)
return
}
var modIDs []string
for _, m := range ml.Mods {
if m.Enabled {
modIDs = append(modIDs, m.ID)
}
}
if len(modIDs) > 0 {
if err := steamcmd.DownloadMods(modIDs); err != nil {
log.Printf("startup: auto-update mods failed: %v", err)
}
}
}()
}
if s.AutoStartOnStartup && s.WasRunning {
go func() {
log.Print("startup: auto-restarting server (was running before)")
if err := process.Start(); err != nil {
log.Printf("startup: auto-start failed: %v", err)
}
}()
}
}
// Start the scheduled updater
scheduler.Start()
log.Printf("starting server on %s", listen) log.Printf("starting server on %s", listen)
srv := &http.Server{Addr: listen, Handler: r} srv := &http.Server{Addr: listen, Handler: r}
@@ -80,6 +130,7 @@ func main() {
<-quit <-quit
log.Print("shutting down server...") log.Print("shutting down server...")
scheduler.Stop()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel() defer cancel()

View File

@@ -33,6 +33,7 @@ require (
github.com/quic-go/qpack v0.6.0 // indirect github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.59.0 // indirect github.com/quic-go/quic-go v0.59.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.1 // indirect github.com/ugorji/go/codec v1.3.1 // indirect
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect

View File

@@ -65,6 +65,8 @@ github.com/quic-go/quic-go v0.59.0 h1:OLJkp1Mlm/aS7dpKgTc6cnpynnD2Xg7C1pwL6vy/SA
github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU= github.com/quic-go/quic-go v0.59.0/go.mod h1:upnsH4Ju1YkqpLXC305eW3yDZ4NfnNbmQRCMWS58IKU=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=

View File

@@ -12,6 +12,7 @@ type Handler struct {
modlists *services.ModlistManager modlists *services.ModlistManager
process *services.ProcessManager process *services.ProcessManager
steamcmd *services.SteamCmdManager steamcmd *services.SteamCmdManager
scheduler *services.Scheduler
streamer *services.LogStreamer streamer *services.LogStreamer
serverfileDir string serverfileDir string
modsDir string modsDir string
@@ -25,6 +26,7 @@ func New(
modlists *services.ModlistManager, modlists *services.ModlistManager,
process *services.ProcessManager, process *services.ProcessManager,
steamcmd *services.SteamCmdManager, steamcmd *services.SteamCmdManager,
scheduler *services.Scheduler,
streamer *services.LogStreamer, streamer *services.LogStreamer,
serverfileDir, modsDir, cfgDir, profilesDir string, serverfileDir, modsDir, cfgDir, profilesDir string,
) *Handler { ) *Handler {
@@ -34,6 +36,7 @@ func New(
modlists: modlists, modlists: modlists,
process: process, process: process,
steamcmd: steamcmd, steamcmd: steamcmd,
scheduler: scheduler,
streamer: streamer, streamer: streamer,
serverfileDir: serverfileDir, serverfileDir: serverfileDir,
modsDir: modsDir, modsDir: modsDir,

View File

@@ -7,16 +7,20 @@ import (
) )
type updateSettingsInput struct { type updateSettingsInput struct {
IPPort *string `json:"ip_port"` IPPort *string `json:"ip_port"`
ServerParameters *string `json:"server_parameters"` ServerParameters *string `json:"server_parameters"`
SteamBranch *string `json:"steam_branch"` SteamBranch *string `json:"steam_branch"`
SteamUser *string `json:"steam_user"` SteamUser *string `json:"steam_user"`
Platform *string `json:"platform"` Platform *string `json:"platform"`
CBASettings *string `json:"cba_settings"` CBASettings *string `json:"cba_settings"`
AILevelPresets *string `json:"ai_level_presets"` AILevelPresets *string `json:"ai_level_presets"`
DifficultyPresets *string `json:"difficulty_presets"` DifficultyPresets *string `json:"difficulty_presets"`
ActiveConfig *string `json:"active_config"` ActiveConfig *string `json:"active_config"`
ActiveModlist *string `json:"active_modlist"` ActiveModlist *string `json:"active_modlist"`
AutoUpdateOnStartup *bool `json:"auto_update_on_startup"`
AutoStartOnStartup *bool `json:"auto_start_on_startup"`
AutoUpdateModsOnStartup *bool `json:"auto_update_mods_on_startup"`
ScheduledUpdate *string `json:"scheduled_update"`
} }
func (h *Handler) GetSettings(c *gin.Context) { func (h *Handler) GetSettings(c *gin.Context) {
@@ -51,6 +55,10 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
if input.DifficultyPresets != nil { s.DifficultyPresets = *input.DifficultyPresets } if input.DifficultyPresets != nil { s.DifficultyPresets = *input.DifficultyPresets }
if input.ActiveConfig != nil { s.ActiveConfig = *input.ActiveConfig } if input.ActiveConfig != nil { s.ActiveConfig = *input.ActiveConfig }
if input.ActiveModlist != nil { s.ActiveModlist = *input.ActiveModlist } if input.ActiveModlist != nil { s.ActiveModlist = *input.ActiveModlist }
if input.AutoUpdateOnStartup != nil { s.AutoUpdateOnStartup = *input.AutoUpdateOnStartup }
if input.AutoStartOnStartup != nil { s.AutoStartOnStartup = *input.AutoStartOnStartup }
if input.AutoUpdateModsOnStartup != nil { s.AutoUpdateModsOnStartup = *input.AutoUpdateModsOnStartup }
if input.ScheduledUpdate != nil { s.ScheduledUpdate = *input.ScheduledUpdate }
if err := h.process.WriteUserconfigFiles(s); err != nil { if err := h.process.WriteUserconfigFiles(s); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "write userconfig: " + err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": "write userconfig: " + err.Error()})
@@ -61,6 +69,11 @@ func (h *Handler) UpdateSettings(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return return
} }
if h.scheduler != nil {
h.scheduler.Refresh()
}
c.JSON(http.StatusOK, s) c.JSON(http.StatusOK, s)
} }

View File

@@ -3,15 +3,20 @@ package models
import "time" import "time"
type ServerSettings struct { type ServerSettings struct {
IPPort string `json:"ip_port"` IPPort string `json:"ip_port"`
ServerParameters string `json:"server_parameters"` ServerParameters string `json:"server_parameters"`
SteamBranch string `json:"steam_branch"` SteamBranch string `json:"steam_branch"`
SteamUser string `json:"steam_user"` SteamUser string `json:"steam_user"`
Platform string `json:"platform"` Platform string `json:"platform"`
CBASettings string `json:"cba_settings"` CBASettings string `json:"cba_settings"`
AILevelPresets string `json:"ai_level_presets"` AILevelPresets string `json:"ai_level_presets"`
DifficultyPresets string `json:"difficulty_presets"` DifficultyPresets string `json:"difficulty_presets"`
ActiveConfig string `json:"active_config"` ActiveConfig string `json:"active_config"`
ActiveModlist string `json:"active_modlist"` ActiveModlist string `json:"active_modlist"`
UpdatedAt time.Time `json:"updated_at"` AutoUpdateOnStartup bool `json:"auto_update_on_startup"`
AutoStartOnStartup bool `json:"auto_start_on_startup"`
AutoUpdateModsOnStartup bool `json:"auto_update_mods_on_startup"`
WasRunning bool `json:"was_running"`
ScheduledUpdate string `json:"scheduled_update"`
UpdatedAt time.Time `json:"updated_at"`
} }

View File

@@ -0,0 +1,92 @@
package services
import (
"log"
"sync"
"github.com/robfig/cron/v3"
)
type Scheduler struct {
cron *cron.Cron
entryID cron.EntryID
settings *SettingsManager
modlists *ModlistManager
steamcmd *SteamCmdManager
mu sync.Mutex
}
func NewScheduler(settings *SettingsManager, modlists *ModlistManager, steamcmd *SteamCmdManager) *Scheduler {
return &Scheduler{
cron: cron.New(),
settings: settings,
modlists: modlists,
steamcmd: steamcmd,
}
}
func (s *Scheduler) Start() {
s.cron.Start()
s.Refresh()
}
func (s *Scheduler) Stop() {
s.cron.Stop()
}
func (s *Scheduler) Refresh() {
s.mu.Lock()
defer s.mu.Unlock()
if s.entryID != 0 {
s.cron.Remove(s.entryID)
s.entryID = 0
}
sett, err := s.settings.Load()
if err != nil || sett.ScheduledUpdate == "" {
return
}
id, err := s.cron.AddFunc(sett.ScheduledUpdate, s.runScheduledUpdate)
if err != nil {
log.Printf("scheduler: invalid cron expression %q: %v", sett.ScheduledUpdate, err)
return
}
s.entryID = id
log.Printf("scheduler: scheduled update with cron %q", sett.ScheduledUpdate)
}
func (s *Scheduler) runScheduledUpdate() {
sett, err := s.settings.Load()
if err != nil {
return
}
if sett.SteamUser != "" && sett.SteamUser != "anonymous" {
log.Print("scheduler: running gameserver update")
if err := s.steamcmd.UpdateGame(sett.SteamBranch, sett.SteamUser); err != nil {
log.Printf("scheduler: game update failed: %v", err)
}
}
if sett.ActiveModlist != "" {
ml, err := s.modlists.Get(sett.ActiveModlist)
if err != nil {
log.Printf("scheduler: load modlist %s: %v", sett.ActiveModlist, err)
return
}
var modIDs []string
for _, m := range ml.Mods {
if m.Enabled {
modIDs = append(modIDs, m.ID)
}
}
if len(modIDs) > 0 {
log.Printf("scheduler: updating %d mod(s)", len(modIDs))
if err := s.steamcmd.DownloadMods(modIDs); err != nil {
log.Printf("scheduler: mod update failed: %v", err)
}
}
}
}

View File

@@ -72,6 +72,11 @@ func (pm *ProcessManager) Start() error {
return fmt.Errorf("load settings: %w", err) return fmt.Errorf("load settings: %w", err)
} }
s.WasRunning = true
if err := pm.settings.Save(s); err != nil {
return fmt.Errorf("save was_running: %w", err)
}
binName := "arma3server_x64" binName := "arma3server_x64"
if s.Platform == "windows" { if s.Platform == "windows" {
binName = "arma3server_x64.exe" binName = "arma3server_x64.exe"
@@ -141,6 +146,13 @@ func (pm *ProcessManager) Stop() error {
rp.cancel() rp.cancel()
<-rp.exited <-rp.exited
s, err := pm.settings.Load()
if err == nil {
s.WasRunning = false
pm.settings.Save(s)
}
return nil return nil
} }

View File

@@ -54,13 +54,18 @@ func (sm *SettingsManager) Save(s *models.ServerSettings) error {
func (sm *SettingsManager) defaults() *models.ServerSettings { func (sm *SettingsManager) defaults() *models.ServerSettings {
return &models.ServerSettings{ return &models.ServerSettings{
IPPort: "0.0.0.0:2302", IPPort: "0.0.0.0:2302",
ServerParameters: "-server -world=empty -loadMissionToMemory -noPause", ServerParameters: "-server -world=empty -loadMissionToMemory -noPause",
SteamBranch: "stable", SteamBranch: "stable",
SteamUser: "anonymous", SteamUser: "anonymous",
Platform: "linux", Platform: "linux",
ActiveConfig: "", ActiveConfig: "",
ActiveModlist: "", ActiveModlist: "",
UpdatedAt: time.Now().UTC(), AutoUpdateOnStartup: false,
AutoStartOnStartup: false,
AutoUpdateModsOnStartup: false,
WasRunning: false,
ScheduledUpdate: "",
UpdatedAt: time.Now().UTC(),
} }
} }

View File

@@ -26,6 +26,10 @@ export default function Settings() {
const [difficulty, setDifficulty] = useState('') const [difficulty, setDifficulty] = useState('')
const [activeConfig, setActiveConfig] = useState('') const [activeConfig, setActiveConfig] = useState('')
const [activeModlist, setActiveModlist] = useState('') const [activeModlist, setActiveModlist] = useState('')
const [autoUpdateOnStartup, setAutoUpdateOnStartup] = useState(false)
const [autoStartOnStartup, setAutoStartOnStartup] = useState(false)
const [autoUpdateModsOnStartup, setAutoUpdateModsOnStartup] = useState(false)
const [scheduledUpdate, setScheduledUpdate] = useState('')
useEffect(() => { useEffect(() => {
if (settings) { if (settings) {
@@ -39,6 +43,10 @@ export default function Settings() {
setDifficulty(settings.difficulty_presets) setDifficulty(settings.difficulty_presets)
setActiveConfig(settings.active_config) setActiveConfig(settings.active_config)
setActiveModlist(settings.active_modlist) setActiveModlist(settings.active_modlist)
setAutoUpdateOnStartup(settings.auto_update_on_startup)
setAutoStartOnStartup(settings.auto_start_on_startup)
setAutoUpdateModsOnStartup(settings.auto_update_mods_on_startup)
setScheduledUpdate(settings.scheduled_update)
} }
}, [settings]) }, [settings])
@@ -54,6 +62,10 @@ export default function Settings() {
difficulty_presets: difficulty, difficulty_presets: difficulty,
active_config: activeConfig, active_config: activeConfig,
active_modlist: activeModlist, active_modlist: activeModlist,
auto_update_on_startup: autoUpdateOnStartup,
auto_start_on_startup: autoStartOnStartup,
auto_update_mods_on_startup: autoUpdateModsOnStartup,
scheduled_update: scheduledUpdate,
}), }),
onSuccess: () => { qc.invalidateQueries({ queryKey: ['settings'] }); setDirty(false) }, onSuccess: () => { qc.invalidateQueries({ queryKey: ['settings'] }); setDirty(false) },
}) })
@@ -220,6 +232,45 @@ export default function Settings() {
</span> </span>
</div> </div>
<hr className="border-neutral-800 my-6" />
<div>
<h3 className="text-lg font-medium mb-3">Automation</h3>
<div className="space-y-3">
<label className="flex items-center gap-3 cursor-pointer">
<input type="checkbox" checked={autoUpdateOnStartup} onChange={e => { setAutoUpdateOnStartup(e.target.checked); setDirty(true) }} className="accent-amber-600 w-4 h-4" />
<div>
<div className="text-sm">Auto-update server on startup</div>
<div className="text-xs text-neutral-500">Run gameserver update when the web service starts</div>
</div>
</label>
<label className="flex items-center gap-3 cursor-pointer">
<input type="checkbox" checked={autoUpdateModsOnStartup} onChange={e => { setAutoUpdateModsOnStartup(e.target.checked); setDirty(true) }} className="accent-amber-600 w-4 h-4" />
<div>
<div className="text-sm">Auto-update mods on startup</div>
<div className="text-xs text-neutral-500">Download workshop updates for the active modlist when the web service starts</div>
</div>
</label>
<label className="flex items-center gap-3 cursor-pointer">
<input type="checkbox" checked={autoStartOnStartup} onChange={e => { setAutoStartOnStartup(e.target.checked); setDirty(true) }} className="accent-amber-600 w-4 h-4" />
<div>
<div className="text-sm">Auto-start server on startup</div>
<div className="text-xs text-neutral-500">Restart the server if it was running before the web service stopped</div>
</div>
</label>
<div>
<label className="text-xs text-neutral-500 block mb-1">Scheduled update (cron)</label>
<input
value={scheduledUpdate}
onChange={e => { setScheduledUpdate(e.target.value); setDirty(true) }}
placeholder='e.g. "0 4 * * *" for daily at 4 AM'
className="w-full bg-neutral-800 border border-neutral-700 rounded px-3 py-2 text-sm font-mono"
/>
<div className="text-xs text-neutral-500 mt-1">Empty = disabled. Runs game + mod updates at the specified schedule.</div>
</div>
</div>
</div>
{showSteamCMD && ( {showSteamCMD && (
<div className="mt-4"> <div className="mt-4">
<div className="flex items-center justify-between mb-2"> <div className="flex items-center justify-between mb-2">

View File

@@ -9,6 +9,11 @@ export interface ServerSettings {
difficulty_presets: string difficulty_presets: string
active_config: string active_config: string
active_modlist: string active_modlist: string
auto_update_on_startup: boolean
auto_start_on_startup: boolean
auto_update_mods_on_startup: boolean
was_running: boolean
scheduled_update: string
updated_at: string updated_at: string
} }