mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(host-deployer): deploy telegraf systemd service type simple (#20458)
This commit is contained in:
@@ -793,7 +793,10 @@ func (d *sLinuxRootFs) DeployTelegraf(config string) (bool, error) {
|
||||
return false, errors.Wrap(err, "chmod supervise run script")
|
||||
}
|
||||
initCmd := fmt.Sprintf("%s/supervise %s", cloudMonitorPath, telegrafPath)
|
||||
err = d.installInitScript("telegraf", initCmd)
|
||||
if d.isSupportSystemd() {
|
||||
initCmd = path.Join(telegrafPath, "run")
|
||||
}
|
||||
err = d.installInitScript("telegraf", initCmd, false)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(err, "installInitScript")
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ func (d *sLinuxRootFs) isSupportSystemd() bool {
|
||||
return d.rootFs.Exists(unitDirPath, false) && d.rootFs.Exists(enableDirPath, false)
|
||||
}
|
||||
|
||||
func (d *sLinuxRootFs) installInitScript(name, cmd string) error {
|
||||
func (d *sLinuxRootFs) installInitScript(name, cmd string, oneshot bool) error {
|
||||
if d.isSupportSystemd() {
|
||||
return d.installSystemd(name, cmd)
|
||||
return d.installSystemd(name, cmd, oneshot)
|
||||
} else {
|
||||
return d.installCrond(cmd)
|
||||
}
|
||||
@@ -54,10 +54,15 @@ func (d *sLinuxRootFs) installCrond(cmd string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *sLinuxRootFs) installSystemd(name, cmd string) error {
|
||||
func (d *sLinuxRootFs) installSystemd(name, cmd string, oneshot bool) error {
|
||||
var serviceName = fmt.Sprintf("%s.service", name)
|
||||
var unitPath = fmt.Sprintf("%s/%s", unitDirPath, serviceName)
|
||||
var enablePath = fmt.Sprintf("%s/%s", enableDirPath, serviceName)
|
||||
var serviceType = "simple"
|
||||
if oneshot {
|
||||
serviceType = "oneshot"
|
||||
}
|
||||
|
||||
var unitContent = fmt.Sprintf(`[Unit]
|
||||
Description=Run once
|
||||
After=local-fs.target
|
||||
@@ -66,11 +71,11 @@ After=network.target
|
||||
[Service]
|
||||
ExecStart=%s
|
||||
RemainAfterExit=true
|
||||
Type=oneshot
|
||||
Type=%s
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
`, cmd)
|
||||
`, cmd, serviceType)
|
||||
err := d.rootFs.FilePutContents(unitPath, unitContent, false, false)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "save user_data unit fail")
|
||||
|
||||
@@ -93,7 +93,7 @@ func (d *sLinuxRootFs) deployUserDataBySystemd(userData string) error {
|
||||
}
|
||||
}
|
||||
{
|
||||
err := d.installInitScript(serviceName, "/bin/sh "+scriptPath)
|
||||
err := d.installInitScript(serviceName, "/bin/sh "+scriptPath, true)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "installInitScript")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user