rcsm

package
v0.0.0-...-5c84f98 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2023 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Version is the current version of rcsm
	Version string = "1.1.4"
	// EnvFile is the path to the .env file config
	EnvFile string = ".env"

	// InstanceName is used for event reporting on Redis and Webhooks, useful if you have multiple rcsm instances
	InstanceName string = "server"

	// RedisEnabled specifies if Redis communication should be enabled
	RedisEnabled bool = false
	// RedisHost specifies the Redis server to use
	RedisHost string = "localhost:6379"
	// RedisPassword is the plaintext password of the server
	RedisPassword string = ""
	// RedisDatabase is the database ID used for Redis
	RedisDatabase int64 = 0
	// RedisPubSubChannel is the channel used for Redis pub/sub notifications
	RedisPubSubChannel string = "rcsm"

	// S3Enabled specifies wether or not S3 is enabled to update the server from templates
	S3Enabled bool = false
	// S3Endpoint specifies the S3 endpoint if you use something else than AWS
	S3Endpoint string = ""
	// S3Region specifies the region to use for the S3 bucket
	S3Region string = ""
	// S3Bucket specifies the bucket name for server templates
	S3Bucket string = ""
	// AWSAccessKeyID is the key ID for S3 authentication
	AWSAccessKeyID string = ""
	// AWSSecretAccessKey is the secret key for S3 authentication
	AWSSecretAccessKey string = ""

	// S3BackupEnabled specifies wether or not S3 is enabled to backup the files
	S3BackupEnabled bool = false
	// S3BackupEndpoint specifies the S3 endpoint if you use something else than AWS
	S3BackupEndpoint string = ""
	// S3BackupRegion specifies the region to use for the S3 bucket
	S3BackupRegion string = ""
	// S3BackupBucket specifies the bucket name for server templates
	S3BackupBucket string = ""
	// AWSBackupAccessKeyID is the key ID for S3 authentication
	AWSBackupAccessKeyID string = ""
	// AWSBackupSecretAccessKey is the secret key for S3 authentication
	AWSBackupSecretAccessKey string = ""

	// MinecraftServersDirectory is the directory where server directories are stored
	MinecraftServersDirectory string = "/opt/minecraft"
	// MinecraftServersToCreate is the servers you want to deploy if a template exists on S3
	MinecraftServersToCreate string = ""
	// MinecraftTmuxSessionPrefix is the prefix to use for tmux session names
	MinecraftTmuxSessionPrefix string = "rcsm_"

	// AutoStartOnBoot specifies if Minecraft servers should start when rcsm starts
	AutoStartOnBoot bool = true
	// AutoStopOnClose specifies if Minecraft servers should stopped when rcsm closes
	AutoStopOnClose bool = false
	// AutoRestartCrashEnabled specifies if rcsm should attempt to restart servers on crash
	AutoRestartCrashEnabled bool = true
	// AutoRestartCrashMaxTries specifies how many tries rcsm should attempt to get a server running for more than 5 minutes
	AutoRestartCrashMaxTries int64 = 3
	// AutoRestartCrashTimeoutSec specifies for how long rcsm will wait to kill the server if not responding
	AutoRestartCrashTimeoutSec int64 = 60

	// WebhooksEnabled specifies if Webhooks (using Discord format) are enabled for alerts
	WebhooksEnabled bool = false
	// WebhooksEndpoint is the endpoint to use to send notifications to
	WebhooksEndpoint string = ""

	// AutoUpdateEnabled specifies if the auto update system should check for new versions of rcsm and install them
	AutoUpdateEnabled bool = true
	// AutoUpdateIntervalMinutes specifies how often updates should be checked
	AutoUpdateIntervalMinutes int64 = 60
	// AutoUpdateRepo specifies where to download updates for the last rcsm release
	AutoUpdateRepo string = "redcraft-org/redcraft_server_management"
	// ExitOnAutoUpdate specifies if rcsm should quit itself once updated. This is very useful when wrapped with systemd
	ExitOnAutoUpdate bool = false
)
View Source
var RedisAvailable bool

RedisAvailable is used to know if redis is ready to receive messages

View Source
var RedisClient *redis.Client

RedisClient is the client instance

Functions

func BackupAllServers

func BackupAllServers()

BackupAllServers backups all servers

func BackupServer

func BackupServer(serverName string)

BackupServer backups a server with a specified name

func BackupServerS3

func BackupServerS3(serverName string, directoriesToBackup []string)

BackupServerS3 creates a backup of the server and uploads it to S3

func CreateMissingServers

func CreateMissingServers()

CreateMissingServers creates missing servers from MINECRAFT_SERVERS_TO_CREATE

func DiscoverServers

func DiscoverServers()

DiscoverServers does a scan to know which servers exists

func ListenForRedisCommands

func ListenForRedisCommands()

