Unable to add systemd

I am trying to add systemd on our image and I am using this example from github, but the service isnt starting after it was downloaded. I’m not sure how to go about solving this as I am fairly inexperienced.

here is my docker.template
FROM balenalib/%%BALENA_MACHINE_NAME%%-node:12.14.0-buster-build

#################
# Install Systemd
#################
ENV container docker
RUN apt-get update && apt-get install -y --no-install-recommends \
	systemd \
    systemd-sysv \
	&& rm -rf /var/lib/apt/lists/*

# We never want these to run in a container
# Feel free to edit the list but this is the one we used
RUN systemctl mask \
    dev-hugepages.mount \
    sys-fs-fuse-connections.mount \
    sys-kernel-config.mount \

    display-manager.service \
    getty@.service \
    systemd-logind.service \
    systemd-remount-fs.service \

    getty.target \
    graphical.target

COPY resin/entry.sh /usr/bin/entry.sh
COPY resin/balena.service /etc/systemd/system/balena.service

RUN systemctl enable /etc/systemd/system/balena.service

STOPSIGNAL 37
ENTRYPOINT ["/usr/bin/entry.sh"]

######################
# Finish setup systemd
######################


# Defines our working directory in container
WORKDIR /usr/src/app

# This will copy all files in our root to the working  directory in the container
COPY . ./

# Set the timezone
RUN ./resin/timezone.sh

ENV UDEV=1
# use apt-get if you need to install dependencies,
RUN apt-get update && apt-get install -yq \
    libudev-dev libusb-1.0-0-dev vim python libpython2.7 && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PlatformIO
RUN python -c "$(curl -fsSL https://raw.githubusercontent.com/platformio/platformio/develop/scripts/get-platformio.py)"

# Install Gulp
RUN npm install -g gulp

CMD ["bash", "./resin/start.sh"]

Hi, there is a section of the services masterclass here https://www.balena.io/docs/learn/more/masterclasses/services-masterclass/#5-running-systemd-in-a-service that has a walk-through of running systemd in a container. Perhaps, if you start with that example and get it working you can add incrementally add the custom portions to your Dockerfile?

Also does your use-case specifically require running systemd in a container?

1 Like

hi @garethtdavies thanks for the reply. Our use-case involves using systemctl to mask/unmask udev while flashing to a device. What other alternative can we do in Balena if we dont have systemd in our image?

Hi there, just to go back a step - your Dockerfile looks reasonable, but one more thing to check if you are setting INITSYSTEM=on environment variable on your container? This drives the behaviour whether to pass control to your app or to systemd running in the container.