Documentation
¶
Index ¶
- Variables
- func BackupAllServers()
- func BackupServer(serverName string)
- func BackupServerS3(serverName string, directoriesToBackup []string)
- func CreateMissingServers()
- func DiscoverServers()
- func ListenForRedisCommands()
- func ReadConfig()
- func ReadEnvBool(envName string, defaultValue bool) bool
- func ReadEnvInt(envName string, defaultValue int64) int64
- func ReadEnvString(envName string, defaultValue string) string
- func RedisConnect()
- func RestartAllServers()
- func RestartServer(serverName string)
- func RunCommandAllServers(command string)
- func RunCommandServer(serverName string, command string)
- func SendDiscordWebhook(level string, service string, message string) error
- func SendRedisEvent(level string, service string, message string) error
- func ServerExists(serverName string) bool
- func SessionCreate(serverName string, fullPath string, startCommand string) (string, error)
- func SessionExists(serverName string) bool
- func SessionRunCommand(serverName string, command string) error
- func SessionTerminate(serverName string, stopCommand string, instantKill bool) error
- func StartAllServers()
- func StartHealthCheck()
- func StartServer(serverName string)
- func StartUpdateChecks()
- func StopAllServers()
- func StopServer(serverName string)
- func TriggerLogEvent(level string, service string, message string)
- func UpdateTemplate(serverName string)
- func WaitForSessionState(serverName string, wantedState bool, timeout time.Duration) error
- type ChannelListener
- type DiscordEmbed
- type DiscordErrorMessage
- type DiscordField
- type DiscordWebhookRequest
- type MinecraftServer
- type RedisCommand
- type RedisMessage
Constants ¶
This section is empty.
Variables ¶
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 )
var RedisAvailable bool
RedisAvailable is used to know if redis is ready to receive messages
var RedisClient *redis.Client
RedisClient is the client instance
Functions ¶
func BackupServer ¶
func BackupServer(serverName string)
BackupServer backups a server with a specified name
func BackupServerS3 ¶
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 ReadEnvBool ¶
ReadEnvBool reads a boolean from the env variables
func ReadEnvInt ¶
ReadEnvInt reads an integer from the env variables
func ReadEnvString ¶
ReadEnvString reads a string from the env variables
func RedisConnect ¶
func RedisConnect()
RedisConnect actually RedisConnects the redis client if enabled
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 ¶
RunCommandServer restarts a server with a specified name
func SendDiscordWebhook ¶
SendDiscordWebhook sends a webhook request to Discord
func SendRedisEvent ¶
SendRedisEvent sends an event on Redis
func ServerExists ¶
ServerExists returns wether a server exists or not
func SessionCreate ¶
SessionCreate is used to create a tmux session and start a command
func SessionExists ¶
SessionExists is used to check if a session exists
func SessionRunCommand ¶
SessionRunCommand is used to run a command on a session
func SessionTerminate ¶
SessionTerminate is used to terminate a session with an optional instant kill
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 StopServer ¶
func StopServer(serverName string)
StopServer stops a server with a specified name
func TriggerLogEvent ¶
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
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