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

Restart long-running systemd services #2162

Merged
merged 1 commit into from
Jun 3, 2022

Conversation

arnaldo2792
Copy link
Contributor

@arnaldo2792 arnaldo2792 commented May 31, 2022

Issue number:
N / A

Description of changes:

packages: restart long-running systemd services

This adds the 'Restart' and 'RestartSec' directives to the following
services since they must be running even if they exit or are killed by
the OS:

- acpid
- vmtoolsd
- apiserver

Testing done:
I executed this script from the admin container to confirm that the services were restarted after the main process was killed:

SYSTEMCTL_CMD="chroot /.bottlerocket/rootfs /usr/bin/systemctl"
KILL_CMD="chroot /.bottlerocket/rootfs /usr/bin/kill"
SERVICES="acpid  apiserver"

get_pid() {
    local service
    service="${1}"
    ${SYSTEMCTL_CMD} show "${service}" | grep -E '^ExecMainPID' | awk ' { split($0,a,"="); print a[2] } '
}

for s in ${SERVICES}; do
    OLD_PID=$(get_pid "${s}")
    echo "OLD PID for ${s} is ${OLD_PID}"
    ${KILL_CMD} -9 ${OLD_PID}
    # Sleep a little longer than it takes for the service to restart
    sleep 7
    NEW_PID=$(get_pid "${s}")
    echo "NEW PID for ${s} is ${NEW_PID}"
done

Output:

OLD PID for acpid is 2291
NEW PID for acpid is 2768
OLD PID for apiserver is 2302
NEW PID for apiserver is 2779

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

@jpculp
Copy link
Member

jpculp commented May 31, 2022

If we're going to have it always restart, we might want to set some "start limits" to avoid restarting too many times too quickly if something is amiss.

This adds the 'Restart' and 'RestartSec' directives to the following
services since they must be running even if they exit or are killed by
the OS:

- acpid
- vmtoolsd
- apiserver

Signed-off-by: Arnaldo Garcia Rincon <[email protected]>
@arnaldo2792
Copy link
Contributor Author

arnaldo2792 commented Jun 2, 2022

Forced push includes:

@arnaldo2792 arnaldo2792 merged commit d2fff55 into bottlerocket-os:develop Jun 3, 2022
@arnaldo2792 arnaldo2792 deleted the restart-services branch June 7, 2022 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants