Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/lxd-to-incus: Add OpenRC target support #204

Merged
merged 1 commit into from
Oct 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion cmd/lxd-to-incus/targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type Target interface {
Paths() (*DaemonPaths, error)
}

var targets = []Target{&targetSystemd{}}
var targets = []Target{&targetSystemd{}, &targetOpenRC{}}

type targetSystemd struct{}

Expand Down Expand Up @@ -61,3 +61,47 @@ func (s *targetSystemd) Paths() (*DaemonPaths, error) {
Cache: "/var/cache/incus/",
}, nil
}

type targetOpenRC struct{}

func (s *targetOpenRC) Present() bool {
if !util.PathExists("/var/lib/incus/") {
return false
}

_, err := subprocess.RunCommand("rc-service", "--exists", "incus")
if err != nil {
return false
}

return true
}

func (s *targetOpenRC) Stop() error {
_, err := subprocess.RunCommand("rc-service", "incus", "stop")
return err
}

func (s *targetOpenRC) Start() error {
_, err := subprocess.RunCommand("rc-service", "incus", "start")
if err != nil {
return err
}

// Wait for the socket to become available.
time.Sleep(5 * time.Second)

return nil
}

func (s *targetOpenRC) Connect() (incus.InstanceServer, error) {
return incus.ConnectIncusUnix("/var/lib/incus/unix.socket", nil)
}

func (s *targetOpenRC) Paths() (*DaemonPaths, error) {
return &DaemonPaths{
Daemon: "/var/lib/incus/",
Logs: "/var/log/incus/",
Cache: "/var/cache/incus/",
}, nil
}
Loading