我有一个源包(foo),它生成两个二进制包(foo-a和foo-b)。
在 2.0 版本中,文件/etc/foo从 移动foo-a到foo-b. 这会导致apt upgrade失败:
$ sudo apt upgrade
...
dpkg: error processing archive /var/cache/apt/archives/foo-b_2.0_amd64.deb (--unpack):
trying to overwrite '/etc/foo', which is also in package foo-a 1.0.
Run Code Online (Sandbox Code Playgroud)
有没有客户端解决方案apt可以解决这个问题?
我创建了一个安装服务的deb包。
在我们的嵌入式设备上,我希望这个包自动启用服务。在我们的开发人员工作站上,我希望开发人员systemctl start foo手动执行(这是一项繁重的服务,因此如果一直在桌面环境中运行,它只会消耗资源)。
我如何在apt-get步骤中提示用户做出决定?这是最好的解决方案吗?
请注意,我已经使用dh_make和创建了包debhelper并启用了它:
%:
dh $@ --with=systemd
override_dh_systemd_enable:
dh_systemd_enable --name=foo foo.service
Run Code Online (Sandbox Code Playgroud) 我有一个不错的小bash脚本,它解析正则表达式的消息并对捕获组执行某些操作:
regex='\((Closes|Resolves):\s([0-9]+)\)'
msg='Fixed a problem (Closes: 1234), (Resolves: 5678)'
if [[ $msg =~ $regex ]] ; then
action="${BASH_REMATCH[1]}"
issue="${BASH_REMATCH[2]}"
do_something $action $issue
fi
Run Code Online (Sandbox Code Playgroud)
这适用于第一场比赛,但如果有多个比赛msg,后面的比赛将被忽略。有没有办法对我来说,遍历每场比赛或者是时候开始想着python还是perl?
我希望群组中的用户foogroup能够:
systemctl start foo.service,systemctl stop foo.service,systemctl status foo.service, 和journalctl -u foo.service 不使用提升的权限。那可能吗?
我有一个 systemd 服务,如下所示:
[Unit]
Description=foo service
[Service]
Type=simple
ExecStart=/bin/sleep infinity
User=foobot
Group=foogroup
Run Code Online (Sandbox Code Playgroud)
foobot系统用户在哪里。
我知道我们可以安装单元文件以~/.config/systemd/user/允许非特权用户使用 systemd,但这并不能真正帮助组。
注意:我计划在 cockpit 中使用sd - bus API ,因此添加不会有帮助。libsystem-devsystemctl/etc/sudoers
我不太关心systemctl enable,如果我需要更高的特权也没关系。
我试图允许用户somegroup管理someunitsystemd 服务。
在 中polkit (>=0.106),这可以通过添加规则来完成:
/etc/polkit-1/rules.d/20-someunit.rules
---
polkit.addRule(function(action, subject) {
if (action.id == "org.freedesktop.systemd1.manage-units"
&& subject.isInGroup("somegroup")
&& (action.lookup("unit") == "someunit.service") )
{
var verb = action.lookup("verb");
if (verb == "start" || verb == "stop" || verb == "restart") {
return polkit.Result.YES;
}
}
});
Run Code Online (Sandbox Code Playgroud)
polkit 0.105然而,我使用的是 Debian Stretch/Buster,我们自 2012 年以来 一直使用该版本。polkit(<0.106)不支持这些rules.d/*文件。相反,我们依赖/etc/polkit-1/localauthority/50-local.d/*.pkla.
按照pklocalauthority(8)中的一些示例,我可以在等效的 pkla 文件中完成大部分工作:
/etc/polkit-1/localauthority/50-local.d/manage-units.pkla
----
[Allow users to manage services]
Identity=unix-group:somegroup
Action=org.freedesktop.systemd1.manage-units
ResultActive=yes
Run Code Online (Sandbox Code Playgroud)
但是,这会授予对所有服务的所有操作的访问权限。是否有相当于允许特定action.lookup() …
我正在创建一个foo启动/关闭上游包的包bar。关系应该是:
bar 可以在不影响的情况下启动、停止或重新加载 foo如果/lib/systemd/system/bar.service看起来像这样:
[Unit]
Description=Bar
[Service]
ExecStart=/bin/sleep infinity
Restart=on-failure
Run Code Online (Sandbox Code Playgroud)
那么“正常”解决方案是添加WantedBy和PartOf关系到bar:
[Unit]
Description=Bar
PartOf=foo.service
[Service]
ExecStart=/bin/sleep infinity
Restart=on-failure
[Install]
WantedBy=foo.service
Run Code Online (Sandbox Code Playgroud)
但是,bar是一个上游包,我认为强制bar了解foo或修补是不太正确的bar。
我认为一个完美的解决方案是这样创建foo.service:
[Unit]
Description=Foo
Wants=bar.service
ConsistsOf=bar.service
[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=yes
Run Code Online (Sandbox Code Playgroud)
但是我的 journalctl 说:
“单位”部分中的未知左值“ConsistsOf”
和手册页说:
当 PartOf=b.service 用于 a.service 时,此依赖项将在 b.service 的属性列表中显示为 ConsistsOf=a.service。ConsistsOf= 依赖项不能直接指定。
我不确定为什么 ConsistsOf= …
我正在尝试将一些getopts逻辑转移到函数中,这样我就可以多次使用它,从而为用户指定参数的顺序提供更大的灵活性:
print-usage() {
echo "myssh [options] <host> [options] [-- ssh-options...]" >&2
exit 1
}
extra_args=()
parse-args() {
while getopts ":hvV:" opt; do
case ${opt} in
(h) print-usage ;;
(v) extra_args+=('-L 5900:localhost:5900') ;;
(V) extra_args+=("-L $OPTARG:localhost:5900") ;;
(\?) echo "Invalid option: -$OPTARG" >&2 ;;
(:) echo "Invalid option: -$OPTARG requires an argument" >&2 ;;
esac
done
echo $((OPTIND -1))
}
shift $(parse-args $@)
host=$1
shift
shift $(parse-args $@)
ssh $host $extra_args $@
Run Code Online (Sandbox Code Playgroud)
我的问题是这parse-args() { ... extra_args+=(...) }不会影响全局变量 …
如何授予只读权限somegroup以读取系统日志?(我在 Debian10 buster 上)。
$ journalctl
Hint: You are currently not seeing messages from other users and the system.
Users in the 'systemd-journal' group can see all messages. Pass -q to
turn off this notice.
No journal files were opened due to insufficient permissions.
Run Code Online (Sandbox Code Playgroud)
我知道我可以将用户添加到systemd-journal组中,但是如何授予组读取权限?
我有一个脚本,它读取 VCS 日志,将其转换为乳胶,然后使用文本awk替换@COMMITS@模板中的关键字:
untagged=$(get-commit-messages "$server" "$rev")
IFS=$'\n' untagged=( $untagged ) # Tokenize based on newlines
for commit in "${untagged[@]}"; do
tex+="\\\nui{" # Wrap each commit in a custom command
tex+=$(echo "$commit" | pandoc -t latex --wrap=none)
tex+="}
"
done
awk -v r="$tex" '{gsub(/@COMMITS@/,r)}1' template
Run Code Online (Sandbox Code Playgroud)
由于提交消息实际上只是文本,因此我pandoc -t latex用来确保所有内容都为 Latex 解析器正确转义。
我的问题是awk解析器未转义这些。如果我_在提交消息中找到 a ,pandoc会将其替换为\_,但随后awk会将其转换回并发出警告:
awk: warning: escape sequence `\_' treated as plain `_'
Run Code Online (Sandbox Code Playgroud)
这将导致乳胶解析器失败。
有没有办法让我防止awk …
我正在运行一个服务,它有一个连接到标准输入的 CLI。当我ssh进入机器时,我希望能够向该服务的标准输入发送命令。
systemd.exec说这StandardInput=file:/path/to/file是一个东西并且支持 FIFO。这听起来是最简单的方法。
我已经在我的~/.config/systemd/user/foo.service
[Service]
ExecStartPre=mkfifo %t/foo.stdin
ExecStart=cat -
StandardInput=file:%t/foo.stdin
ExecStopPost=rm -f %t/foo.stdin
Run Code Online (Sandbox Code Playgroud)
在此示例中,我希望当我运行以下命令时,我将在日志中看到输出回显。
echo "hello" > /run/user/1000/foo.stdin
Run Code Online (Sandbox Code Playgroud)
我对此有两个问题:
foo.service: Failed to set up standard input: No such file or directory 。看来StandardInput=之前一定存在过ExecStartPre=。在安装过程中,我是否需要在静态位置创建永久管道,或者是否有解决方法?如果我手动创建文件并删除ExecStartPre/ ExecStopPost,那么事情就可以了。echo "command"处理得很好,但发送一个EOF并且标准输入关闭。我希望标准输入保持开放。 答案(exec 3> stdin,...,exec 3>&-)似乎是使用 bash FD 重定向,但这在 systemd 中不可用。我的机器上有这个:
$ cat /etc/profile.d/proxy.sh
export http_proxy=http://192.168.1.30:3128
export https_proxy=https://192.168.1.30:3128
Run Code Online (Sandbox Code Playgroud)
这非常有效,直到我需要在本地主机上的应用程序中使用 HTTP 接口。
$ wget localhost
--2023-03-02 06:54:52-- http://localhost/
Connecting to 192.168.1.30:3128... connected.
Proxy request sent, awaiting response... 503 Service Unavailable
2023-03-02 06:54:52 ERROR 503: Service Unavailable.
$ wget 127.0.0.1
--2023-03-02 06:55:20-- http://127.0.0.1/
Connecting to 192.168.1.30:3128... connected.
Proxy request sent, awaiting response... 403 Forbidden
2023-03-02 06:55:20 ERROR 403: Forbidden.
Run Code Online (Sandbox Code Playgroud)
有没有办法阻止localhost请求127.0.0.1转发到代理?
细节:
这台机器没有直接连接到互联网。它没有网关或默认路由。但它位于具有代理计算机 (192.168.1.30) 的 LAN 上,该代理计算机安装了代理服务器(端口 3128)并具有 Internet 连接。
$ ip addr
1: lo: ...
inet 127.0.0.1/8 scope …Run Code Online (Sandbox Code Playgroud) 我有一个小型机器网络,systemd-timesyncd.service它们使用并需要同步时钟。它们不需要正确,只需同步即可。我已将其中一台机器指定为 NTP 服务器,其余机器都指向这台机器,但它们需要几个小时才能同步,而且当它们同步时,会出现非常不一致的情况:
Jun 22 18:09:16 host systemd-timesyncd[10515]: Initial synchronization to time server 10.10.1.30:123 (10.10.1.30).
Jun 22 18:25:50 host systemd-timesyncd[10515]: Server has too large root distance. Disconnecting.
Jun 22 18:34:22 host systemd-timesyncd[10515]: Server has too large root distance. Disconnecting.
Jun 22 18:51:26 host systemd-timesyncd[10515]: Server has too large root distance. Disconnecting.
Jun 22 19:25:34 host systemd-timesyncd[10515]: Server has too large root distance. Disconnecting.
Jun 22 19:59:43 host systemd-timesyncd[10515]: Server has too large root distance. Disconnecting.
Jun 22 20:33:51 …Run Code Online (Sandbox Code Playgroud) systemd ×7
debian ×3
bash ×2
dpkg ×2
apt ×1
awk ×1
http-proxy ×1
journalctl ×1
networking ×1
ntp ×1
pandoc ×1
polkit ×1
proxy ×1