Merge pull request #4373 from wanyaoqi/bugfix/wyq/host-misc

host: fix create system service configure file and ceph configure file
This commit is contained in:
yunion-ci-robot
2019-12-27 20:51:31 +08:00
committed by GitHub
2 changed files with 19 additions and 16 deletions
+9 -10
View File
@@ -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
}
}
+10 -6
View File
@@ -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
}