AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

    • 主页
    • 系统&网络
    • Ubuntu
    • Unix
    • DBA
    • Computer
    • Coding
    • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[systemd-unit](unix)

Martin Hope
Stephen Boston
Asked: 2022-06-27 15:00:18 +0800 CST

启动时 systemd 用户单元错误:无法添加依赖项忽略:无效参数

  • 0

Arch 5.18/ MATE 桌面版

我有一个为我的面板设置值的用户服务

[Unit]
Description=Set values for panel widgets
After=mnt-ram
After=sys-subsystem-net-devices-eno1.device

[Service]
ExecStart=/home/stephen/bin/panel-setup.sh 
Type=oneshot
RemainAfterExit=True

[Install]
WantedBy=default.target

两者mnt-ram和都sys-subsystem-net-devices-enp0s8.device显示为活跃于systemctl --user list-units。

启动时日志报告

 systemd[669]: /home/stephen/.config/systemd/user/panel-setup.service:3: Failed to add dependency on mnt-ram, ignoring: Invalid argument
 

但是,在桌面加载后,我可以毫无错误地发出预期效果:systemctl user restart panel-setup

systemd systemd-unit
  • 1 个回答
  • 194 Views
Martin Hope
Александр Инженер
Asked: 2022-04-04 04:25:57 +0800 CST

centos上的systemd挂载单元配置*.img文件

  • 0

有必要创建一个虚拟文件samba.img作为设备并在系统启动时自动挂载它。

从文件创建虚拟磁盘

fallocate -l 2G /root/img/samba.img
mkfs.ext4       /root/img/samba.img

创建挂载点

sudo mkdir /srv/smb

我创建了一个挂载文件以在系统启动时运行

vim /etc/systemd/system/mnt-driveone.mount

mnt-driveone.mount 包含

[Unit]
Description=Additional drive

[Mount]
What=/root/img/samba.img
Where=/srv/smb
Type=ext4
Options=defaults

[Install]
WantedBy=multi-user.target

接下来,添加到自动加载

systemctl enable mnt-driveone.mount

跑

 systemctl start mnt-driveone.mount

我得到一个错误

mnt-driveone.mount: Where= setting doesn't match unit name. Refusing.

我看了看,这样的错误是在写路径有不正确的路径或者空格的时候出现,但是我的目录存在并且没有空格。

systemd systemd-unit
  • 1 个回答
  • 74 Views
Martin Hope
BozanicJosip
Asked: 2022-03-24 08:09:34 +0800 CST

Systemd 单元的 After= 指令未按预期工作

  • 0

所以,我开始分解我的系统初始化并为我登录后想要加载的东西创建一些服务文件。这是常见的东西,比如 polybar、dunst 和其他东西。事情确实有效,但我的 pywal 设置存在一些问题。我已经将依赖项分离到一个单独的 .target 中,称为

主题.target

[Unit]
Description = Theme dependencies
BindsTo = xsession.target
Wants = pywal.service
Wants = i3.service
Wants = polybar.service
Wants = dunst.service

我想要实现的是仅在 pywal.service 完全运行并完成启动脚本的执行后才加载 i3(以及列表的其余部分)。

在 .bin/pywal 我确实睡了 10 秒

pywal.服务

[Unit]
Description = Run pywal service responsible for color schemes
PartOf = theme.target

[Service]
ExecStart = %h/.bin/pywal

[Install]
WantedBy = theme.target

i3.服务

[Unit]
Description = A tiling window manager
PartOf = theme.target
After = pywal.service
Requires = pywal.service

[Service]
ExecStart = /usr/bin/i3-msg restart

[Install]
WantedBy = theme.target

我可能在这里对“成功运行”的实际含义感到困惑,但是我注意到 i3 服务在我运行后立即重新启动

systemctl --user restart theme.target

然后我只是观察所有 3 个服务/目标的状态,并看到 i3 与 pywal.service 同时重新启动。

所以基本上我在这里错过了什么,为什么 i3 在 pywal 后 10 秒不重启?

