mirror of
https://gitee.com/openeuler/A-Tune.git
synced 2025-12-06 08:08:59 +08:00
split atune-rest service from atuned
This commit is contained in:
4
Makefile
4
Makefile
@@ -27,8 +27,8 @@ all: abs-python modules atune-adm atuned db
|
|||||||
abs-python:
|
abs-python:
|
||||||
@if [ $(PYDIR) ] ; then \
|
@if [ $(PYDIR) ] ; then \
|
||||||
sed -i "s?ExecStart=.*python3?ExecStart=$(PYDIR)?g" $(CURDIR)/misc/atune-engine.service; \
|
sed -i "s?ExecStart=.*python3?ExecStart=$(PYDIR)?g" $(CURDIR)/misc/atune-engine.service; \
|
||||||
|
sed -i "s?ExecStart=.*python3?ExecStart=$(PYDIR)?g" $(CURDIR)/misc/atune-rest.service; \
|
||||||
sed -i "s?ExecStart=.*python3?ExecStart=$(PYDIR)?g" $(CURDIR)/misc/atune-ui.service; \
|
sed -i "s?ExecStart=.*python3?ExecStart=$(PYDIR)?g" $(CURDIR)/misc/atune-ui.service; \
|
||||||
sed -i 's?".*python3"?"$(PYDIR)"?g' $(CURDIR)/common/service/pyservice/pyservice.go; \
|
|
||||||
else \
|
else \
|
||||||
echo "no python3 exists."; \
|
echo "no python3 exists."; \
|
||||||
fi
|
fi
|
||||||
@@ -94,6 +94,7 @@ libinstall:
|
|||||||
install -m 640 pkg/daemon_profile_server.so $(DESTDIR)$(PREFIX)/lib/atuned/modules
|
install -m 640 pkg/daemon_profile_server.so $(DESTDIR)$(PREFIX)/lib/atuned/modules
|
||||||
install -m 750 pkg/atune-adm $(BINDIR)
|
install -m 750 pkg/atune-adm $(BINDIR)
|
||||||
install -m 750 pkg/atuned $(BINDIR)
|
install -m 750 pkg/atuned $(BINDIR)
|
||||||
|
install -m 640 misc/atune-rest.service $(SYSTEMDDIR)
|
||||||
install -m 640 misc/atuned.service $(SYSTEMDDIR)
|
install -m 640 misc/atuned.service $(SYSTEMDDIR)
|
||||||
install -m 640 misc/atuned.cnf $(DESTDIR)/etc/atuned/
|
install -m 640 misc/atuned.cnf $(DESTDIR)/etc/atuned/
|
||||||
install -m 640 misc/engine.cnf $(DESTDIR)/etc/atuned/
|
install -m 640 misc/engine.cnf $(DESTDIR)/etc/atuned/
|
||||||
@@ -197,6 +198,7 @@ env:
|
|||||||
|
|
||||||
startup:
|
startup:
|
||||||
systemctl daemon-reload
|
systemctl daemon-reload
|
||||||
|
systemctl restart atune-rest
|
||||||
systemctl restart atuned
|
systemctl restart atuned
|
||||||
systemctl restart atune-engine
|
systemctl restart atune-engine
|
||||||
systemctl restart atune-ui
|
systemctl restart atune-ui
|
||||||
|
|||||||
@@ -211,12 +211,6 @@ func runatuned(ctx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := utils.WaitForPyservice(); err != nil {
|
|
||||||
log.Errorf("waiting for pyservice failed: %v", err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Info("pyservice has been started")
|
|
||||||
_, _ = daemon.SdNotify(false, "READY=1")
|
_, _ = daemon.SdNotify(false, "READY=1")
|
||||||
|
|
||||||
reflection.Register(s)
|
reflection.Register(s)
|
||||||
|
|||||||
@@ -15,6 +15,5 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
_ "gitee.com/openeuler/A-Tune/common/service/monitor"
|
_ "gitee.com/openeuler/A-Tune/common/service/monitor"
|
||||||
_ "gitee.com/openeuler/A-Tune/common/service/pyservice"
|
|
||||||
_ "gitee.com/openeuler/A-Tune/common/service/timer"
|
_ "gitee.com/openeuler/A-Tune/common/service/timer"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,100 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2019 Huawei Technologies Co., Ltd.
|
|
||||||
* A-Tune is licensed under the Mulan PSL v2.
|
|
||||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
|
||||||
* You may obtain a copy of Mulan PSL v2 at:
|
|
||||||
* http://license.coscl.org.cn/MulanPSL2
|
|
||||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
|
||||||
* PURPOSE.
|
|
||||||
* See the Mulan PSL v2 for more details.
|
|
||||||
* Create: 2019-10-29
|
|
||||||
*/
|
|
||||||
|
|
||||||
package pyservice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bufio"
|
|
||||||
"io"
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"os/signal"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"gitee.com/openeuler/A-Tune/common/config"
|
|
||||||
"gitee.com/openeuler/A-Tune/common/log"
|
|
||||||
"gitee.com/openeuler/A-Tune/common/registry"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
registry.RegisterDaemonService("pyengine", &PyEngine{})
|
|
||||||
}
|
|
||||||
|
|
||||||
// PyEngine : the struct store the pyEngine conf
|
|
||||||
type PyEngine struct {
|
|
||||||
Cfg *config.Cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
// Init method init the PyEngine service
|
|
||||||
func (p *PyEngine) Init() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the config of the monitor
|
|
||||||
func (p *PyEngine) Set(cfg *config.Cfg) {
|
|
||||||
p.Cfg = cfg
|
|
||||||
}
|
|
||||||
|
|
||||||
// Run method start the python service
|
|
||||||
func (p *PyEngine) Run() error {
|
|
||||||
cmdSlice := make([]string, 0)
|
|
||||||
cmdSlice = append(cmdSlice, "python3")
|
|
||||||
cmdSlice = append(cmdSlice, path.Join(config.DefaultAnalysisPath, "app_rest.py"))
|
|
||||||
cmdSlice = append(cmdSlice, path.Join(config.DefaultConfPath, "atuned.cnf"))
|
|
||||||
|
|
||||||
cmdStr := strings.Join(cmdSlice, " ")
|
|
||||||
log.Debugf("start pyservice: %s", cmdStr)
|
|
||||||
cmd := exec.Command("sh", "-c", cmdStr)
|
|
||||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
|
|
||||||
|
|
||||||
stdout, _ := cmd.StdoutPipe()
|
|
||||||
stderr, _ := cmd.StderrPipe()
|
|
||||||
|
|
||||||
go listenToSystemSignals(cmd)
|
|
||||||
go logStdout(stdout)
|
|
||||||
go logStdout(stderr)
|
|
||||||
|
|
||||||
err := cmd.Start()
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("cmd.Start() analysis service failed: %v", err)
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = cmd.Wait()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("cmd.Run() analysis failed with: %v", err)
|
|
||||||
os.Exit(-1)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func logStdout(stdout io.ReadCloser) {
|
|
||||||
scanner := bufio.NewScanner(stdout)
|
|
||||||
for scanner.Scan() {
|
|
||||||
line := scanner.Text()
|
|
||||||
log.Debug(line)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func listenToSystemSignals(cmd *exec.Cmd) {
|
|
||||||
signalChan := make(chan os.Signal, 1)
|
|
||||||
|
|
||||||
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
|
|
||||||
<-signalChan
|
|
||||||
_ = syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
|
|
||||||
os.Exit(100)
|
|
||||||
}
|
|
||||||
10
misc/atune-rest.service
Normal file
10
misc/atune-rest.service
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=A-Tune AI service
|
||||||
|
After=network.target
|
||||||
|
Requires=polkit.service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStart=python3 /usr/libexec/atuned/analysis/app_rest.py /etc/atuned/atuned.cnf
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[Unit]
|
[Unit]
|
||||||
Description=A-Tune Daemon
|
Description=A-Tune Daemon
|
||||||
After=systemd-sysctl.service network.target
|
After=systemd-sysctl.service network.target atune-rest.service
|
||||||
Requires=polkit.service
|
Requires=polkit.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
|
|||||||
Reference in New Issue
Block a user