Documentation
¶
Overview ¶
Package instance keeps to one server per data folder. The first start takes a lock that the system lets go of when the process ends, however it ends, so a crash never leaves anything behind to block the next start. A second start finds the first one through instance.json and its health check, and says so or asks what to do.
Index ¶
- Constants
- Variables
- func AnotherText(folder string, port int) string
- func FreePort(host string, from int, skip ...int) int
- func HealthID(ctx context.Context, base string) (id string, ok bool)
- func Held(dir string) bool
- func HeldBy(dir string) (pid int, running, known bool)
- func Holder(dir string) int
- func Line(r Running, dir string) string
- func NotAnsweringText(r Running) string
- func PrepareAnother(args []string, listen string, d Decision) ([]string, error)
- func RunningText(r Running, now time.Time) string
- func SameFolder(a, b string) bool
- func SuggestFolder(dir string) string
- type Ask
- type Choice
- type Decision
- type Info
- type Lock
- type Outcome
- type Question
- type Running
Constants ¶
const ( TitleRunning = "WittyMediaServer is already running" ButtonOpen = "Open WittyMediaServer" ButtonAnother = "Start another server…" ButtonExit = "Exit" TitleAnother = "Start another server" ButtonStart = "Start it" ButtonChoose = "Choose another folder…" ButtonBack = "Back" )
The words of the question, kept here so the tray app and the server say the same.
const ( // LockFile is held by the running server for as long as it runs. It's never removed: // removing a lock file is how two processes end up each holding one. LockFile = "instance.lock" // InfoFile says where the running server is. No secrets: it's only how a second // start finds the first. InfoFile = "instance.json" // ExitRunning is the exit code of a start that found its data folder in use. Service // managers are told not to restart on it. ExitRunning = 3 // FirstOtherPort is where the search for a second server's port starts. FirstOtherPort = 9798 )
Variables ¶
var ( // ErrBusy: another process holds the data folder. ErrBusy = errors.New("another server is using this data folder") // ErrUnsupported: the folder's file system can't lock (some network shares and // container file sharing). The server starts anyway, unguarded. ErrUnsupported = errors.New("this folder can't be locked") )
Functions ¶
func AnotherText ¶
AnotherText explains what a second server is before it starts.
func FreePort ¶
FreePort finds the first port from `from` that host can listen on, skipping those in skip. It returns 0 when none of the next hundred are free.
func HealthID ¶
HealthID asks a server at base for its instance id. A WittyMediaServer older than this answers with an empty one; ok says something answered as a WittyMediaServer does.
func Held ¶
Held says another process holds dir, for tools that mustn't change its files under a running server.
func HeldBy ¶
HeldBy says whether another process is running as a server on dir, and its process number when that's known: this process holding it doesn't count, for the repairs a server runs on itself. known is false for a folder no server of this version has used, where a tool has to fall back on what it did before.
func Holder ¶
Holder is the process number of the server holding dir, or 0 when none does or it can't be told.
func NotAnsweringText ¶
NotAnsweringText is said when the server on the folder doesn't answer.
func PrepareAnother ¶
PrepareAnother gets the second server's folder ready and returns args to start it with. It has a config file of its own in its folder: the first server's wms.json, or WMS_* variables, can name a cache, transcode, artwork or log folder outside the data folder, and two servers must never share those. That file is also how it's started again by hand: wittymediaserver -config <folder>/wms.json.
func RunningText ¶
RunningText is the first question's text.
func SuggestFolder ¶
SuggestFolder is the folder offered for a second server: beside dir, named after it, and not in use by a server already.
Types ¶
type Ask ¶
Ask shows a question with buttons and returns the index of the one chosen, or -1 when the question was closed (Escape). The programs pass desktop.Ask; tests pass a fake.
type Choice ¶
type Choice int
Choice is what the person chose when their server was already running.
type Decision ¶
type Decision struct {
Choice Choice
Folder string // ChoiceAnother: the second server's data folder
Port int // and its port
}
Decision is what to do.
type Info ¶
type Info struct {
PID int `json:"pid"`
Started time.Time `json:"started"`
Version string `json:"version"`
URLs []string `json:"urls"`
Instance string `json:"instance"`
// Service: started by a service manager, which the tray app attaches to rather than asking.
Service bool `json:"service,omitempty"`
}
Info is what instance.json holds.
type Lock ¶
type Lock struct {
// contains filtered or unexported fields
}
Lock is this process's hold on a data folder.
func AcquireWait ¶
AcquireWait is Acquire for a start that follows a restart: the process before this one may still be closing, so a busy folder gets up to wait.
func (*Lock) ID ¶
ID is this run's own random id, which /api/health gives out so that a second start knows it's talking to this server and not some other program on the port.
type Outcome ¶
type Outcome struct {
Code int // exit with this, unless one of these is set:
Again []string // start again with these arguments: a second server
Attach bool // the tray app: show the service that's running there
}
Outcome is what a start that found its data folder in use does next.
func WhenRunning ¶
WhenRunning handles a start that found dir in use, for the server and the tray app alike: one line when nobody is there to answer, the question when someone is. listen is the address this start would have used. Only the tray app attaches to a service.
type Question ¶
type Question struct {
Running Running
Dir string // the data folder that's in use
Ask Ask
// Pick chooses a folder. Nil leaves only the one suggested.
Pick func() (string, error)
// FreePort finds a port for the second server; 0 means none.
FreePort func() int
// InUse says a folder has a server already. Held, unless a test says otherwise.
InUse func(dir string) bool
// Suggest is the folder offered. SuggestFolder, unless a test says otherwise.
Suggest func(dir string) string
Now time.Time
}
Question is everything Decide needs.
func DesktopQuestion ¶
DesktopQuestion is the question as the programs ask it: in the system's own dialogs, with its folder picker, and a port free beside the running one.