ooni-probe-cli/internal/autorun/autorun.go
Simone Basso 504a4e79d4
feat: implement darwin launch agent (#192)
* feat: sketch out periodic command

* feat: sketch out periodic command for macOS

* feat: implement darwin's launch agent

* refactor: better way to run on darwin

Make sure we have code that builds on all platforms.

* fix(run): max 10 URLs with darwin in unattended mode

* feat: add support for seeing/streaming logs

* feat: implement the status command and add usage hints

* feat(periodic): run onboarding if needed

* fix: no too confusing function names

* fix: s/periodic/autorun/

Discussed earlier this morning with @hellais.

* fix: we cannot show logs before Big Sur

Bug reported by @hellais.
2021-01-14 18:32:05 +01:00

50 lines
1.0 KiB
Go

// Package autorun contains code to manage automatic runs
package autorun
import "sync"
const (
// StatusScheduled indicates that OONI is scheduled to run
// periodically in the background.
StatusScheduled = "scheduled"
// StatusStopped indicates that OONI is not scheduled to
// run periodically in the background.
StatusStopped = "stopped"
// StatusRunning indicates that OONI is currently
// running in the background.
StatusRunning = "running"
)
// Manager manages automatic runs
type Manager interface {
LogShow() error
LogStream() error
Start() error
Status() (string, error)
Stop() error
}
var (
registry map[string]Manager
mtx sync.Mutex
)
func register(platform string, manager Manager) {
defer mtx.Unlock()
mtx.Lock()
if registry == nil {
registry = make(map[string]Manager)
}
registry[platform] = manager
}
// Get gets the specified autorun manager. This function
// returns nil if no autorun manager exists.
func Get(platform string) Manager {
defer mtx.Unlock()
mtx.Lock()
return registry[platform]
}