-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add logic to mark config changes and display message
- Loading branch information
Showing
7 changed files
with
319 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package restart | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ethpandaops/contributoor-installer/cmd/cli/options" | ||
"github.com/ethpandaops/contributoor-installer/internal/sidecar" | ||
"github.com/ethpandaops/contributoor-installer/internal/tui" | ||
"github.com/sirupsen/logrus" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func RegisterCommands(app *cli.App, opts *options.CommandOpts) { | ||
app.Commands = append(app.Commands, cli.Command{ | ||
Name: opts.Name(), | ||
Aliases: opts.Aliases(), | ||
Usage: "Restart Contributoor", | ||
UsageText: "contributoor restart [options]", | ||
Action: func(c *cli.Context) error { | ||
var ( | ||
log = opts.Logger() | ||
installerCfg = opts.InstallerConfig() | ||
) | ||
|
||
sidecarCfg, err := sidecar.NewConfigService(log, c.GlobalString("config-path")) | ||
if err != nil { | ||
return fmt.Errorf("error loading config: %w", err) | ||
} | ||
|
||
dockerSidecar, err := sidecar.NewDockerSidecar(log, sidecarCfg, installerCfg) | ||
if err != nil { | ||
return fmt.Errorf("error creating docker sidecar service: %w", err) | ||
} | ||
|
||
systemdSidecar, err := sidecar.NewSystemdSidecar(log, sidecarCfg, installerCfg) | ||
if err != nil { | ||
return fmt.Errorf("error creating systemd sidecar service: %w", err) | ||
} | ||
|
||
binarySidecar, err := sidecar.NewBinarySidecar(log, sidecarCfg, installerCfg) | ||
if err != nil { | ||
return fmt.Errorf("error creating binary sidecar service: %w", err) | ||
} | ||
|
||
return restartContributoor(c, log, sidecarCfg, dockerSidecar, systemdSidecar, binarySidecar) | ||
}, | ||
}) | ||
} | ||
|
||
func restartContributoor( | ||
c *cli.Context, | ||
log *logrus.Logger, | ||
config sidecar.ConfigManager, | ||
docker sidecar.DockerSidecar, | ||
systemd sidecar.SystemdSidecar, | ||
binary sidecar.BinarySidecar, | ||
) error { | ||
var ( | ||
runner sidecar.SidecarRunner | ||
cfg = config.Get() | ||
) | ||
|
||
fmt.Printf("%sRestarting Contributoor%s\n", tui.TerminalColorLightBlue, tui.TerminalColorReset) | ||
|
||
// Determine which runner to use | ||
switch cfg.RunMethod { | ||
case sidecar.RunMethodDocker: | ||
runner = docker | ||
case sidecar.RunMethodSystemd: | ||
runner = systemd | ||
case sidecar.RunMethodBinary: | ||
runner = binary | ||
default: | ||
return fmt.Errorf("invalid sidecar run method: %s", cfg.RunMethod) | ||
} | ||
|
||
// Check if running | ||
running, err := runner.IsRunning() | ||
if err != nil { | ||
log.Errorf("could not check sidecar status: %v", err) | ||
|
||
return err | ||
} | ||
|
||
// Stop if running | ||
if running { | ||
if err := runner.Stop(); err != nil { | ||
return fmt.Errorf("failed to stop service: %w", err) | ||
} | ||
} else { | ||
fmt.Printf("%sContributoor is not running, starting contributoor%s\n", tui.TerminalColorYellow, tui.TerminalColorReset) | ||
} | ||
|
||
// Start the service. | ||
if err := runner.Start(); err != nil { | ||
return fmt.Errorf("failed to start service: %w", err) | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.