From 87cf5ab794ed8fb127aa46a119d1bb0954c27635 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Fri, 27 Dec 2019 16:05:28 +0800 Subject: [PATCH] fix create system service configure file and ceph configure file --- pkg/hostman/diskutils/diskutils.go | 19 +++++++++---------- pkg/hostman/system_service/system_service.go | 16 ++++++++++------ 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/pkg/hostman/diskutils/diskutils.go b/pkg/hostman/diskutils/diskutils.go index dc67752272..951e17b195 100644 --- a/pkg/hostman/diskutils/diskutils.go +++ b/pkg/hostman/diskutils/diskutils.go @@ -17,7 +17,6 @@ package diskutils import ( "fmt" "io/ioutil" - "os" "path" "path/filepath" "runtime/debug" @@ -29,7 +28,6 @@ import ( "yunion.io/x/onecloud/pkg/hostman/diskutils/nbd" "yunion.io/x/onecloud/pkg/hostman/guestfs" "yunion.io/x/onecloud/pkg/hostman/guestfs/fsdriver" - "yunion.io/x/onecloud/pkg/util/fileutils2" "yunion.io/x/onecloud/pkg/util/procutils" "yunion.io/x/onecloud/pkg/util/qemuimg" "yunion.io/x/onecloud/pkg/util/qemutils" @@ -79,15 +77,16 @@ func (d *SKVMGuestDisk) connect() bool { if strings.HasPrefix(d.imagePath, "rbd:") || d.getImageFormat() == "raw" { //qemu-nbd 连接ceph时 /etc/ceph/ceph.conf 必须存在 if strings.HasPrefix(d.imagePath, "rbd:") { - if !fileutils2.Exists("/etc/ceph") { - if err := os.Mkdir("/etc/ceph", 0755); err != nil { - log.Errorf("failed to mkdir /etc/ceph error: %v", err) - return false - } + err := procutils.NewRemoteCommandAsFarAsPossible("mkdir", "-p", "/etc/ceph").Run() + if err != nil { + log.Errorf("Failed to mkdir /etc/ceph: %s", err) + return false } - if !fileutils2.IsFile("/etc/ceph/ceph.conf") { - if _, err := os.Create("/etc/ceph/ceph.conf"); err != nil { - log.Errorf("failed to create /etc/ceph/ceph.conf error: %v", err) + err = procutils.NewRemoteCommandAsFarAsPossible("test", "-f", "/etc/ceph/ceph.conf").Run() + if err != nil { + err = procutils.NewRemoteCommandAsFarAsPossible("touch", "/etc/ceph/ceph.conf").Run() + if err != nil { + log.Errorf("failed to create /etc/ceph/ceph.conf: %s", err) return false } } diff --git a/pkg/hostman/system_service/system_service.go b/pkg/hostman/system_service/system_service.go index 2ef98ee671..df422f8983 100644 --- a/pkg/hostman/system_service/system_service.go +++ b/pkg/hostman/system_service/system_service.go @@ -15,9 +15,11 @@ package system_service import ( + "fmt" + "yunion.io/x/log" - "yunion.io/x/onecloud/pkg/util/fileutils2" + "yunion.io/x/onecloud/pkg/util/procutils" ) type ISystemService interface { @@ -81,13 +83,15 @@ func NewBaseSystemService(name string, urls interface{}) *SBaseSystemService { } func (s *SBaseSystemService) reload(conf, conFile string) error { - oldConf, err := fileutils2.FileGetContents(conFile) - if err != nil { - return err - } + output, _ := procutils.NewRemoteCommandAsFarAsPossible("cat", conFile).Output() + oldConf := string(output) if conf != oldConf { log.Infof("Reload service %s ...", s.name) - err := fileutils2.FilePutContents(conFile, conf, false) + err := procutils.NewRemoteCommandAsFarAsPossible("rm", "-f", conFile).Run() + if err != nil { + return nil + } + err = procutils.NewRemoteCommandAsFarAsPossible("sh", "-c", fmt.Sprintf("echo '%s' > %s", conf, conFile)).Run() if err != nil { return err }