如何打包 systemd 服务?

tra*_*ter 15 packaging debian systemd

我正在尝试打包一个单声道应用程序以作为 systemd 服务运行。

我已按照此处的说明进行操作:https : //wiki.debian.org/Teams/pkg-systemd/Packaging

我已将 dh-systemd (>= 1.5) 添加到我的 debian 控制文件构建依赖项中。

我已将 --with=systemd 添加到我的规则文件中,如下所示:

%:
    dh $@ --with=cli --with=systemd
Run Code Online (Sandbox Code Playgroud)

我已将我的服务文件添加到名为 mypackage.service 的 debian 文件夹中,其中包含以下内容:

[Unit]
Description=My Service Description
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/mono /usr/lib/mypackage/myservice.exe

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

但是,构建会给出以下 lintian 警告和错误:

Now running lintian...
E: mypackage: postrm-does-not-call-updaterc.d-for-init.d-script     etc/init.d/mypackage
W: mypackage: init.d-script-not-marked-as-conffile etc/init.d/mypackage
E: mypackage: init.d-script-not-included-in-package etc/init.d/mypackage
Run Code Online (Sandbox Code Playgroud)

由于几个原因,这让我感到困惑

  1. 这些警告是关于 init.d 的,它是由 systemd 取代的旧系统,这些错误和警告是错误的,debuild 是否认为我正在使用 init.d 因为我配置了错误的包?
  2. 我的印象是 --with=systemd 会为我创建这些脚本。

更新

生成的postrm文件如下:

#!/bin/sh
set -e
# Automatically added by dh_systemd_start
if [ -d /run/systemd/system ]; then
    systemctl --system daemon-reload >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_systemd_enable
if [ "$1" = "remove" ]; then
    if [ -x "/usr/bin/deb-systemd-helper" ]; then
        deb-systemd-helper mask mypackage.service >/dev/null
    fi
fi

if [ "$1" = "purge" ]; then
     if [ -x "/usr/bin/deb-systemd-helper" ]; then
        deb-systemd-helper purge mypackage.service >/dev/null
        deb-systemd-helper unmask mypackage.service >/dev/null
    fi
fi
# End automatically added section
Run Code Online (Sandbox Code Playgroud)

生成的prerm文件如下:

#!/bin/sh
set -e
# Automatically added by dh_systemd_start
if [ -d /run/systemd/system ]; then
    deb-systemd-invoke stop mypackage.service >/dev/null
fi
# End automatically added section
# Automatically added by dh_installinit
if [ -x "/etc/init.d/mypackage" ] || [ -e "/etc/init/mypackage.conf" ]; then
    invoke-rc.d mypackage stop || exit $?
fi
# End automatically added section
Run Code Online (Sandbox Code Playgroud)

该软件包实际上安装正常并且服务正确启动。lintian 错误令人担忧,我想深入了解它们。

bat*_*get 7

我也遇到了这个问题。这是我想出的:

你会想要覆盖 dh_installinit 和 dh_systemd_start,这是我的网桥服务的一个例子:

#!/usr/bin/make -f

PKGDIR=debian/tmp

%:
    dh $@ --with systemd

override_dh_installinit:
    dh_systemd_enable -popenstack --name=openstack openstack.service
    dh_installinit -popenstack --no-start --noscripts
    dh_systemd_start -popenstack --no-restart-on-upgrade

override_dh_systemd_start:
    echo "Not running dh_systemd_start"
Run Code Online (Sandbox Code Playgroud)

我的包的完整源可以在这里找到:https : //github.com/Ubuntu-Solutions-Engineering/openstack-deb/tree/master/debian

我还使用了https://github.com/lxc/lxd-pkg-ubuntu/blob/dpm-xenial/debian/rules作为参考。

希望这能让你继续前进,因为我确实花了一点时间来弄清楚这一点。


Luc*_*cas 6

如果不包括的SysV或暴发户init脚本,指导dh_installinit不修改postinst/ postrm/prerm脚本。dh_systemd会处理的。

override_dh_installinit:
    dh_installinit --noscripts
Run Code Online (Sandbox Code Playgroud)

这适用于debhelper兼容级别 < 10 和 10 即使dh_systemd已合并到debhelper.

根据https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=800043 debhelper兼容级别 11 >= 这将修复此问题。