1

So I've been configuring this Docker setup to run a simple service on Linux. The service uses the systemd watchdog and the sdnotify python library to ensure the service doesn't freeze. My problem is that the notify doesn't seem to get out of the docker VM to systemd and the watchdog always timeout. Here's my service:

[Unit]
Description=My Service
After=docker.service
Requires=docker.service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
WatchdogSec=190
TimeoutStartSec=0
NotifyAccess=all
User=root
WorkingDirectory=/root
ExecStartPre=-/usr/bin/docker stop my-container
ExecStartPre=-/usr/bin/docker rm my-container
ExecStartPre=-/bin/bash docker_build.sh
ExecStart=/bin/bash docker_start.sh

[Install]
WantedBy=multi-user.target

I start the container using:

docker run -t --name my-container --privileged my-service

My dockerfile looks like this:

FROM python:3.6.9

# Open MQTT and HTTPS ports
EXPOSE 443 8883

COPY requirements.txt requirements.txt
RUN python -m pip install -U -r requirements.txt

CMD python -u -m service_module

Output:

May 05 13:31:55 DIET bash[11155]: [SO][Build Date]: 0.1-V-20200122h13:09
May 05 13:31:55 DIET bash[11155]: [SYS][INFO][17:31:55]: Serial port opened on: /dev/ttyS1
May 05 13:31:56 DIET bash[11155]: [GOOGLE][INFO][17:31:56]: Sent message: {'ip': ['x'], 'versions': {}, 'temperature': 37.793, 'cpu': 15.1, 'memory': 47.7, 'net': {'out': 7.95, 'in': 95.587}}
May 05 13:33:37 DIET systemd[1]: my.service: Watchdog timeout (limit 3min 10s)!
May 05 13:33:37 DIET systemd[1]: my.service: Killing process 11155 (bash) with signal SIGABRT.
May 05 13:33:37 DIET systemd[1]: my.service: Killing process 11157 (docker) with signal SIGABRT.
May 05 13:33:37 DIET systemd[1]: my.service: Main process exited, code=killed, status=6/ABRT
May 05 13:34:53 DIET bash[11155]: [GOOGLE][INFO][17:34:53]: Sent message: {'ip': ['x'], 'versions': {}, 'temperature': 33.916, 'cpu': 0.9, 'memory': 47.8, 'net': {'out': 9.882, 'in': 6.336}}

The notify is sent when the '[GOOGLE][INFO]' lines are shown. There is only about 2 minutes between the first one and the timeout meaning it never got reset. Thanks in advance !

EDIT: Running this service outside of docker works properly.

0

I have fixed it using sdnotify-proxy. I changed my starting command for this:

/usr/local/bin/sdnotify-proxy /run/my-sd.sock \
    /usr/bin/docker run -t --name my-container --volume /run/my-sd.sock:/run/my-sd.sock \
    --env NOTIFY_SOCKET=/run/my-sd.sock --privileged my
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.