ListenForRedisCommands initializes the listener to listen for redis commands

func ReadConfig

func ReadConfig()

ReadConfig reads the config from the env file

func ReadEnvBool

func ReadEnvBool(envName string, defaultValue bool) bool

ReadEnvBool reads a boolean from the env variables

func ReadEnvInt

func ReadEnvInt(envName string, defaultValue int64) int64

ReadEnvInt reads an integer from the env variables

func ReadEnvString

func ReadEnvString(envName string, defaultValue string) string

ReadEnvString reads a string from the env variables

func RedisConnect

func RedisConnect()

RedisConnect actually RedisConnects the redis client if enabled

func RestartAllServers

func RestartAllServers()

RestartAllServers starts all servers

func RestartServer

func RestartServer(serverName string)

RestartServer restarts a server with a specified name

func RunCommandAllServers

func RunCommandAllServers(command string)

RunCommandAllServers restarts a server with a specified name

func RunCommandServer

func RunCommandServer(serverName string, command string)

RunCommandServer restarts a server with a specified name

func SendDiscordWebhook

func SendDiscordWebhook(level string, service string, message string) error

SendDiscordWebhook sends a webhook request to Discord

func SendRedisEvent

func SendRedisEvent(level string, service string, message string) error

SendRedisEvent sends an event on Redis

func ServerExists

func ServerExists(serverName string) bool

ServerExists returns wether a server exists or not

func SessionCreate

func SessionCreate(serverName string, fullPath string, startCommand string) (string, error)

SessionCreate is used to create a tmux session and start a command

func SessionExists

func SessionExists(serverName string) bool

SessionExists is used to check if a session exists

func SessionRunCommand

func SessionRunCommand(serverName string, command string) error

SessionRunCommand is used to run a command on a session

func SessionTerminate

func SessionTerminate(serverName string, stopCommand string, instantKill bool) error

SessionTerminate is used to terminate a session with an optional instant kill

func StartAllServers

func StartAllServers()

StartAllServers starts all servers

func StartHealthCheck

func StartHealthCheck()

StartHealthCheck starts a task to check that servers are still running

func StartServer

func StartServer(serverName string)

StartServer starts a server with a specified name

func StartUpdateChecks

func StartUpdateChecks()

StartUpdateChecks starts a task to check for updates

func StopAllServers

func StopAllServers()

StopAllServers stops all servers

func StopServer

func StopServer(serverName string)

StopServer stops a server with a specified name

func TriggerLogEvent

func TriggerLogEvent(level string, service string, message string)

TriggerLogEvent is the method used to log messages so they can be broadcasted on Redis and Webhooks

func UpdateTemplate

func UpdateTemplate(serverName string)

UpdateTemplate downloads the most recent template from S3 and tries to update server files

func WaitForSessionState

func WaitForSessionState(serverName string, wantedState bool, timeout time.Duration) error

WaitForSessionState is used to wait for a wanted session state, such as wait for the server to shutdown

Types

type ChannelListener

type ChannelListener struct {
	PubSub   *redis.PubSub
	Channel  string
	Callback callbackFunc
}

ChannelListener defines a channel listener with its callback

func StartRedisListener

func StartRedisListener(channel string, callback callbackFunc) (*ChannelListener, error)

StartRedisListener starts a listener and returns a ChannelListener instance

type DiscordEmbed

type DiscordEmbed struct {
	Color  int            `json:"color"`
	Fields []DiscordField `json:"fields"`
}

DiscordEmbed defines the format of a Discord embed message

type DiscordErrorMessage

type DiscordErrorMessage struct {
	Global     bool   `json:"global"`
	Message    string `json:"message"`
	RetryAfter int    `json:"retry_after"`
}

DiscordErrorMessage defines the format of a webhook request

type DiscordField

type DiscordField struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Inline bool   `json:"inline"`
}

DiscordField defines the format of an embed field

type DiscordWebhookRequest

type DiscordWebhookRequest struct {
	Content string         `json:"content"`
	Embeds  []DiscordEmbed `json:"embeds"`
}

DiscordWebhookRequest defines the format of a webhook request

type MinecraftServer

type MinecraftServer struct {
	StartCommand        string   `json:"start_command"`
	StopCommand         string   `json:"stop_command"`
	DirectoriesToBackup []string `json:"directories_to_backup"`
	// contains filtered or unexported fields
}

MinecraftServer defines the stats about a server

type RedisCommand

type RedisCommand struct {
	Target  string `json:"target"`
	Action  string `json:"action"`
	Content string `json:"content"`
}

RedisCommand defines the format of a redis command

type RedisMessage

type RedisMessage struct {
	Level    string `json:"level"`
	Instance string `json:"instance"`
	Service  string `json:"service"`
	Message  string `json:"message"`
}

RedisMessage defines the structure of the messages we send on Redis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL