Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions etcd/cmd/microshift-etcd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ func (s *EtcdService) Run() error {
}
<-e.Server.ReadyNotify()

// Wait to be stopped.
sigTerm := make(chan os.Signal, 1)
signal.Notify(sigTerm, os.Interrupt, syscall.SIGTERM)
sig := <-sigTerm
Expand Down
3 changes: 3 additions & 0 deletions hack/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ sudo bash -c "
systemctl disable microshift 2>/dev/null
pkill -9 microshift

systemctl stop --now microshift-etcd 2>/dev/null
systemctl reset-failed microshift-etcd 2>/dev/null

echo Removing crio container and image storage
crio wipe -f &>/dev/null || true
systemctl restart crio
Expand Down
29 changes: 27 additions & 2 deletions pkg/controllers/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,39 @@ func (s *EtcdService) Name() string { return "etcd" }
func (s *EtcdService) Dependencies() []string { return []string{} }

func (s *EtcdService) Run(ctx context.Context, ready chan<- struct{}, stopped chan<- struct{}) error {
defer close(stopped)

// Check to see if we should run as a systemd run or directly as a binary.
runningAsSvc := os.Getenv("INVOCATION_ID") != ""
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main thing we wanted was to always use the microshift-etcd binary in the same directory as the microshift binary, to support the developer use case. Does it matter if that developer binary is run in a systemd unit? Would always using system simplify anything below?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. Only thing is that etcd logs would be separate, but I don't think we need them that much in day to day development

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is another area to simplify after the initial version is merged?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC, there was some pushback in a previous meeting about not executing etcd as a systemd unit in development, I don't remember the reason given.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may have been worried that it wouldn't work, or wouldn't stop, or something. I don't have a preference, as long as it works. We can land it this way and experiment with removing it when we have some time.


// Get the path to the etcd binary based on the MicroShift binary location.
microshiftExecPath, err := os.Executable()
if err != nil {
return fmt.Errorf("%v failed to get exec path: %v", s.Name(), err)
}
etcdPath := filepath.Join(filepath.Dir(microshiftExecPath), "microshift-etcd")
// Not running the etcd binary directly, the proper etcd arguments are handled
// in etcd/cmd/microshift-etcd/run.go.
args := []string{"run"}

// If we're launching MicroShift as a service, we need to do the same
// with etcd, so wrap it in a transient systemd-unit that's tied
// to the MicroShift service lifetime.
var exe string
if runningAsSvc {
args = append([]string{
"--uid=root",
"--scope",
"--property", "BindsTo=microshift.service",
"--unit", "microshift-etcd",
etcdPath,
}, args...)
exe = "systemd-run"
Comment thread
dusk125 marked this conversation as resolved.
Outdated
} else {
exe = etcdPath
}
// Not using context as canceling ctx sends SIGKILL to process
cmd := exec.Command(etcdPath, args...)
cmd := exec.Command(exe, args...)

wd, err := os.Getwd()
if err != nil {
Expand All @@ -63,7 +87,7 @@ func (s *EtcdService) Run(ctx context.Context, ready chan<- struct{}, stopped ch
cmd.Dir = wd
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {
if err = cmd.Start(); err != nil {
return fmt.Errorf("%s failed to start: %v", s.Name(), err)
}

Expand All @@ -87,6 +111,7 @@ func (s *EtcdService) Run(ctx context.Context, ready chan<- struct{}, stopped ch
klog.Info("etcd is ready!")
close(ready)

// Wait for MicroShift to be done
<-ctx.Done()
return ctx.Err()
}
Expand Down