docker.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package system_service
  15. import (
  16. "os"
  17. "yunion.io/x/jsonutils"
  18. )
  19. type SDocker struct {
  20. *SBaseSystemService
  21. }
  22. func NewDockerService() *SDocker {
  23. return &SDocker{NewBaseSystemService("docker", nil)}
  24. }
  25. func (s *SDocker) GetConfig(kwargs map[string]interface{}) string {
  26. return jsonutils.Marshal(kwargs).PrettyString()
  27. }
  28. func (s *SDocker) GetConfigFile() string {
  29. os.MkdirAll("/etc/docker", 0755)
  30. return "/etc/docker/daemon.json"
  31. }
  32. func (s *SDocker) Reload(kwargs map[string]interface{}) error {
  33. return s.reload(s.GetConfig(kwargs), s.GetConfigFile())
  34. }
  35. func (s *SDocker) BgReload(kwargs map[string]interface{}) {
  36. go s.Reload(kwargs)
  37. }
  38. func (s *SDocker) BgReloadConf(kwargs map[string]interface{}) {
  39. go s.reloadConf(s.GetConfig(kwargs), s.GetConfigFile())
  40. }