Skip to content

Commit e829e19

Browse files
committed
daemon: create daemon management interface
Create 'DaemonProvider' interface for creating and managing daemon processes, to eventually be used by the 'web-server' subcommand to manage a web server daemon. Because daemon process management is dependent on the operating system/tools available, initially create two types to implement the interface: one for 'launchd' (MacOS) and one for 'systemd' (Linux). The functions, for now, all return "not implemented" errors but will be implemented in later patches. Finally, add a 'NewDaemonProvider' to create the appropriate daemon provider implementation based on the operating system. Signed-off-by: Victoria Dye <[email protected]>
1 parent 2d4657d commit e829e19

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed

internal/daemon/daemon.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package daemon
2+
3+
import (
4+
"fmt"
5+
"runtime"
6+
)
7+
8+
type DaemonConfig struct {
9+
Label string
10+
Program string
11+
}
12+
13+
type DaemonProvider interface {
14+
Create(config *DaemonConfig, force bool) error
15+
16+
Start(label string) error
17+
18+
Stop(label string) error
19+
}
20+
21+
func NewDaemonProvider() (DaemonProvider, error) {
22+
switch thisOs := runtime.GOOS; thisOs {
23+
case "linux":
24+
// Use systemd/systemctl
25+
return NewSystemdProvider(), nil
26+
case "darwin":
27+
// Use launchd/launchctl
28+
return NewLaunchdProvider(), nil
29+
default:
30+
return nil, fmt.Errorf("cannot configure daemon handler for OS '%s'", thisOs)
31+
}
32+
}

internal/daemon/launchd.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package daemon
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
type launchd struct{}
8+
9+
func NewLaunchdProvider() DaemonProvider {
10+
return &launchd{}
11+
}
12+
13+
func (l *launchd) Create(config *DaemonConfig, force bool) error {
14+
return fmt.Errorf("not implemented")
15+
}
16+
17+
func (l *launchd) Start(label string) error {
18+
return fmt.Errorf("not implemented")
19+
}
20+
21+
func (l *launchd) Stop(label string) error {
22+
return fmt.Errorf("not implemented")
23+
}

internal/daemon/systemd.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package daemon
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
type systemd struct{}
8+
9+
func NewSystemdProvider() DaemonProvider {
10+
return &systemd{}
11+
}
12+
13+
func (s *systemd) Create(config *DaemonConfig, force bool) error {
14+
return fmt.Errorf("not implemented")
15+
}
16+
17+
func (s *systemd) Start(label string) error {
18+
return fmt.Errorf("not implemented")
19+
}
20+
21+
func (s *systemd) Stop(label string) error {
22+
return fmt.Errorf("not implemented")
23+
}

0 commit comments

Comments
 (0)