编辑:根据评论修复了一个句子以在这种情况下更有意义

systemd systemd-unit
  • 1 个回答
  • 80 Views
Martin Hope
Tom Hale
Asked: 2022-01-22 01:56:31 +0800 CST

systemd 单元文件中 `ExecSearchPath=` 的默认值是什么?

  • 3

man systemd.exec说关于ExecSearchPath=:

采用冒号分隔的绝对路径列表,可以找到 Exec*=(例如 ExecStart=、ExecStop= 等)属性使用的可执行文件。如果用户未通过 Environment=、EnvironmentFile= 或 PassEnvironment= 提供 $PATH,则 ExecSearchPath= 将覆盖 $PATH。分配一个空字符串会删除之前的分配,并且多次将 ExecSearchPath= 设置为一个值将附加到之前的设置。

的默认值是ExecSearchPath=多少?

systemd systemd-unit
  • 1 个回答
  • 285 Views
Martin Hope
agentsmith
Asked: 2020-03-11 01:01:34 +0800 CST

在隔离目标时,通缉和冲突单位究竟会发生什么

  • 0

以下用例: unitA和 unitB是 target 想要的T。单位A冲突B。单元B在单元之前启动A。系统启动到目标T。

如果我正确理解文档,单元A将在启动时停止单元B。我根本不会阻止单元B启动。我的假设正确吗?

systemd systemd-unit
  • 1 个回答
  • 28 Views
Martin Hope
Mitch
Asked: 2018-12-11 14:21:45 +0800 CST

Systemd - 在单元文件中反转条件?

  • 4

我正在尝试创建一个只有在文件系统上不存在某个文件时才应该启动的 systemd 服务。

如果我使用ConditionPathExists这将使服务仅在有问题的文件存在时启动,这与我想要的行为相反。

有没有办法扭转这些条件?

systemd systemd-unit
  • 1 个回答
  • 2792 Views
Martin Hope
SBF
Asked: 2018-06-26 13:14:13 +0800 CST

/run/user/$UID 未在守护程序启动时挂载

  • 3

当我重新启动我的 Raspberry Pi (Stretch) 时,一个守护进程无法启动,因为/run/user/1000它不存在。这是我的单位文件:

[Unit]
Description=SBFspot Upload Daemon

[Service]
User=pi
Type=forking
TimeoutStopSec=60
ExecStart=/usr/local/bin/sbfspot.3/SBFspotUploadDaemon -p /run/user/1000/sbfspotupload.pid 2>&1> /dev/null
PIDFile=/run/user/1000/sbfspotupload.pid
Restart=no
RestartSec=15
SuccessExitStatus=SIGKILL

[Install]
WantedBy=default.target

重试几次后,当我配置为Restart=on-failure一切顺利时,但这并不是我真正想要的。我希望守护程序等待/run/user/1000安装。我试过了,After=run-user-1000.mount但它仍然失败。

这是可能的还是我必须坚持Restart=on-failure?

systemd systemd-unit
  • 1 个回答
  • 1776 Views
Martin Hope
the_drow
Asked: 2018-04-17 02:49:41 +0800 CST

无法确定补充组:不允许操作

  • 15

我正在尝试将守望者设置为用户服务。

我已尽可能密切关注他们的文档。这就是我所拥有的:

套接字文件:

[Unit]
Description=Watchman socket for user %i

[Socket]
ListenStream=/usr/local/var/run/watchman/%i-state/sock
Accept=false
SocketMode=0664
SocketUser=%i
SocketGroup=%i

[Install]
WantedBy=sockets.target

服务文件:

[Unit]
Description=Watchman for user %i
After=remote-fs.target
Conflicts=shutdown.target

[Service]
ExecStart=/usr/local/bin/watchman --foreground --inetd --log-level=2
ExecStop=/usr/bin/pkill -u %i -x watchman
Restart=on-failure
User=%i
Group=%i
StandardInput=socket
StandardOutput=syslog
SyslogIdentifier=watchman-%i

[Install]
WantedBy=multi-user.target

