podman

Форк
0
64 строки · 2.2 Кб
1
package docker
2

3
import (
4
	"errors"
5
	"fmt"
6
	"net/http"
7
)
8

9
// RestartPolicy represents the policy for automatically restarting a container.
10
//
11
// Possible values are:
12
//
13
//   - always: the docker daemon will always restart the container
14
//   - on-failure: the docker daemon will restart the container on failures, at
15
//     most MaximumRetryCount times
16
//   - unless-stopped: the docker daemon will always restart the container except
17
//     when user has manually stopped the container
18
//   - no: the docker daemon will not restart the container automatically
19
type RestartPolicy struct {
20
	Name              string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
21
	MaximumRetryCount int    `json:"MaximumRetryCount,omitempty" yaml:"MaximumRetryCount,omitempty" toml:"MaximumRetryCount,omitempty"`
22
}
23

24
// AlwaysRestart returns a restart policy that tells the Docker daemon to
25
// always restart the container.
26
func AlwaysRestart() RestartPolicy {
27
	return RestartPolicy{Name: "always"}
28
}
29

30
// RestartOnFailure returns a restart policy that tells the Docker daemon to
31
// restart the container on failures, trying at most maxRetry times.
32
func RestartOnFailure(maxRetry int) RestartPolicy {
33
	return RestartPolicy{Name: "on-failure", MaximumRetryCount: maxRetry}
34
}
35

36
// RestartUnlessStopped returns a restart policy that tells the Docker daemon to
37
// always restart the container except when user has manually stopped the container.
38
func RestartUnlessStopped() RestartPolicy {
39
	return RestartPolicy{Name: "unless-stopped"}
40
}
41

42
// NeverRestart returns a restart policy that tells the Docker daemon to never
43
// restart the container on failures.
44
func NeverRestart() RestartPolicy {
45
	return RestartPolicy{Name: "no"}
46
}
47

48
// RestartContainer stops a container, killing it after the given timeout (in
49
// seconds), during the stop process.
50
//
51
// See https://goo.gl/MrAKQ5 for more details.
52
func (c *Client) RestartContainer(id string, timeout uint) error {
53
	path := fmt.Sprintf("/containers/%s/restart?t=%d", id, timeout)
54
	resp, err := c.do(http.MethodPost, path, doOptions{})
55
	if err != nil {
56
		var e *Error
57
		if errors.As(err, &e) && e.Status == http.StatusNotFound {
58
			return &NoSuchContainer{ID: id}
59
		}
60
		return err
61
	}
62
	resp.Body.Close()
63
	return nil
64
}
65

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.