diff --git a/cli/cmd/logrotate.go b/cli/cmd/logrotate.go index d6594da08..00b70f484 100644 --- a/cli/cmd/logrotate.go +++ b/cli/cmd/logrotate.go @@ -47,11 +47,10 @@ func internalLogrotateModule(cmdCtx *cmdcontext.CmdCtx, args []string) error { } for _, run := range runningCtx.Instances { - res, err := running.Logrotate(&run) + err := running.Logrotate(&run) if err != nil { - return err + log.Infof(err.Error()) } - log.Info(res) } return nil diff --git a/cli/running/running.go b/cli/running/running.go index ddbd455c5..995db03ea 100644 --- a/cli/running/running.go +++ b/cli/running/running.go @@ -858,24 +858,27 @@ func Status(run *InstanceCtx) process_utils.ProcessState { } // Logrotate rotates logs of a started tarantool instance. -func Logrotate(run *InstanceCtx) (string, error) { +func Logrotate(run *InstanceCtx) error { + fullInstanceName := GetAppInstanceName(*run) + pid, err := process_utils.GetPIDFromFile(run.PIDFile) if err != nil { - return "", errors.New(instStateStopped.String()) + return fmt.Errorf("%s: the instance is not running, it must be started", fullInstanceName) } alive, err := process_utils.IsProcessAlive(pid) if !alive { - return "", errors.New(instStateDead.String()) + return errors.New(instStateDead.String()) } if err := syscall.Kill(pid, syscall.Signal(syscall.SIGHUP)); err != nil { - return "", fmt.Errorf(`can't rotate logs: "%v"`, err) + return fmt.Errorf(`can't rotate logs: "%v"`, err) } // Rotates logs [instance name pid] - fullInstanceName := GetAppInstanceName(*run) - return fmt.Sprintf("%s: logs has been rotated. PID: %v.", fullInstanceName, pid), nil + log.Infof("%s (PID = %v): logs has been rotated.", fullInstanceName, pid) + + return nil } // Check returns the result of checking the syntax of the application file. diff --git a/test/integration/logrotate/test_logrotate.py b/test/integration/logrotate/test_logrotate.py index 4f2810b3c..e3fbed62d 100644 --- a/test/integration/logrotate/test_logrotate.py +++ b/test/integration/logrotate/test_logrotate.py @@ -30,31 +30,26 @@ def post_start(tt_app, instances): # Do logrotate. rc, out = tt_app.logrotate(target) - - # If any of the requested instances is not running return failure. - for inst in tt_app.instances_of(target): - if not tt_app.is_instance_of(inst, *running_targets): - assert rc != 0 - assert "NOT RUNNING" in out - return + assert rc == 0 # Wait for the log files to be re-created. tt_app_wait_log_files(tt_app, tt_app.instances_of(target)) # Check the instances. - assert rc == 0 status = tt_app.status() for inst in tt_app.instances: inst_id = tt_app.inst_id(inst) was_running = tt_app.is_instance_of(inst, *running_targets) if tt_app.is_instance_of(inst, target): - assert was_running - assert status[inst_id]["STATUS"] == "RUNNING" - assert status[inst_id]["PID"] == orig_status[inst_id]["PID"] - pid = status[inst_id]["PID"] - assert f"{inst_id}: logs has been rotated. PID: {pid}" in out - with open(tt_app.log_path(inst, log_file)) as f: - assert "reopened" in f.read() + if was_running: + assert status[inst_id]["STATUS"] == "RUNNING" + pid = status[inst_id]["PID"] + assert pid == orig_status[inst_id]["PID"] + assert f"{inst_id} (PID = {pid}): logs has been rotated." in out + with open(tt_app.log_path(inst, log_file)) as f: + assert "reopened" in f.read() + else: + assert f"{inst_id}: the instance is not running, it must be started" in out else: assert inst_id not in out assert status[inst_id]["STATUS"] == orig_status[inst_id]["STATUS"]