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 --dry option to run command #175

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 12 additions & 1 deletion cmd/pebble/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package main

import (
"errors"
"fmt"
"os"
"os/signal"
Expand All @@ -40,6 +41,7 @@ type cmdRun struct {
clientMixin

CreateDirs bool `long:"create-dirs"`
Dry bool `long:"dry"`
Hold bool `long:"hold"`
HTTP string `long:"http"`
Verbose bool `short:"v" long:"verbose"`
Expand All @@ -49,6 +51,7 @@ func init() {
addCommand("run", shortRunHelp, longRunHelp, func() flags.Commander { return &cmdRun{} },
map[string]string{
"create-dirs": "Create pebble directory on startup if it doesn't exist",
"dry": "Don't start the pebble daemon. This option is incompatible with --create-dirs",
anpep marked this conversation as resolved.
Show resolved Hide resolved
"hold": "Do not start default services automatically",
"http": `Start HTTP API listening on this address (e.g., ":4000")`,
"verbose": "Log all output from services to stdout",
Expand All @@ -60,6 +63,10 @@ func (rcmd *cmdRun) Execute(args []string) error {
return ErrExtraArgs
}

if rcmd.CreateDirs && rcmd.Dry {
return errors.New("cannot run pebble: --create-dirs and --dry are mutually exclusive")
}

sigs := make(chan os.Signal, 2)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)

Expand Down Expand Up @@ -126,6 +133,7 @@ func runDaemon(rcmd *cmdRun, ch chan os.Signal) error {
dopts := daemon.Options{
Dir: pebbleDir,
SocketPath: socketPath,
Dry: rcmd.Dry,
}
if rcmd.Verbose {
dopts.ServiceOutput = os.Stdout
Expand All @@ -152,10 +160,13 @@ func runDaemon(rcmd *cmdRun, ch chan os.Signal) error {
tic = time.NewTicker(checkRunningConditionsRetryDelay)
checkTicker = tic.C
}

d.Version = cmd.Version
d.Start()

if rcmd.Dry {
return nil
}
anpep marked this conversation as resolved.
Show resolved Hide resolved

watchdog, err := runWatchdog(d)
if err != nil {
return fmt.Errorf("cannot run software watchdog: %v", err)
Expand Down
14 changes: 14 additions & 0 deletions internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type Options struct {
// ServiceOuput is an optional io.Writer for the service log output, if set, all services
// log output will be written to the writer.
ServiceOutput io.Writer

Dry bool
anpep marked this conversation as resolved.
Show resolved Hide resolved
}

// A Daemon listens for requests and routes them to the right command
Expand All @@ -92,6 +94,7 @@ type Daemon struct {
tomb tomb.Tomb
router *mux.Router
standbyOpinions *standby.StandbyOpinions
dry bool

// set to remember we need to restart the system
restartSystem bool
Expand Down Expand Up @@ -354,6 +357,13 @@ func logit(handler http.Handler) http.Handler {
// Init sets up the Daemon's internal workings.
// Don't call more than once.
func (d *Daemon) Init() error {
if _, err := d.overlord.ServiceManager().Plan(); err != nil {
return err
}
anpep marked this conversation as resolved.
Show resolved Hide resolved
if d.dry {
return nil
}

listenerMap := make(map[string]net.Listener)

if listener, err := getListener(d.normalSocketPath, listenerMap); err == nil {
Expand Down Expand Up @@ -453,6 +463,9 @@ func (d *Daemon) initStandbyHandling() {
}

func (d *Daemon) Start() {
if d.dry {
return
}
if d.rebootIsMissing {
// we need to schedule and wait for a system restart
d.tomb.Kill(nil)
Expand Down Expand Up @@ -786,6 +799,7 @@ func New(opts *Options) (*Daemon, error) {
normalSocketPath: opts.SocketPath,
untrustedSocketPath: opts.SocketPath + ".untrusted",
httpAddress: opts.HTTPAddress,
dry: opts.Dry,
}

ovld, err := overlord.New(opts.Dir, d, opts.ServiceOutput)
Expand Down