Documentation ¶
Index ¶
- Constants
- Variables
- func FeedDecryptionPasswordToStdinAndStart(decryptionPassword string, cmd *exec.Cmd) error
- func RemoveFromFlags(deleteFun func(string) bool, flags []string) (ret []string)
- type AWSIntegration
- type Benchmark
- func (bench *Benchmark) BenchmarkDNSDaemon()
- func (bench *Benchmark) BenchmarkHTTPDaemon()
- func (bench *Benchmark) BenchmarkHTTPSDaemon()
- func (bench *Benchmark) BenchmarkPlainSocketDaemon()
- func (bench *Benchmark) BenchmarkSMTPDaemon()
- func (bench *Benchmark) BenchmarkSNMPDaemon()
- func (bench *Benchmark) BenchmarkSimpleIPSvcDaemon()
- func (bench *Benchmark) BenchmarkSockDaemon()
- func (bench *Benchmark) RunBenchmarkAndProfiler()
- type Config
- func (config *Config) DeserialiseFromJSON(in []byte) error
- func (config *Config) GetAutoUnlock() *autounlock.Daemon
- func (config *Config) GetDNSD() *dnsd.Daemon
- func (config *Config) GetHTTPD() *httpd.Daemon
- func (config *Config) GetHTTPProxyDaemon() *httpproxy.Daemon
- func (config *Config) GetMailCommandRunner() *mailcmd.CommandRunner
- func (config *Config) GetMailDaemon() *smtpd.Daemon
- func (config *Config) GetMaintenance() *maintenance.Daemon
- func (config *Config) GetPasswdRPCDaemon() *passwdrpc.Daemon
- func (config *Config) GetPhoneHomeDaemon() *phonehome.Daemon
- func (config *Config) GetPlainSocketDaemon() *plainsocket.Daemon
- func (config *Config) GetSNMPD() *snmpd.Daemon
- func (config *Config) GetSimpleIPSvcD() *simpleipsvcd.Daemon
- func (config *Config) GetSockDaemon() *sockd.Daemon
- func (config *Config) GetTelegramBot() *telegrambot.Daemon
- func (config *Config) Initialise() error
- type HTTPHandlers
- type StandardFilters
- type Supervisor
Constants ¶
const ( /* EnvironmentStripURLPrefixFromRequest is an environemnt variable name, the value of which is an optional prefix string that is expected to be present in request URLs. If used, HTTP server will install all of its handlers at URL location according to the server configuration, but with the prefix URL string added to each of them. This often helps when some kind of API gateway (e.g. AWS API gateway) proxies visitors' requests and places a prefix string in each request. For example: a homepage's domain is served by a CDN, the CDN forwards visitors' requests to a backend ("origin") and in doing so automatically adds a URL prefix "/stageLive" because the backend expects such prefix. In this case, the stripURLPrefixFromRequest shall be "/stageLive". */ EnvironmentStripURLPrefixFromRequest = "LAITOS_STRIP_URL_PREFIX_FROM_REQUEST" /* EnvironmentStripURLPrefixFromResponse is an environment variable name, the value of which is is an optional prefix string that will be stirpped from rendered HTML pages, such as links on pages and form action URLs, this is usually used in conjunction with EnvironmentStripURLPrefixFromRequest. */ EnvironmentStripURLPrefixFromResponse = "LAITOS_STRIP_URL_PREFIX_FROM_RESPONSE" )
const ( LambdaFlagName = "awslambda" // LambdaFlagName is the CLI boolean flag that tells main function to start lambda handler. ConfigFlagName = "config" // ConfigFlagName is the CLI string flag that tells a path to configuration file JSON SupervisorFlagName = "supervisor" // SupervisorFlagName is the CLI boolean flag that determines whether supervisor should run DaemonsFlagName = "daemons" // DaemonsFlagName is the CLI string flag of daemon names (comma separated) to launch // Individual daemon names as provided by user in CLI to launch laitos: DNSDName = "dnsd" HTTPDName = "httpd" InsecureHTTPDName = "insecurehttpd" MaintenanceName = "maintenance" PlainSocketName = "plainsocket" SimpleIPSvcName = "simpleipsvcd" SMTPDName = "smtpd" SNMPDName = "snmpd" SOCKDName = "sockd" TelegramName = "telegram" AutoUnlockName = "autounlock" PhoneHomeName = "phonehome" PasswdRPCName = "passwdrpc" HTTPProxyName = "httpproxy" /* FailureThresholdSec determines the maximum failure interval for supervisor to tolerate before taking action to shed off components. */ FailureThresholdSec = 20 * 60 // StartAttemptIntervalSec is the amount of time to wait between supervisor's attempts to start main program. StartAttemptIntervalSec = 30 // MemoriseOutputCapacity is the size of laitos main program output to memorise for notification purpose. MemoriseOutputCapacity = 4 * 1024 )
Variables ¶
var AllDaemons = []string{ AutoUnlockName, DNSDName, HTTPDName, InsecureHTTPDName, MaintenanceName, PhoneHomeName, PlainSocketName, SimpleIPSvcName, SMTPDName, SNMPDName, SOCKDName, TelegramName, PasswdRPCName, HTTPProxyName, }
AllDaemons is an unsorted list of string daemon names.
var ShedOrder = []string{ MaintenanceName, SimpleIPSvcName, PasswdRPCName, SNMPDName, HTTPProxyName, DNSDName, SOCKDName, SMTPDName, HTTPDName, InsecureHTTPDName, PlainSocketName, TelegramName, PhoneHomeName, }
ShedOrder is the sequence of daemon names to be taken offline one after another by supervisor, in case of rapid and repeated program crash. This mechanism is inspired by design of various aircraft abnormal procedure checklists. The sequence is prioritised this way: 1. System maintenance daemon. 2. Non-essential services that do not require authentication/authorisation. 3. Non-essential services that require authentication/authorisation. 4. Heavy services that use significant amount of resources. 5. Lightweight services.
The supervisor will not shed the last remaining daemon, which is the auto-unlocking daemon, conveniently not present in this list. The auto-unlocking daemon provides memorised password to unlock data and configuration of other healthy instances of laitos program on the LAN or Internet.
If the program continues to crash repeatedly after all rounds of shedding, then the fault may not reside in any of the shed daemons, and all daemons will be re-enabled, the user will have to make diagnosis manually.
Functions ¶
func FeedDecryptionPasswordToStdinAndStart ¶
FeedDecryptionPasswordToStdinAndStart starts the main program and writes the universal decryption password into its stdin.
Types ¶
type AWSIntegration ¶
type AWSIntegration struct { // SendWarningLogToSQSURL is the URL of SQS queue that will receive a copy of each warning log entry. // The queue will however ignore the warning log entries generated repeatedly by the same actor. SendWarningLogToSQSURL string `json:"SendWarningLogToSQSURL"` // ForwardMessageProcessorReportsToFirehoseStreamName is the name of kinesis firestream that will receive a copy of each // subject report as they arrive. ForwardMessageProcessorReportsToFirehoseStreamName string `json:"ForwardMessageProcessorReportsToFirehoseStreamName"` // ForwardMessageProcessorReportsToSNSTopicARN is the ARN of SNS topic that will receive a copy of each subject report as they // arrive. ForwardMessageProcessorReportsToSNSTopicARN string `json:"ForwardMessageProcessorReportsToSNSTopicARN"` }
AWSIntegration contains configuration properties for global behaviours (e.g. logger) of laitos program to integrate with AWS services such as SQS.
type Benchmark ¶
type Benchmark struct { Config *Config // Config is an initialised configuration structure that provides for all daemons involved in benchmark. DaemonNames []string // DaemonNames is a list of daemons that have already started and waiting to run benchmark. Logger *lalog.Logger // Logger is specified by caller if the caller wishes. HTTPPort int // HTTPPort is to be served by net/http/pprof on an HTTP server running on localhost. Stop bool // Stop, if true, will soon terminate ongoing benchmark. It may be reset to false in preparation for a new benchmark run. }
func (*Benchmark) BenchmarkDNSDaemon ¶
func (bench *Benchmark) BenchmarkDNSDaemon()
BenchmarkDNSDaemon continuously sends DNS queries via both TCP and UDP in a sequential manner.
func (*Benchmark) BenchmarkHTTPDaemon ¶
func (bench *Benchmark) BenchmarkHTTPDaemon()
BenchmarkHTTPDaemonn continuously sends HTTP requests in a sequential manner.
func (*Benchmark) BenchmarkHTTPSDaemon ¶
func (bench *Benchmark) BenchmarkHTTPSDaemon()
BenchmarkHTTPDaemonn continuously sends HTTPS requests in a sequential manner.
func (*Benchmark) BenchmarkPlainSocketDaemon ¶
func (bench *Benchmark) BenchmarkPlainSocketDaemon()
BenchmarkPlainSocketDaemon continuously sends toolbox commands via both TCP and UDP in a sequential manner.
func (*Benchmark) BenchmarkSMTPDaemon ¶
func (bench *Benchmark) BenchmarkSMTPDaemon()
BenchmarkSMTPDaemon continuously sends emails in a sequential manner.
func (*Benchmark) BenchmarkSNMPDaemon ¶
func (bench *Benchmark) BenchmarkSNMPDaemon()
BenchmarkSNMPDaemon sends random data to SNMP port, aims to catch hidden mistakes in SNMP packet decoder.
func (*Benchmark) BenchmarkSimpleIPSvcDaemon ¶
func (bench *Benchmark) BenchmarkSimpleIPSvcDaemon()
BenchmarkSimpleIPSvcDaemon continuously sends requests to all simple IP services via both TCP and UDP.
func (*Benchmark) BenchmarkSockDaemon ¶
func (bench *Benchmark) BenchmarkSockDaemon()
BenchmarkSockDaemon continuously sends packets via both TCP and UDP in a sequential manner.
func (*Benchmark) RunBenchmarkAndProfiler ¶
func (bench *Benchmark) RunBenchmarkAndProfiler()
RunBenchmarkAndProfiler starts benchmark immediately and continuously reports progress via logger. The function kicks off more goroutines for benchmarking individual daemons, and therefore does not block caller.
Benchmark cases usually uses randomly generated data and do not expect a normal response. Therefore, they serve well as fuzzy tests too.
The function assumes that daemons are already started and ready to receive requests, therefore caller may wish to consider waiting a short while for daemons to settle before running this benchmark routine.
type Config ¶
type Config struct { /* Features consist of all app instances, shared by all daemons and command runners. Avoid duplicating this structure because certain app features (such as AES file decryption) may hold large amount of data in memory. Therefore, all daemons with app command execution capability share the same app instances. */ Features *toolbox.FeatureSet `json:"Features"` // MessageProcessorFilters configure the Message Processor app's own command processor. MessageProcessorFilters StandardFilters `json:"MessageProcessorFilters"` MailClient inet.MailClient `json:"MailClient"` // MailClient is the common client configuration for sending notification emails and mail command runner results. Maintenance *maintenance.Daemon `json:"Maintenance"` // Daemon configures behaviour of periodic health-check/system maintenance DNSDaemon *dnsd.Daemon `json:"DNSDaemon"` // DNSDaemon: configure DNS daemon's network behaviour DNSFilters StandardFilters `json:"DNSFilters"` // DNSFilters: configure DNS daemon's toolbox command processor HTTPDaemon *httpd.Daemon `json:"HTTPDaemon"` // HTTP daemon configuration HTTPFilters StandardFilters `json:"HTTPFilters"` // HTTP daemon filter configuration HTTPHandlers HTTPHandlers `json:"HTTPHandlers"` // HTTP daemon handler configuration MailDaemon *smtpd.Daemon `json:"MailDaemon"` // SMTP daemon configuration MailCommandRunner *mailcmd.CommandRunner `json:"MailCommandRunner"` // MailCommandRunner processes toolbox commands from incoming mail body. MailFilters StandardFilters `json:"MailFilters"` // MailFilters configure command processor for mail command runner PhoneHomeDaemon *phonehome.Daemon `json:"PhoneHomeDaemon"` // PhoneHomeDaemon daemon instance and daemon configuration PhoneHomeFilters StandardFilters `json:"PhoneHomeFilters"` // PhoneHomeFilters daemon command processor configuration PlainSocketDaemon *plainsocket.Daemon `json:"PlainSocketDaemon"` // Plain text protocol TCP and UDP daemon configuration PlainSocketFilters StandardFilters `json:"PlainSocketFilters"` // Plain text daemon filter configuration SockDaemon *sockd.Daemon `json:"SockDaemon"` // Intentionally undocumented SNMPDaemon *snmpd.Daemon `json:"SNMPDaemon"` // SNMPDaemon configuration and instance SimpleIPSvcDaemon *simpleipsvcd.Daemon `json:"SimpleIPSvcDaemon"` // SimpleIPSvcDaemon is the simple TCP/UDP service daemon configuration and instance TelegramBot *telegrambot.Daemon `json:"TelegramBot"` // Telegram bot configuration TelegramFilters StandardFilters `json:"TelegramFilters"` // Telegram bot filter configuration AutoUnlock *autounlock.Daemon `json:"AutoUnlock"` // AutoUnlock daemon // PasswordRPCDaemon offers a network listener for a gRPC service that allows other laitos program instances to obtain password for unlocking their encrypted config/data files. PasswordRPCDaemon *passwdrpc.Daemon `json:"PasswordRPCDaemon"` // HTTPProxyDaemon offers an HTTP proxy capable of handling both HTTP and HTTPS destinations. HTTPProxyDaemon *httpproxy.Daemon `json:"HTTPProxyDaemon"` SupervisorNotificationRecipients []string `json:"SupervisorNotificationRecipients"` // Email addresses of supervisor notification recipients // AWSIntegration are settings for integrating with various AWS services, such as S3 and SQS. AWSIntegration AWSIntegration `json:"AWSIntegration"` // contains filtered or unexported fields }
Config is an aggregated structure of configuration properties that include daemon settings, mail settings, cloud integration settings, app settings, and so on. The entry point of laitos program deserialises this structure from a (often) hand-crafted configuration file written in JSON.
func (*Config) DeserialiseFromJSON ¶
DeserialiseFromJSON deserialised configuration of all daemons and toolbox features from JSON input, and then prepares itself for daemon operations.
func (*Config) GetAutoUnlock ¶
func (config *Config) GetAutoUnlock() *autounlock.Daemon
GetAutoUnlock constructs the auto-unlock prober and returns.
func (*Config) GetHTTPProxyDaemon ¶
GetHTTPProxyDaemon returns an initialised instance of HTTP proxy daemon.
func (*Config) GetMailCommandRunner ¶
func (config *Config) GetMailCommandRunner() *mailcmd.CommandRunner
Construct a mail command runner from configuration and return. It will use the common mail client to send replies. The command runner is usually built into laitos' own SMTP daemon to process feature commands from incoming mails, but an independent mail command runner is useful in certain scenarios, such as integrating with postfix's "forward-mail-to-program" mechanism.
func (*Config) GetMailDaemon ¶
Construct an SMTP daemon together with its mail command processor. Both SMTP daemon and mail command processor will use the common mail client to forward mails and send replies.
func (*Config) GetMaintenance ¶
func (config *Config) GetMaintenance() *maintenance.Daemon
GetMaintenance constructs a system maintenance / health check daemon from configuration and return.
func (*Config) GetPasswdRPCDaemon ¶
GetPasswdRPCDaemon returns the network daemon that allows other laitos program instances to obtain password for unlocking their encrypted config/data files.
func (*Config) GetPhoneHomeDaemon ¶
GetPhoneHomeDaemon initialises a Phone-Home daemon and returns it.
func (*Config) GetPlainSocketDaemon ¶
func (config *Config) GetPlainSocketDaemon() *plainsocket.Daemon
Construct a plain text protocol TCP&UDP daemon and return. It will use common mail client for sending outgoing emails.
func (*Config) GetSimpleIPSvcD ¶
func (config *Config) GetSimpleIPSvcD() *simpleipsvcd.Daemon
GetSimpleIPSvcD initialises simple IP services daemon and returns it.
func (*Config) GetSockDaemon ¶
Intentionally undocumented
func (*Config) GetTelegramBot ¶
func (config *Config) GetTelegramBot() *telegrambot.Daemon
Construct a telegram bot from configuration and return.
func (*Config) Initialise ¶
Initialise decorates feature configuration and command bridge configuration in preparation for daemon operations.
type HTTPHandlers ¶
type HTTPHandlers struct { AppCommandEndpoint string `json:"AppCommandEndpoint"` CommandFormEndpoint string `json:"CommandFormEndpoint"` FileUploadEndpoint string `json:"FileUploadEndpoint"` GitlabBrowserEndpoint string `json:"GitlabBrowserEndpoint"` GitlabBrowserEndpointConfig handler.HandleGitlabBrowser `json:"GitlabBrowserEndpointConfig"` IndexEndpointConfig handler.HandleHTMLDocument `json:"IndexEndpointConfig"` IndexEndpoints []string `json:"IndexEndpoints"` InformationEndpoint string `json:"InformationEndpoint"` LatestRequestsInspectorEndpoint string `json:"LatestRequestsInspectorEndpoint"` MailMeEndpoint string `json:"MailMeEndpoint"` MailMeEndpointConfig handler.HandleMailMe `json:"MailMeEndpointConfig"` MessageBankEndpoint string `json:"MessageBankEndpoint"` MicrosoftBotEndpoint1 string `json:"MicrosoftBotEndpoint1"` MicrosoftBotEndpoint2 string `json:"MicrosoftBotEndpoint2"` MicrosoftBotEndpoint3 string `json:"MicrosoftBotEndpoint3"` MicrosoftBotEndpointConfig1 handler.HandleMicrosoftBot `json:"MicrosoftBotEndpointConfig1"` MicrosoftBotEndpointConfig2 handler.HandleMicrosoftBot `json:"MicrosoftBotEndpointConfig2"` MicrosoftBotEndpointConfig3 handler.HandleMicrosoftBot `json:"MicrosoftBotEndpointConfig3"` ProcessExplorerEndpoint string `json:"ProcessExplorerEndpoint"` PrometheusMetricsEndpoint string `json:"PrometheusMetricsEndpoint"` RecurringCommandsEndpoint string `json:"RecurringCommandsEndpoint"` RecurringCommandsEndpointConfig handler.HandleRecurringCommands `json:"RecurringCommandsEndpointConfig"` ReportsRetrievalEndpoint string `json:"ReportsRetrievalEndpoint"` RequestInspectorEndpoint string `json:"RequestInspectorEndpoint"` LoraWANWebhookEndpoint string `json:"LoraWANWebhookEndpoint"` TwilioCallEndpoint string `json:"TwilioCallEndpoint"` TwilioCallEndpointConfig handler.HandleTwilioCallHook `json:"TwilioCallEndpointConfig"` TwilioSMSEndpoint string `json:"TwilioSMSEndpoint"` VirtualMachineEndpoint string `json:"VirtualMachineEndpoint"` VirtualMachineEndpointConfig handler.HandleVirtualMachine `json:"VirtualMachineEndpointConfig"` WebProxyEndpoint string `json:"WebProxyEndpoint"` }
Configure path to HTTP handlers and handler themselves.
type StandardFilters ¶
type StandardFilters struct { // For input command content TranslateSequences toolbox.TranslateSequences `json:"TranslateSequences"` PINAndShortcuts toolbox.PINAndShortcuts `json:"PINAndShortcuts"` // For command execution result NotifyViaEmail toolbox.NotifyViaEmail `json:"NotifyViaEmail"` LintText toolbox.LintText `json:"LintText"` }
StandardFilters contains a standard set of filters (PIN match, notification, lint, etc) that are useful to nearly all laitos daemons that carry a command processor. The filters' configuration is fed by Config struct, which is itself fed by deserialised JSON text.
type Supervisor ¶
type Supervisor struct { // CLIFlags are the thorough list of original program flags to launch laitos. This must not include the leading executable path. CLIFlags []string // NotificationRecipients are the mail address that will receive notification emails generated by this supervisor. NotificationRecipients []string // MailClient is used for sending notification emails. MailClient inet.MailClient // DaemonNames are the original set of daemon names that user asked to start. DaemonNames []string // contains filtered or unexported fields }
Supervisor manages the lifecycle of laitos main program that runs daemons. In case that main program crashes rapidly, the supervisor will attempt to isolate the crashing daemon by restarting laitos main program with reduced set of daemons, helping healthy daemons to stay online as long as possible.
func (*Supervisor) GetLaunchParameters ¶
func (sup *Supervisor) GetLaunchParameters(nthAttempt int) (cliFlags []string, daemonNames []string)
GetLaunchParameters returns the parameters used for launching laitos program for the N-th attempt. The very first attempt is the 0th attempt.
func (*Supervisor) Start ¶
func (sup *Supervisor) Start()
Start will fork and launch laitos main program and restarts it in case of crash. If consecutive crashes occur within 20 minutes, each crash will lead to reduced set of daemons being restarted with the main program. If Email notification recipients are configured, a crash report will be delivered to those recipients. The function blocks caller indefinitely.