Skip to content

Commit 813fe44

Browse files
Add acpid service: (#274)
## Description <!--- Please describe what this PR is going to change --> This service allows HookOS to react to ACPI events. Useful for things like `ipmitool chassis power soft`. ## Why is this needed <!--- Link to issue you have raised --> Fixes: # ## How Has This Been Tested? <!--- Please describe in detail how you tested your changes. --> <!--- Include details of your testing environment, and the tests you ran to --> <!--- see how your change affects other areas of the code, etc. --> ## How are existing users impacted? What migration steps/scripts do we need? <!--- Fixes a bug, unblocks installation, removes a component of the stack etc --> <!--- Requires a DB migration script, etc. --> ## Checklist: I have: - [ ] updated the documentation and/or roadmap (if required) - [ ] added unit or e2e tests - [ ] provided instructions on how to upgrade
2 parents abe190b + 4a4d42b commit 813fe44

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ images/hook-embedded/docker/*
2020
!images/hook-embedded/docker/.keep
2121
images/hook-embedded/images_tar/*
2222
!images/hook-embedded/images_tar/.keep
23+
scratch/

bash/hook-lk-containers.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ function build_all_hook_linuxkit_containers() {
1010
build_hook_linuxkit_container hook-bootkit "HOOK_CONTAINER_BOOTKIT_IMAGE"
1111
build_hook_linuxkit_container hook-docker "HOOK_CONTAINER_DOCKER_IMAGE"
1212
build_hook_linuxkit_container hook-udev "HOOK_CONTAINER_UDEV_IMAGE"
13+
build_hook_linuxkit_container hook-acpid "HOOK_CONTAINER_ACPID_IMAGE"
1314
build_hook_linuxkit_container hook-containerd "HOOK_CONTAINER_CONTAINERD_IMAGE"
1415
build_hook_linuxkit_container hook-runc "HOOK_CONTAINER_RUNC_IMAGE"
1516
build_hook_linuxkit_container hook-embedded "HOOK_CONTAINER_EMBEDDED_IMAGE"

images/hook-acpid/Dockerfile

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# We are building a static acpid binary from source because the linuxkit/acpid image
2+
# does not work
3+
FROM alpine:3.22 AS alpine
4+
5+
# Install build dependencies
6+
RUN apk add --no-cache \
7+
gcc \
8+
musl-dev \
9+
make \
10+
git \
11+
autoconf \
12+
automake \
13+
libtool \
14+
linux-headers \
15+
wget \
16+
xz \
17+
patch \
18+
busybox-static \
19+
# Install the dynamically built acpid so that we can get the handler script and event files
20+
acpid
21+
22+
# Download and build acpid
23+
ENV ACPID_VERSION=2.0.34
24+
RUN wget https://sourceforge.net/projects/acpid2/files/acpid-${ACPID_VERSION}.tar.xz/download -O acpid-${ACPID_VERSION}.tar.xz && \
25+
tar -xf acpid-${ACPID_VERSION}.tar.xz
26+
27+
WORKDIR /acpid-${ACPID_VERSION}
28+
29+
# Fix musl compatibility - replace stat64/fstat64 with stat/fstat
30+
RUN sed -i 's/struct stat64/struct stat/g' sock.c && \
31+
sed -i 's/fstat64/fstat/g' sock.c
32+
33+
# Build static binary with musl-compatible flags
34+
RUN ./configure \
35+
--enable-static \
36+
--disable-shared \
37+
CFLAGS="-D_GNU_SOURCE -Os" \
38+
LDFLAGS="-static" && \
39+
make && \
40+
strip acpid && \
41+
cp acpid /usr/bin/
42+
43+
# Verify it's statically linked
44+
RUN ldd /usr/bin/acpid 2>&1 | grep -q "not a dynamic executable" || echo "Warning: not statically linked"
45+
46+
# Copy BusyBox static binary and create poweroff symlink
47+
RUN mkdir -p /stage/bin && cp /bin/busybox.static /bin/busybox && \
48+
ln -s /bin/busybox /stage/bin/poweroff && \
49+
ln -s /bin/busybox /stage/bin/logger && \
50+
# This is needed for the acpid handler scripts (/etc/acpi/handler.sh, /etc/acpi/events/anything) to work
51+
ln -s /bin/busybox /stage/bin/sh
52+
53+
FROM scratch
54+
WORKDIR /
55+
ENTRYPOINT []
56+
COPY --from=alpine /usr/bin/acpid /usr/bin/
57+
COPY --from=alpine /etc/acpi/events/anything /etc/acpi/events/anything
58+
COPY --from=alpine /etc/acpi/handler.sh /etc/acpi/handler.sh
59+
COPY --from=alpine /bin/busybox /bin/busybox
60+
COPY --from=alpine /stage/ /
61+
CMD ["/usr/bin/acpid", "-f", "-d"]

linuxkit-templates/hook.template.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# - HOOK_CONTAINER_BOOTKIT_IMAGE: ${HOOK_CONTAINER_BOOTKIT_IMAGE}
77
# - HOOK_CONTAINER_DOCKER_IMAGE: ${HOOK_CONTAINER_DOCKER_IMAGE}
88
# - HOOK_CONTAINER_UDEV_IMAGE: ${HOOK_CONTAINER_UDEV_IMAGE}
9+
# - HOOK_CONTAINER_ACPID_IMAGE: ${HOOK_CONTAINER_ACPID_IMAGE}
910
# - HOOK_CONTAINER_CONTAINERD_IMAGE: ${HOOK_CONTAINER_CONTAINERD_IMAGE}
1011
# - HOOK_CONTAINER_RUNC_IMAGE: ${HOOK_CONTAINER_RUNC_IMAGE}
1112
# - HOOK_CONTAINER_EMBEDDED_IMAGE: ${HOOK_CONTAINER_EMBEDDED_IMAGE}
@@ -78,6 +79,20 @@ services:
7879
- name: ntpd
7980
image: linuxkit/openntpd:v1.0.0
8081

82+
- name: acpi
83+
image: "${HOOK_CONTAINER_ACPID_IMAGE}"
84+
capabilities:
85+
- all
86+
pid: host
87+
binds.add:
88+
- /dev:/dev
89+
- /var/run:/var/run
90+
devices:
91+
- path: all
92+
type: b
93+
- path: all
94+
type: c
95+
8196
- name: getty
8297
image: linuxkit/getty:v1.0.0
8398
capabilities:

0 commit comments

Comments
 (0)