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

Commit

Permalink
break out to multiple services
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccallister committed Jul 27, 2020
1 parent e0a3ef7 commit 2313e4d
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 180 deletions.
5 changes: 3 additions & 2 deletions cmd/nitrod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ func main() {
// create the grpc server
s := grpc.NewServer()

// register our service
nitrod.RegisterNitroServiceServer(s, nitrod.New())
// register our services
nitrod.RegisterNitroServiceServer(s, nitrod.NewNitroService())
nitrod.RegisterSystemServiceServer(s, nitrod.NewSystemService())

fmt.Println("running nitrod on port", *port)

Expand Down
9 changes: 9 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ func NewClient(ip, port string) nitrod.NitroServiceClient {

return nitrod.NewNitroServiceClient(cc)
}

func NewSystemClient(ip, port string) nitrod.SystemServiceClient {
cc, err := grpc.Dial(ip+":"+port, grpc.WithInsecure())
if err != nil {
log.Fatal("error creating nitrod system client, error:", err)
}

return nitrod.NewSystemServiceClient(cc)
}
12 changes: 6 additions & 6 deletions internal/cmd/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ var nginxRestartCommand = &cobra.Command{
machine := flagMachineName
runner := nitro.NewMultipassRunner("multipass")
ip := nitro.IP(machine, runner)
c := client.NewClient(ip, "50051")
c := client.NewSystemClient(ip, "50051")

resp, err := c.NginxService(cmd.Context(), &nitrod.NginxServiceRequest{Action: nitrod.ServiceAction_RESTART})
resp, err := c.Nginx(cmd.Context(), &nitrod.NginxServiceRequest{Action: nitrod.ServiceAction_RESTART})
if err != nil {
return err
}
Expand All @@ -45,9 +45,9 @@ var nginxStartCommand = &cobra.Command{
machine := flagMachineName
runner := nitro.NewMultipassRunner("multipass")
ip := nitro.IP(machine, runner)
c := client.NewClient(ip, "50051")
c := client.NewSystemClient(ip, "50051")

resp, err := c.NginxService(cmd.Context(), &nitrod.NginxServiceRequest{Action: nitrod.ServiceAction_START})
resp, err := c.Nginx(cmd.Context(), &nitrod.NginxServiceRequest{Action: nitrod.ServiceAction_START})
if err != nil {
return err
}
Expand All @@ -65,9 +65,9 @@ var nginxStopCommand = &cobra.Command{
machine := flagMachineName
runner := nitro.NewMultipassRunner("multipass")
ip := nitro.IP(machine, runner)
c := client.NewClient(ip, "50051")
c := client.NewSystemClient(ip, "50051")

resp, err := c.NginxService(cmd.Context(), &nitrod.NginxServiceRequest{Action: nitrod.ServiceAction_STOP})
resp, err := c.Nginx(cmd.Context(), &nitrod.NginxServiceRequest{Action: nitrod.ServiceAction_STOP})
if err != nil {
return err
}
Expand Down
14 changes: 7 additions & 7 deletions internal/cmd/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"github.com/spf13/cobra"

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

var phpCommand = &cobra.Command{
Expand All @@ -26,10 +26,10 @@ var phpRestartCommand = &cobra.Command{
machine := flagMachineName
runner := nitro.NewMultipassRunner("multipass")
ip := nitro.IP(machine, runner)
c := client.NewClient(ip, "50051")
c := client.NewSystemClient(ip, "50051")
php := config.GetString("php", flagPhpVersion)

resp, err := c.PhpFpmService(cmd.Context(), &nitrod.PhpFpmServiceRequest{Version: php, Action: nitrod.ServiceAction_RESTART})
resp, err := c.PhpFpm(cmd.Context(), &nitrod.PhpFpmServiceRequest{Version: php, Action: nitrod.ServiceAction_RESTART})
if err != nil {
return err
}
Expand All @@ -47,10 +47,10 @@ var phpStartCommand = &cobra.Command{
machine := flagMachineName
runner := nitro.NewMultipassRunner("multipass")
ip := nitro.IP(machine, runner)
c := client.NewClient(ip, "50051")
c := client.NewSystemClient(ip, "50051")
php := config.GetString("php", flagPhpVersion)

resp, err := c.PhpFpmService(cmd.Context(), &nitrod.PhpFpmServiceRequest{Version: php, Action: nitrod.ServiceAction_START})
resp, err := c.PhpFpm(cmd.Context(), &nitrod.PhpFpmServiceRequest{Version: php, Action: nitrod.ServiceAction_START})
if err != nil {
return err
}
Expand All @@ -68,10 +68,10 @@ var phpStopCommand = &cobra.Command{
machine := flagMachineName
runner := nitro.NewMultipassRunner("multipass")
ip := nitro.IP(machine, runner)
c := client.NewClient(ip, "50051")
c := client.NewSystemClient(ip, "50051")
php := config.GetString("php", flagPhpVersion)

resp, err := c.PhpFpmService(cmd.Context(), &nitrod.PhpFpmServiceRequest{Version: php, Action: nitrod.ServiceAction_STOP})
resp, err := c.PhpFpm(cmd.Context(), &nitrod.PhpFpmServiceRequest{Version: php, Action: nitrod.ServiceAction_STOP})
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/nitrod/iniset.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/craftcms/nitro/validate"
)

func (s *Service) PhpIniSettings(ctx context.Context, request *ChangePhpIniSettingRequest) (*ServiceResponse, error) {
func (s *NitroService) PhpIniSettings(ctx context.Context, request *ChangePhpIniSettingRequest) (*ServiceResponse, error) {
var setting string
value := request.GetValue()
version := request.GetVersion()
Expand Down
2 changes: 1 addition & 1 deletion internal/nitrod/initset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func TestNitrodService_PhpIniSettings(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
spy := &spyChainRunner{}
s := &Service{
s := &NitroService{
command: spy,
logger: tt.fields.logger,
}
Expand Down
33 changes: 0 additions & 33 deletions internal/nitrod/nginx.go

This file was deleted.

Loading

0 comments on commit 2313e4d

Please # to comment.