-
Notifications
You must be signed in to change notification settings - Fork 35
/
restart.go
45 lines (37 loc) · 1.12 KB
/
restart.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package application
import (
"context"
"strings"
api "github.com/ehazlett/stellar/api/services/application/v1"
ptypes "github.com/gogo/protobuf/types"
"github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func (s *service) Restart(ctx context.Context, req *api.RestartRequest) (*ptypes.Empty, error) {
appName := getAppName(req.Name)
containers, err := s.getApplicationContainers(appName)
if err != nil {
return empty, err
}
if len(containers) == 0 {
return empty, status.Errorf(codes.NotFound, "application %s not found", appName)
}
for _, cc := range containers {
if !strings.HasPrefix(cc.Container.ID, req.Name) {
continue
}
logrus.Debugf("restarting container %s on node %s", cc.Container.ID, cc.Node.ID)
nc, err := s.client(cc.Node.Address)
if err != nil {
logrus.Warnf("delete: error getting client for node %s: %s", cc.Node.ID, err)
continue
}
if err := nc.Node().RestartContainer(cc.Container.ID); err != nil {
logrus.Warnf("restart: error restarting service on node %s: %s", cc.Node.ID, err)
continue
}
nc.Close()
}
return empty, err
}