Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
add restart database command
Browse files Browse the repository at this point in the history
Signed-off-by: Jason McCallister <jason@craftcms.com>
  • Loading branch information
jasonmccallister committed Apr 3, 2020
1 parent 0742ff4 commit ec5067e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 33 deletions.
4 changes: 3 additions & 1 deletion internal/cmd/nitro.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ func init() {
)
siteCommand.AddCommand(siteAddCommand, siteRemoveCommand)
xdebugCommand.AddCommand(xdebugOnCommand, xdebugOffCommand)
machineCommand.AddCommand(destroyCommand, createCommand, servicesCommand)
machineCommand.AddCommand(destroyCommand, createCommand, restartCommand)
logsCommand.AddCommand(logsNginxCommand, logsDatabaseCommand)
restartDatabaseCommand.AddCommand(servicesDatabaseRestartCommand)
restartCommand.AddCommand(restartDatabaseCommand)
}

func Execute() {
Expand Down
15 changes: 15 additions & 0 deletions internal/cmd/restart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import (
"github.com/spf13/cobra"
)

var (
restartCommand = &cobra.Command{
Use: "restart",
Short: "Restart services on machine",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
)
29 changes: 29 additions & 0 deletions internal/cmd/restart_database.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/spf13/cobra"

"github.com/craftcms/nitro/config"
"github.com/craftcms/nitro/internal/nitro"
)

var (
restartDatabaseCommand = &cobra.Command{
Use: "database",
Short: "Restart database",
RunE: func(cmd *cobra.Command, args []string) error {
name := config.GetString("machine", flagMachineName)
engine := config.GetString("database.engine", flagDatabase)
version := config.GetString("database.version", flagDatabaseVersion)

return nitro.Run(nitro.NewMultipassRunner("multipass"), nitro.RestartDatabase(name, engine, version))
},
}
servicesDatabaseRestartCommand = &cobra.Command{
Use: "restart",
Short: "Restart the database",
RunE: func(cmd *cobra.Command, args []string) error {
return cmd.Help()
},
}
)
27 changes: 0 additions & 27 deletions internal/cmd/services.go

This file was deleted.

6 changes: 1 addition & 5 deletions internal/cmd/site.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ var siteCommand = &cobra.Command{
Use: "site",
Short: "Perform site commands",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return cmd.Help()
}

return nil
return cmd.Help()
},
}
15 changes: 15 additions & 0 deletions internal/nitro/restart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package nitro

import "fmt"

func RestartDatabase(name, engine, version string) []Command {
imageName := fmt.Sprintf("nitro_%v_%v", engine, version)
fmt.Println(imageName)
return []Command{
{
Machine: name,
Type: "exec",
Args: []string{name, "--", "docker", "restart", imageName},
},
}
}

0 comments on commit ec5067e

Please # to comment.