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 Sysbox Services on Failure #12

Merged
merged 5 commits into from
Mar 26, 2024
Merged
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
15 changes: 15 additions & 0 deletions sysbox-eks.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ build {
]
}

provisioner "file" {
source = "systemd"
destination = "/home/ubuntu"
}

provisioner "shell" {
inline_shebang = "/usr/bin/env bash"
inline = [
"echo '>>> Configuring Systemd for Sysbox'",
"sudo mv /home/ubuntu/systemd/system/sysbox-mgr.service /lib/systemd/system/sysbox-mgr.service",
"sudo mv /home/ubuntu/systemd/system/sysbox-fs.service /lib/systemd/system/sysbox-fs.service",
"sudo mv /home/ubuntu/systemd/system/sysbox.service /lib/systemd/system/sysbox.service",
]
}

provisioner "shell" {
inline_shebang = "/usr/bin/env bash"
inline = [
Expand Down
24 changes: 24 additions & 0 deletions systemd/system/sysbox-fs.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[Unit]
Description=sysbox-fs (part of the Sysbox container runtime)
PartOf=sysbox.service
After=sysbox-mgr.service

[Service]
Type=simple
Type=notify
ExecStart=/usr/bin/sysbox-fs
Restart=always
TimeoutStartSec=10
TimeoutStopSec=10
StartLimitInterval=0
NotifyAccess=main
OOMScoreAdjust=-500

# The number of files opened by sysbox-fs is a function of the number of
# containers and the workloads within them. Thus we set the limit to
# infinite so to prevent "too many open files" errors.
LimitNOFILE=infinity
LimitNPROC=infinity

[Install]
WantedBy=sysbox.service
23 changes: 23 additions & 0 deletions systemd/system/sysbox-mgr.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[Unit]
Description=sysbox-mgr (part of the Sysbox container runtime)
PartOf=sysbox.service

[Service]
Type=simple
Type=notify
ExecStart=/usr/bin/sysbox-mgr
Restart=always
TimeoutStartSec=45
TimeoutStopSec=90
StartLimitInterval=0
NotifyAccess=main
OOMScoreAdjust=-500

# The number of files opened by sysbox-mgr is a function of the number of
# containers and the size of the rootfs within them. Thus we set the limit to
# infinite so to prevent "too many open files" errors.
LimitNOFILE=infinity
LimitNPROC=infinity

[Install]
WantedBy=sysbox.service
26 changes: 26 additions & 0 deletions systemd/system/sysbox.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Sysbox unit to act as a wrapper of sysbox's inner components/daemons:
# sysbox-mgr and sysbox-fs.

[Unit]
Description=Sysbox container runtime
Documentation=https://github.com/nestybox/sysbox
# rahul: using BindsTo + PartOf prevents the services that are bound
# from restarting on failure. For example, if sysbox-mgr.service is
# killed, sysbox.service will stop because of the 'BindsTo' constraint.
# However, because sysbox-mgr.service is 'PartOf' sysbox.service,
# sysbox-mgr.service will not restart until sysbox.service has started
# BindsTo=sysbox-mgr.service sysbox-fs.service
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers: note this change to service file, restarts don't work without removing the BindsTo constraint
The effect of this is that if sysbox-mgr or sysbox-fs stop/restart, sysbox.service won't. I don't think this is an issue but just flagging

After=sysbox-mgr.service sysbox-fs.service

# Must start before Docker/containerd to ensure "docker --restart" works
# properly with Sysbox.
Before=docker.service containerd.service

[Service]
Type=exec
ExecStart=/bin/sh -c "/usr/bin/sysbox-runc --version && /usr/bin/sysbox-mgr --version && /usr/bin/sysbox-fs --version && /bin/sleep infinity"
Restart=always

[Install]
# Components of this application should be started at boot time
WantedBy=multi-user.target
Loading