Skip to content

fix(gitlab-shell): gitlab-shell graceful term

Steve Xuereb requested to merge fix/gitlab-shell-pid into master

What does this MR do?

What

Move gitlab-shell process to PID 1 by using exec in start up script and CMD in exec form as well.

Why

GitLab-shell (SSHD) supports graceful termination on SIGTERM. SIGTERM is sent to PID 1 automatically to the container by Kubernetes, however gitlab-shell is not PID 1 since it's wrapped in the /scripts/process-wrapper and CMD in the Dockerfile uses the shell form

Process tree before:

git@gitlab-gitlab-shell-77cf75d847-lnflg:/$ ps faux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
git         4720  1.0  0.0   5996  3808 pts/0    Ss   08:30   0:00 bash
git         4729  0.0  0.0   8592  3188 pts/0    R+   08:30   0:00  \_ ps faux
git            1  0.0  0.0   2420   524 ?        Ss   07:19   0:00 /bin/sh -c "/scripts/process-wrapper"
git           14  0.0  0.0   5868  3472 ?        S    07:19   0:00 /bin/bash /scripts/process-wrapper
git           18  0.0  0.0   4256   508 ?        S    07:19   0:00  \_ tail -f /var/log/gitlab-shell/gitlab-shell.log /var/log/gitlab-shell/ssh.log
git           19  0.0  0.0  13292  7556 ?        S    07:19   0:00  \_ sshd: /usr/sbin/sshd -D -E /var/log/gitlab-shell/ssh.log [listener] 0 of 10-100 startups

Process tree after:

git@gitlab-gitlab-shell-695dd8fdcb-srw6j:/$ ps faux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
git           28  0.5  0.0   5992  3744 pts/0    Ss   09:05   0:00 bash
git           35  0.0  0.0   8592  3312 pts/0    R+   09:05   0:00  \_ ps faux
git            1  0.2  0.0  13292  7456 ?        Ss   09:04   0:00 sshd: /usr/sbin/sshd -D -E /var/log/gitlab-shell/ssh.log [listener] 0 of 10-100 startups
git           17  0.0  0.0   4256   508 ?        S    09:04   0:00 tail -f /var/log/gitlab-shell/gitlab-shell.log /var/log/gitlab-shell/ssh.log

Related issues

Reference: gitlab-org/charts/gitlab#3249 (closed)

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion

Required

  • Merge Request Title, and Description are up to date, accurate, and descriptive
  • MR targeting the appropriate branch
  • MR has a green pipeline on GitLab.com

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes
  • Documentation created/updated
  • Integration tests added to GitLab QA
  • The impact any change in container size has should be evaluated
Edited by Steve Xuereb

Merge request reports