- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们目前在一台主机上运行着许多不同的服务,我们正在广泛使用 systemd,包括用于消息传递的 systemd-notify 和用于服务管理的自己的前端。
我们希望开始在容器内运行这些服务,以简化依赖管理并同时运行多个版本进行测试。我们想要:
请注意;大多数问题都是关于在 docker 容器中运行 systemd 的。这不是这个问题的意思。相反,我想在 systemd 中运行一个(docker?)容器。
最佳答案
我们采用了以下解决方案:
我们决定使用 Podman . Podman 是 RunC 的包装器,其 CLI 工具已调整为 Docker 的直接替代品。然而,因为它不是在守护进程下运行容器(无论如何我更喜欢它),所以几乎不需要任何管道来使 systemd-notify 工作。
只需在 sytemd 服务文件中指定 Environment=NOTIFY_SOCKET=/run/systemd/notify
即可。
参见 here
完整示例:
我正在使用来自:https://github.com/bb4242/sdnotify 的 systemd-notify 测试脚本
docker 文件
FROM python
COPY test.py /
RUN pip install sdnotify
RUN chmod 755 /test.py
ENTRYPOINT ["/usr/local/bin/python", "test.py"]
CMD ["run"]
EXPOSE 8080
build.sh - 创建 Podman 容器,需要与 Dockerfile 和 test.py 脚本位于同一文件夹中。
#!/bin/bash
IMAGE_NAME=python-test
CONTAINER_NAME=python-test
sudo podman build . -t ${IMAGE_NAME}
sudo podman rm ${CONTAINER_NAME}
sudo podman create -e PYTHONUNBUFFERED=true -d --name=${CONTAINER_NAME} ${IMAGE_NAME}
通知测试服务
[Unit]
Description=A test service written in Python
[Service]
# Note: setting PYTHONUNBUFFERED is necessary to see the output of this service in the journal
# See https://docs.python.org/2/using/cmdline.html#envvar-PYTHONUNBUFFERED
Environment=PYTHONUNBUFFERED=true
Environment=NOTIFY_SOCKET=/run/systemd/notify
SyslogIdentifier=notify-test
NotifyAccess=all
ExecStart=/usr/bin/podman start -a python-test
ExecStop=/usr/bin/podman stop python-test
# Note that we use Type=notify here since test.py will send "READY=1"
# when it's finished starting up
Type=notify
[Install]
WantedBy=multi-user.target
所以首先安装podman,将上面url中的test.py、Dockerfile、build.sh放在单独的文件夹中。运行 ./build.sh
。
然后获取.service 文件,并将其与其他systemd 服务文件放在/usr/lib/systemd/user
中。执行 sudo systemctl daemon-reload
。
现在,可以使用 sudo systemctl start notify-test
和 sudo systemctl stop notify-test
启动和停止服务。
systemd 默认情况下会自动将写入 stdout/stderr 的任何内容记录到它自己的日志(可通过 journalctl
访问)和系统日志。
参见:https://www.freedesktop.org/software/systemd/man/systemd.exec.html
SyslogLevelPrefix=Takes a boolean argument. If true andStandardOutput= or StandardError= are set to journal or kmsg (or tothe same settings in combination with +console), log lines written bythe executed process that are prefixed with a log level will beprocessed with this log level set but the prefix removed. If set tofalse, the interpretation of these prefixes is disabled and the loggedlines are passed on as-is. This only applies to log messages writtento stdout or stderr. For details about this prefixing seesd-daemon(3). Defaults to true.
两个问题:
问题:当使用 podman 作为 ExecStart=
时,日志源默认为可执行文件的名称,即“podman”。
解决方案:使用 SyslogIdentifier=
指定日志记录的名称,如上面的 .service 文件示例。
问题:日志行的日志级别之间没有任何区别。
解决方案:如所述here在 systemd 文档中,在日志行前面加上 <7>(用于调试)、<6>(用于信息)、<4>(用于警告)等,让 systemd 在任何地方设置正确的日志级别,包括 syslog。甚至可以免费在 journalctl 工具中获取颜色!
关于docker - 如何在 systemd 中运行在容器中运行的服务,包括 systemd-notify 和日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63540832/
我想在 systemd 的 myapp.service 文件中使用多个命令 [Unit] Description=to serve myapp [Service] User=ubuntu Workin
我想为 systemd 服务启用核心转储生成,该服务提供 SEGV 状态并退出。 scd.service: main process exited, code=killed, status=11/SE
我有一个由 systemd 运行的程序,其服务文件如下所示: [Unit] Description=... [Service] Type=notify ExecStart=/usr/sbin/mypr
我有一个 systemd 单元,参数中有空格 ExecStart=command --argument="text text" systemd 似乎无法识别双引号或单引号,并将参数拆分为两个参数。知道
我正在使用一个 systemd 服务,它在“启动”时调用一个进程(例如 systemctl start test.service)。根据设计,进程永远处于循环状态,我们可以使用 ps 命令查看进程的存
我的解决方案(到目前为止)是从公共(public) session 中评论 pam_systemd.so 。一切都在 system.slice 中运行,没有对照组。我还不确定这会产生什么影响,但至少一
我四处查看并用 google 搜索,找不到节点导出器公开的 systemd 指标列表? 最佳答案 node_systemd 指标列表: node_systemd_unit_state - System
我正在尝试将文件写入磁盘作为 ExecStartPre 的一部分systemd 单元文件的命令。 这就是我正在使用的: [Unit] Description=My service [Service]
我的 journalctl到处都是gnome-session警告。我已将问题追溯到谷歌浏览器,警告相对无害。然而,它淹没了我的日志输出,坦率地说,如果我确实需要检查它,我将无法找到我需要的东西。 Ma
操作系统级别:CentOS Linux release 7.4.1708普罗米修斯等级:2.4.2prometheus.service: [Unit] Description=Prometheus [
我们有一个 systemd 服务,根据建议的配置 here 来管理 Puma 进程。 . 虽然看起来运行良好,但重新启动超时,因此看起来失败,即使它们是成功的。如何调试这一类问题? systemd 期
systemd 可以让 rsyslog 守护进程保持事件状态,即使它死了,这真是太棒了。 但是我正在制作一个新的 rsyslog 配置文件,并且需要在 Debug模式下启动此 rsyslog 守护进程
我想更改 systemd-logind 服务的环境参数。这不在 configuration.nix 中可用的登录选项中,所以我尝试了 systemd = { services.system
我试图了解我的新项目中不同 systemd 服务之间的依赖关系。我们正在使用 yocto 构建系统和 systemd/系统服务。 如果我表现出色, systemctl -l 它将按字母顺序列出所有服务
我正在尝试在 lindux debian 上安装和配置 systemD,但在安装 systemd-sysv 时出现错误,我知道这是让 systemD 管理服务所必需的。 当我运行时 apt-get i
我有两个服务 A 和 B。 A 在启动时在 etcd 中设置一个值,比如它从环境文件中获取的公共(public) IP 地址: ExecStartPost=/usr/bin/etcdctl set /
我们目前在一台主机上运行着许多不同的服务,我们正在广泛使用 systemd,包括用于消息传递的 systemd-notify 和用于服务管理的自己的前端。 我们希望开始在容器内运行这些服务,以简化依赖
我们目前在一台主机上运行着许多不同的服务,我们正在广泛使用 systemd,包括用于消息传递的 systemd-notify 和用于服务管理的自己的前端。 我们希望开始在容器内运行这些服务,以简化依赖
几个月前,我使用 systemd.journal 编写了一个小型 Python 服务。 Pip list 显示我在相应的 virtualenv 中安装了 python-systemd (231)。 当
我想启动一个不存在的计时器,它应该在当时启动一个不存在的服务。这应该通过 systemd 临时单元(如 systemd-run)来完成。 当我执行以下代码时,我收到一个异常(见下文)。有人可以告诉我,
我是一名优秀的程序员,十分优秀!