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

Commit

Permalink
Added detach 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 Mar 11, 2020
1 parent 64fdb9b commit da7133f
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
1 change: 1 addition & 0 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func NewApp(r command.Runner) *cli.App {
command.Update(r),
command.Logs(r),
command.IP(r),
command.Detach(r),
},
}
}
4 changes: 4 additions & 0 deletions internal/command/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ func bootstrapAfterAction(c *cli.Context, r Runner) error {
port = 3306
}

fmt.Println("")
fmt.Println("==== SERVER INFO ====")
fmt.Println("server:", "http://"+ip)
fmt.Println("")
fmt.Println("")
fmt.Println("==== DATABASE INFO ====")
fmt.Println("server:", ip)
Expand Down
8 changes: 8 additions & 0 deletions internal/command/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ write_files:
# enable the nginx site
sudo ln -s /etc/nginx/sites-available/"$NEW_HOST_NAME" /etc/nginx/sites-enabled/
# reload nginx
sudo service nginx reload
- path: /opt/nitro/nginx/remove-site.sh
content: |
#!/usr/bin/env bash
REMOVE_HOST="$1"
# remove the nginx site
sudo rm /etc/nginx/sites-enabled/"$REMOVE_HOST"
# reload nginx
sudo service nginx reload
- path: /opt/nitro/nginx/tail-logs.sh
Expand Down
37 changes: 37 additions & 0 deletions internal/command/detach.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package command

import (
"errors"
"fmt"

"github.com/urfave/cli/v2"
)

var (
ErrDetachNoPathArgProvided = errors.New("missing the host to remove")
)

func Detach(r Runner) *cli.Command {
return &cli.Command{
Name: "detach",
Before: func(c *cli.Context) error {
return detachBeforeAction(c)
},
Action: func(c *cli.Context) error {
return detachAction(c, r)
},
}
}

func detachBeforeAction(c *cli.Context) error {
if c.Args().First() == "" {
return ErrDetachNoPathArgProvided
}

return nil
}

func detachAction(c *cli.Context, r Runner) error {
fmt.Println(fmt.Sprintf("removed mount %v from machine", c.Args().First()))
return r.Run([]string{"umount", c.String("machine") + ":/home/ubuntu/sites/" + c.Args().First()})
}
10 changes: 3 additions & 7 deletions internal/command/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@ func removeBeforeAction(c *cli.Context) error {
}

func removeAction(c *cli.Context, r Runner) error {
machine := c.String("machine")
host := c.Args().First()

return r.Run([]string{"exec", "--name", machine, "--", "sudo", "bash", "/opt/nitro/nginx/remove-host.sh", host})
return r.Run([]string{"exec", c.String("machine"), "--", "sudo", "bash", "/opt/nitro/nginx/remove-site.sh", c.Args().First()})
}

func removeAfterAction(c *cli.Context) error {
fmt.Println("removed host", c.Args().First())

return nil
fmt.Println(fmt.Sprintf("removed host %v from nginx", c.Args().First()))
return c.App.RunContext(c.Context, []string{c.App.Name, "--machine", c.String("machine") + "detach", c.Args().First()})
}

0 comments on commit da7133f

Please # to comment.