Systemd 尝试运行 watchman 但卡在重启循环中。
这些是我得到的错误:

Apr 16 05:41:00 debian systemd[20894]: watchman@user.service: Failed to determine supplementary groups: Operation not permitted
Apr 16 05:41:00 debian systemd[20894]: watchman@user.service: Failed at step GROUP spawning /usr/local/bin/watchman: Operation not permitted

我 100% 确定我启用此服务和套接字的组和用户存在。我究竟做错了什么?

systemd systemd-unit
  • 2 个回答
  • 11990 Views
Martin Hope
pandita
Asked: 2018-04-02 17:39:58 +0800 CST

systemd 参数无效 - 调试延迟休眠服务文件

  • 1

我正在尝试实现延迟休眠单元。我在拱门/安特戈斯。

>>> systemctl enable suspend-to-hibernate.service
Failed to enable unit ...to-hibernate.service: Invalid argument

systemd-analyze verify ...hibernate.service以空输出响应。

我直接从 arch wiki 复制了单元文件并将 SLEEPLENGTH 更改为 1 小时。如何调试问题?如何使 systemd 发出更具描述性的错误消息?

暂停到休眠.服务

[Unit]
Description=Delayed hibernation trigger
Documentation=https://bbs.archlinux.org/viewtopic.php?pid=1420279#p1420279
Documentation=https://wiki.archlinux.org/index.php/Power_management
Conflicts=hibernate.target hybrid-sleep.target
Before=sleep.target
StopWhenUnneeded=true

[Service]
Type=oneshot
RemainAfterExit=yes
Environment="WAKEALARM=/sys/class/rtc/rtc0/wakealarm"
Environment="SLEEPLENGTH=+1hour"
ExecStart=-/usr/bin/sh -c 'echo -n "alarm set for "; date +%%s -d$SLEEPLENGTH | tee $WAKEALARM'
ExecStop=-/usr/bin/sh -c '\
  alarm=$(cat $WAKEALARM); \
  now=$(date +%%s); \
  if [ -z "$alarm" ] || [ "$now" -ge "$alarm" ]; then \
     echo "hibernate triggered"; \
     systemctl hibernate; \
  else \
     echo "normal wakeup"; \
  fi; \
  echo 0 > $WAKEALARM; \
'

[Install]
WantedBy=sleep.target
systemd systemd-unit
  • 1 个回答
  • 1147 Views
Martin Hope
Abhishek Kumar
Asked: 2018-03-21 22:36:12 +0800 CST

systemd 单个服务的多个单元文件

  • 0

我在 SLES 12 SP3 系统上有一个 postgresql 数据库,其服务由 systemd 通过标准单元文件管理。我想在失败时自动重启服务,所以创建目录/etc/systemd/system/postgresql.service.d/psql.conf,内容如下。

[Service]
Restart=on-failure

这很好用,我很高兴。现在需要设置一个高可用性系统,其中一个从站处于备用状态,以防主站发生故障。从事 HA 工作的团队已请求在设置集群时禁用重新启动服务标志,因为他们将监视服务并在 postgresql 停止时故障转移到从属服务器。所以我创建了一个文件/etc/systemd/system/potgresqlHA.service,它是现有单元文件的副本,并且 HA 团队开始使用这个文件。

systemctl start/stop/restart/status postgresqlHA

现在有一个脚本可以在请求时备份数据库。此脚本在备份之前检查 postgresql 的状态,以确保服务正在运行。

systemctl status postgresql

这在未设置集群时效果很好。但是在设置集群时,服务的状态会停止,因为 postgresqlHA 是启动的服务。

无论正在运行的数据库服务如何,如何使备份脚本工作?我可以在其中一个单元文件中配置一些东西以使其更易于管理吗?

在其他脚本中检查其他一些服务(apache2、tomcat 等)的状态时,我遇到了同样的问题。

谢谢, 阿布舍克

systemd systemd-unit
  • 1 个回答
  • 862 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助
subwaysurfers
my femboy roommate

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve