Skip to content

Commit a247a3d

Browse files
onyxmasterhalter73
authored andcommitted
Attempting to fix systemd activation with minimal changes (#1925)
1 parent be1605a commit a247a3d

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,4 @@ before_install:
2828
- if test "$TRAVIS_OS_NAME" == "osx"; then brew update; brew install openssl; ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/; ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/; fi
2929
script:
3030
- ./build.sh
31-
# Temporarily disabled systemd activation test: https://github.com/aspnet/KestrelHttpServer/issues/1912#issuecomment-311162419
32-
# - if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi
31+
- if test "$TRAVIS_OS_NAME" != "osx"; then bash test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/docker.sh; fi

test/Microsoft.AspNetCore.Server.Kestrel.FunctionalTests/SystemdActivation/Dockerfile

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,34 @@ FROM microsoft/dotnet-nightly:2.0-runtime-deps
33
# The "container" environment variable is read by systemd.
44
ENV container=docker
55

6-
# This is required by systemd and won't work without "dotnet run --privileged".
7-
VOLUME ["/sys/fs/cgroup"]
6+
# Install and configure systemd which requires dbus for graceful shutdown.
7+
RUN ["apt-get", "-o", "Acquire::Check-Valid-Until=false", "update"]
8+
RUN ["apt-get", "install", "-y", "--no-install-recommends", "systemd-sysv"]
9+
10+
# Set proper systemd default target.
11+
RUN ["systemctl", "set-default", "multi-user.target"]
12+
13+
# Remove non-vital systemd services.
14+
RUN ["find", "/etc/systemd/system", "/lib/systemd/system", \
15+
"-path", "*.wants/*", \
16+
"-not", "-name", "*systemd-journald*", \
17+
"-not", "-name", "*systemd-tmpfiles*", \
18+
"-not", "-name", "*systemd-user-sessions*", \
19+
"-delete"]
20+
21+
# Copy .NET installation.
22+
ADD .dotnet/ /usr/share/dotnet/
23+
RUN ["ln", "-s", "/usr/share/dotnet/dotnet", "/usr/bin/dotnet"]
824

925
# Create activate-kestrel.service to launch the "publish" app on new requests to 8080.
1026
EXPOSE 8080
11-
ADD .dotnet/ /usr/share/dotnet/
1227
ADD publish/ /publish/
13-
ADD activate-kestrel.socket /etc/systemd/system/activate-kestrel.socket
1428
ADD activate-kestrel.service /etc/systemd/system/activate-kestrel.service
29+
ADD activate-kestrel.socket /etc/systemd/system/activate-kestrel.socket
1530

16-
# Install and configure systemd which requires dbus for graceful shutdown.
17-
RUN ["apt-get", "-o", "Acquire::Check-Valid-Until=false", "update"]
18-
RUN ["apt-get", "install", "-y", "dbus"]
19-
RUN ["systemctl", "mask", "getty.target", "console-getty.service"]
20-
RUN ["cp", "/lib/systemd/system/dbus.service", "/etc/systemd/system/"]
21-
RUN ["sed", "-i", "s/OOMScoreAdjust=-900//", "/etc/systemd/system/dbus.service"]
22-
23-
# Automatically start activate-kestrel.service on boot.
24-
RUN ["ln", "-s", "/usr/share/dotnet/dotnet", "/usr/bin/dotnet"]
25-
RUN ["ln", "-s", "/usr/lib/systemd/system/activate-kestrel.service", "/etc/systemd/system/multi-user.target.wants/activate-kestrel.service"]
31+
# Automatically start activate-kestrel.socket on boot.
32+
RUN ["systemctl", "enable", "activate-kestrel.socket"]
2633

27-
# Launch systemd.
28-
CMD ["/sbin/init"]
34+
# Launch systemd, with workaround for docker/docker#27202, technique based on comments from docker/docker#9212.
35+
CMD ["/bin/bash", "-c", "exec /sbin/init --log-target=journal 3>&1"]
36+
STOPSIGNAL SIGRTMIN+3
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[Unit]
2-
Description=Kestrel Activation
2+
PartOf=activate-kestrel.service
33

44
[Socket]
55
ListenStream=8080
66
NoDelay=true
77

8+
[Install]
9+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)