Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMM-13409 Fix update status failure after upgrade #3234

Open
wants to merge 7 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion build/ansible/roles/initialization/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
method: GET
retries: 20
delay: 5
ignore_errors: yes
ignore_errors: true

- name: init admin password on AMI
include_role:
Expand All @@ -139,4 +139,9 @@
file:
state: absent
path: /usr/share/pmm-server/maintenance/maintenance.html

- name: Remove the file provisioned by 'getStatus'
file:
state: absent
path: /srv/pmm-update.json
when: need_initialization or need_upgrade
16 changes: 10 additions & 6 deletions managed/services/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type Params struct {

// NewServer returns new server for Server service.
func NewServer(params *Params) (*Server, error) {
path := os.TempDir()
path := "/srv"
if _, err := os.Stat(path); err != nil {
return nil, errors.WithStack(err)
}
Expand Down Expand Up @@ -359,6 +359,12 @@ func (s *Server) StartUpdate(ctx context.Context, req *serverv1.StartUpdateReque

// UpdateStatus returns PMM Server update status.
func (s *Server) UpdateStatus(ctx context.Context, req *serverv1.UpdateStatusRequest) (*serverv1.UpdateStatusResponse, error) {
if _, err := os.Stat(s.pmmUpdateAuthFile); err != nil && os.IsNotExist(err) {
return &serverv1.UpdateStatusResponse{
Done: true,
}, nil
}

token, err := s.readUpdateAuthToken()
if err != nil {
return nil, err
Expand All @@ -370,12 +376,10 @@ func (s *Server) UpdateStatus(ctx context.Context, req *serverv1.UpdateStatusReq
// wait up to 30 seconds for new log lines
var lines []string
var newOffset uint32
var done bool
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
defer cancel()
for ctx.Err() == nil {
done = !s.updater.IsRunning()
if done {
if !s.updater.IsRunning() {
// give supervisord a second to flush logs to file
time.Sleep(time.Second)
}
Expand All @@ -385,7 +389,7 @@ func (s *Server) UpdateStatus(ctx context.Context, req *serverv1.UpdateStatusReq
s.l.Warn(err)
}

if len(lines) != 0 || done {
if len(lines) != 0 {
break
}

Expand All @@ -395,7 +399,7 @@ func (s *Server) UpdateStatus(ctx context.Context, req *serverv1.UpdateStatusReq
return &serverv1.UpdateStatusResponse{
LogLines: lines,
LogOffset: newOffset,
Done: done,
Done: false,
}, nil
}

Expand Down
1 change: 0 additions & 1 deletion managed/services/server/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ func (up *Updater) latest(ctx context.Context) ([]*version.DockerVersionInfo, *v
}

func (up *Updater) readFromFile() (*version.DockerVersionInfo, error) {
// Read from file, if it's not exist read from ENV variable, if it's not exist get the latest tag from DockerHub.
content, err := os.ReadFile(fileName)
if err != nil && !os.IsNotExist(err) {
up.l.WithError(err).Error("Failed to read file")
Expand Down
Loading