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

Server service does not restart automatically when any configuration files change #11180

Closed
Kennybll opened this issue Oct 27, 2024 · 1 comment

Comments

@Kennybll
Copy link

Environmental Info:
K3s Version: v1.30.5+k3s1 (9b58670)

Node(s) CPU architecture, OS, and Version:
Linux ubuntu-2gb-ash-1 6.8.0-45-generic #45-Ubuntu SMP PREEMPT_DYNAMIC Fri Aug 30 12:02:04 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Cluster Configuration:
1 server

Describe the bug:
Whenever a cli flag changes when rerunning the server binary, the service will restart. This makes sense as there was a change in the configuration so it has to restart to apply those changes. However if there is a change in any of the configuration files, either /etc/rancher/k3s/config.yaml or /etc/rancher/k3s/config.yaml.d/*.yaml, the service does not restart so the changes do not get applied automatically. The user must then manually restart the service.

Steps To Reproduce:

mkdir -p /etc/rancher/k3s/config.yaml.d

cat > /etc/rancher/k3s/config.yaml.d/snapshot.yaml <<EOF
etcd-snapshot-schedule-cron: "* * * * *"
EOF

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server" sh -s - --cluster-init

cat > /etc/rancher/k3s/config.yaml.d/snapshot.yaml <<EOF
etcd-snapshot-schedule-cron: "0 */12 * * *"
EOF

curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="server" sh -s - --cluster-init

Expected behavior:
The systemd server should restart since a config file has changed. Whenever any of the config files change, the service should restart.

[INFO]  Finding release for channel stable
[INFO]  Using v1.30.5+k3s1 as release
[INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.30.5+k3s1/sha256sum-amd64.txt
[INFO]  Skipping binary downloaded, installed k3s matches hash
[INFO]  Skipping installation of SELinux RPM
[INFO]  Skipping /usr/local/bin/kubectl symlink to k3s, already exists
[INFO]  Skipping /usr/local/bin/crictl symlink to k3s, already exists
[INFO]  Skipping /usr/local/bin/ctr symlink to k3s, already exists
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
[INFO]  systemd: Starting k3s

Actual behavior:
The service does not restart.

[INFO]  Finding release for channel stable
[INFO]  Using v1.30.5+k3s1 as release
[INFO]  Downloading hash https://github.com/k3s-io/k3s/releases/download/v1.30.5+k3s1/sha256sum-amd64.txt
[INFO]  Skipping binary downloaded, installed k3s matches hash
[INFO]  Skipping installation of SELinux RPM
[INFO]  Skipping /usr/local/bin/kubectl symlink to k3s, already exists
[INFO]  Skipping /usr/local/bin/crictl symlink to k3s, already exists
[INFO]  Skipping /usr/local/bin/ctr symlink to k3s, already exists
[INFO]  Creating killall script /usr/local/bin/k3s-killall.sh
[INFO]  Creating uninstall script /usr/local/bin/k3s-uninstall.sh
[INFO]  env: Creating environment file /etc/systemd/system/k3s.service.env
[INFO]  systemd: Creating service file /etc/systemd/system/k3s.service
[INFO]  systemd: Enabling k3s unit
Created symlink /etc/systemd/system/multi-user.target.wants/k3s.service → /etc/systemd/system/k3s.service.
[INFO]  No change detected so skipping service start

Since the service didn't restart automatically the original snapshot-cron value stays the same, and the new value does not get applied.

Additional context / logs:
Currently when deciding to restart the service it will compare the hash of the created service file and the env file

$SUDO sha256sum ${BIN_DIR}/k3s ${FILE_K3S_SERVICE} ${FILE_K3S_ENV} 2>&1 || true

Proposed change to package/rpm/install.sh which includes any config files:

get_installed_hashes() {
    files="${BIN_DIR}/k3s ${FILE_K3S_SERVICE} ${FILE_K3S_ENV}"
    
    # Check if config.yaml exists, and if so, add it to the files list
    [ -f ${CONFIG_DIR}/config.yaml ] && files+=" ${CONFIG_DIR}/config.yaml"
    
    # Check if the config.yaml.d directory exists and has any .yaml files
    if [ -d ${CONFIG_DIR}/config.yaml.d ] && compgen -G "${CONFIG_DIR}/config.yaml.d/*.yaml" > /dev/null; then
        files+=" ${CONFIG_DIR}/config.yaml.d/*.yaml"
    fi

    # Compute the SHA256 checksums of the listed files
    $SUDO sha256sum $files 2>&1 || true
}
@brandond
Copy link
Member

brandond commented Oct 28, 2024

The install script doesn't manage the contents of the config files, or env files other than the one it creates, and makes no attempt to restart the service when their contents change. This is by design; we have no plans to make the install script restart the service if the contents of files it does not manage change.

@github-project-automation github-project-automation bot moved this from New to Done Issue in K3s Development Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done Issue
Development

No branches or pull requests

2 participants