mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user