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

Add restart cmd + auto/start, stop idempotency. #58

Merged
merged 4 commits into from
Sep 30, 2021

Conversation

hpidcock
Copy link
Member

@hpidcock hpidcock commented Jul 14, 2021

This PR implements the restart command for (re)starting services.

Additionally

  • autostart, start and stop are now idempotent.
  • variable expansion on the command for a service now takes place

Resolves #47

Copy link
Contributor

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Approve (with the addition of README/tests for the $var expanding in command).

cmd/pebble/cmd_restart.go Show resolved Hide resolved
}

args, err := shlex.Split(service.Command)
commandString := os.Expand(service.Command, func(k string) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is a good change, but it doesn't look like it's documented (in the README) or tested anywhere. Can we add those?

Nit: what about calling this commandExpanded?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh yeah I forgot I had made this change, I'll make sure to add some tests and documentation.

@@ -134,6 +150,13 @@ func (m *ServiceManager) doStart(task *state.Task, tomb *tomb.Tomb) error {
go func() {
active.err = cmd.Wait()
_ = active.logBuffer.Close()
releasePlan, err := m.acquirePlan()
if err == nil {
if m.services[req.Name].cmd == cmd {
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this if statement check for? (I realize it was there already below.)

Copy link
Member Author

Choose a reason for hiding this comment

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

acquirePlan wouldn't actually fail here, since the plan is loaded already. I guess I can make this more future proof by relying on the mutex directly incase acquirePlan implementation changes.

README.md Outdated Show resolved Hide resolved
cmd/pebble/cmd_restart.go Outdated Show resolved Hide resolved
Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

Thank you. Just a few trivial remarks, and LGTM when you're happy.

startTasks.WaitAll(stopTasks)
taskSet = state.NewTaskSet()
taskSet.AddAll(stopTasks)
taskSet.AddAll(startTasks)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's nice that both the stop order and the start order is correct here.

internal/overlord/servstate/handlers.go Show resolved Hide resolved
for id := range successors {
id := string(string(id))
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a funny left over from an automatic replacement. The id used to be an ObjectId type.

@niemeyer
Copy link
Contributor

Btw, please keep an eye on the commit message. The description of this PR looks out of date, referring to the env change which was split out.

Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

Oops, sorry, one additional comment that probably needs looking into:

internal/plan/plan.go Outdated Show resolved Hide resolved
Copy link
Contributor

@niemeyer niemeyer left a comment

Choose a reason for hiding this comment

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

Just a couple of trivials about error messages that became logs, and LGTM! Thank you!

internal/overlord/servstate/handlers.go Outdated Show resolved Hide resolved
internal/overlord/servstate/handlers.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

autostart fails if service has already started
3 participants