aboutsummaryrefslogtreecommitdiffhomepage
path: root/hst/fsdaemon.go
blob: fd3f37580aad8dedee3533e4b4b7ca23b5f679cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package hst

import (
	"encoding/gob"

	"hakurei.app/container/check"
)

func init() { gob.Register(new(FSDaemon)) }

// FilesystemDaemon is the type string of a daemon.
const FilesystemDaemon = "daemon"

// FSDaemon represents a daemon to be started in the container.
type FSDaemon struct {
	// Pathname indicating readiness of daemon.
	Target *check.Absolute `json:"dst"`
	// Absolute pathname to daemon executable file.
	Exec *check.Absolute `json:"path"`
	// Arguments (excl. first) passed to daemon.
	Args []string `json:"args"`
}

func (d *FSDaemon) Valid() bool { return d != nil && d.Target != nil && d.Exec != nil }

func (d *FSDaemon) Path() *check.Absolute {
	if !d.Valid() {
		return nil
	}
	return d.Target
}

func (d *FSDaemon) Host() []*check.Absolute { return nil }

func (d *FSDaemon) Apply(z *ApplyState) {
	if !d.Valid() {
		return
	}
	z.Daemon(d.Target, d.Exec, d.Args...)
}

func (d *FSDaemon) String() string {
	if !d.Valid() {
		return "<invalid>"
	}

	return "daemon:" + d.Target.String()
}