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
    • 最新
    • 标签
主页 / server / 问题

问题[systemd-service](server)

Martin Hope
grandinero
Asked: 2022-02-06 05:25:20 +0800 CST

在显示管理器之后运行 Systemd 服务

  • 1

我有一个脚本可以更改我想在启动时运行的一些 Gnome 设置。当我手动运行脚本时,它本身可以正常工作,但是当我将它作为 systemd 服务运行时出现以下错误:

● startup-user.service - Startup Service
     Loaded: loaded (/etc/systemd/system/startup-user.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sat 2022-02-05 13:03:48 UTC; 21s ago
    Process: 1948 ExecStart=/data/startup-user.sh (code=exited, status=1/FAILURE)
   Main PID: 1948 (code=exited, status=1/FAILURE)
        CPU: 22ms

Feb 05 13:03:48 debian systemd[1]: Started Startup Service.
Feb 05 13:03:48 debian gsettings[1950]: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
Feb 05 13:03:48 debian gsettings[1953]: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
Feb 05 13:03:48 debian gsettings[1956]: failed to commit changes to dconf: Cannot autolaunch D-Bus without X11 $DISPLAY
Feb 05 13:03:48 debian startup-user.sh[1959]: Error connecting: Cannot autolaunch D-Bus without X11 $DISPLAY
Feb 05 13:03:48 debian systemd[1]: startup-user.service: Main process exited, code=exited, status=1/FAILURE
Feb 05 13:03:48 debian systemd[1]: startup-user.service: Failed with result 'exit-code'.

这是脚本文件:

#!/bin/bash

gsettings set org.gnome.desktop.peripherals.touchpad natural-scroll false
gsettings set org.gnome.desktop.peripherals.touchpad tap-to-click true
gsettings set org.gnome.settings-daemon.plugins.power ambient-enabled false
gdbus call --session --dest org.gnome.SettingsDaemon.Power --object-path /org/gnome/SettingsDaemon/Power --method org.freedesktop.DBus.Properties.Set org.gnome.SettingsDaemon.Power.Screen Brightness '<int32 100>'

这是服务单元文件:

[Unit]
Description=Startup Service
After=graphical.target

[Service]
Type=simple
ExecStart=/data/startup-user.sh
User=user

[Install]
WantedBy=graphical.target

这是我第一次使用 systemd 服务,我不太了解显示管理器或这里涉及的其他任何内容,但我假设如果我的服务在 之后启动graphical.target,那么应该启动显示管理器并且所有应设置必要的变量。我也试过After=gdm.service了,我不确定我是否应该同时拥有graphical.targetand After=,WantedBy=但是如果我从中删除它,WantedBy=那么服务根本不会运行。

如果您想知道和/或有什么不同,这是针对我正在使用Debian Live构建的实时系统。我不想使用持久性分区,而是希望每次启动时都运行此脚本,以便它可以进行一些基本配置。脚本文件位于安装在的单独 ext4 分区上/data,因此我可以在想要更改设置时修改脚本文件。

我究竟做错了什么?谢谢!

gnome systemd systemd-service
  • 1 个回答
  • 559 Views
Martin Hope
Sean
Asked: 2022-01-30 01:21:20 +0800 CST

显示一个 systemd 单元文件,其覆盖合并在

  • 2

systemctl cat myunit.service打印主myunit.service文件的内容,后跟任何覆盖文件。有没有办法打印 systemd 实际使用的单元文件,即通过将覆盖合并到主单元中形成的单元文件?

systemd systemd-service
  • 1 个回答
  • 593 Views
Martin Hope
tidelake
Asked: 2021-06-27 01:21:55 +0800 CST

跟踪 journalctl 登录失败以重新启动 systemd 服务?

  • 0

我想知道是否有一种简短的方法可以检查有关在重新启动时引发错误的服务的最后 50 行。

$ sudo 服务 nginx 重启
nginx.service 的作业失败,因为控制进程以错误代码退出。 有关详细信息,请参阅“systemctl status nginx.service”和“journalctl -xe”。

我使用别名进行检查,但我忘记了标志的作用。

别名 jrn='sudo journalctl -eu'

$ jrn nginx 

-- 重启 -- Jun 26 02:52:42 xi systemd[1]: 启动 NGINX Plus - 高性能 Web 服务器... 6 月 26 日 02:52:42 xi systemd[1]:启动 NGINX Plus - 高性能 Web 服务器。 Jun 26 04:03:16 xi systemd[1]: 停止 NGINX Plus - 高性能 Web 服务器... Jun 26 04:03:16 xi systemd[1]: nginx.service: 成功。 6 月 26 日 04:03:16 xi systemd[1]:停止 NGINX Plus - 高性能 Web 服务器。 Jun 26 04:03:16 xi systemd[1]: 启动 NGINX Plus - 高性能 Web 服务器... Jun 26 04:03:16 xi nginx[41832]: nginx: [emerg] bind() to 0.0.0.0:3000 failed (98: Address already in use) Jun 26 04:03:17 xi nginx[41832]: nginx: [emerg] bind() to 0.0.0.0:3000 failed (98: Address already in use) Jun 26 04:03:17 xi nginx[41832]: nginx: [emerg] bind() to 0.0.0.0:3000 failed (98: Address already in use) Jun 26 04:03:18 xi nginx[41832]: nginx: [emerg] bind() to 0.0.0.0:3000 failed (98: Address already in use) Jun 26 04:03:18 xi nginx[41832]: nginx: [emerg] bind() to 0.0.0.0:3000 failed (98: Address already in use) 6 月 26 日 04:03:19 xi nginx [41832]:nginx:[emerg] 仍然无法绑定() Jun 26 04:03:19 xi systemd[1]:nginx.service:控制进程退出,code=exited,status=1/FAILURE Jun 26 04:03:19 xi systemd[1]:nginx.service:失败,结果'退出代码'。 6 月 26 日 04:03:19 xi systemd[1]:无法启动 NGINX Plus - 高性能 Web 服务器。
systemd journalctl systemd-service
  • 1 个回答
  • 1391 Views
Martin Hope
mosquetero
Asked: 2021-06-17 03:50:07 +0800 CST

在 ExecStartPre 中验证 bash 二进制文件是否存在

  • 0

我希望我的服务仅在另一个服务不活动时启动。为此,正如其他问题中所解释的那样,我将执行以下操作:

ExecStartPre=/bin/bash -xc '/usr/bin/systemctl is-active --quiet other-unit.service && exit 1 || exit 0'

但是,操作系统不包含 /bin/bash 的可能性很小。在这种情况下,我希望服务能够启动。我试图通过使用来实现这一点:

ExecStartPre=which bash 2>/dev/null && /usr/bin/bash -xc '/usr/bin/systemctl is-enabled --quiet nm-cloud-setup.service && exit 1 || exit 0' || exit 0

但 systemd 抱怨:

which[1122772]: /usr/bin/which: invalid option -- 'x'
which[1122772]: /usr/bin/which: invalid option -- 'c'
which[1122772]: /usr/bin/which: no && in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin)

我猜 ExecStartPre= 非常有限。有没有可能实现我想要的?

job-control systemd systemd-service
  • 1 个回答
  • 149 Views
Martin Hope
Thayne
Asked: 2021-06-08 09:12:29 +0800 CST

无法使用 PrivateTmp=true 在 systemd 服务中写入 /tmp

  • 1

我的 apache2 服务有PrivateTmp=true. 当服务第一次启动时,它工作正常,但几天后,写入 /tmp 失败并显示“没有这样的文件或目录”。为了调试我已经尝试运行nsenter -t <apache-pid> -m bash并且我已经确认它/tmp存在,但是mkdir /tmp/test由于“没有这样的文件或目录”而失败。我宁愿不删除该PrivateTmp=true指令。

如果我重新启动服务,它会再次开始工作。

/tmp 内部的挂载行表示它已挂载到 /dev/nvme0n1,这对我来说似乎很奇怪,但是当 /tmp 在启动服务后立即工作和不可写时都是这种情况。

任何人都知道为什么 /tmp 突然变得不可写?

linux systemd systemd-service
  • 2 个回答
  • 1070 Views
Martin Hope
DenisZ
Asked: 2021-05-31 05:08:57 +0800 CST

如何在 systemd 中创建自定义服务?

  • 0

在多台机器上运行 Fedora 33/34。我成功激活rc-local.service了它工作正常。我有几个需要运行的其他脚本,/etc/init.d/并且我创建了与 类似的服务文件rc-local.service,但我无法启用它,而 rc-local.service 可以毫无问题地启用/禁用/盯着/停止。
我知道,我有一个选项(我目前使用)从rc.local文件中调用这些脚本,但宁愿将它们作为服务单独调用。所以我的服务文件如下所示:
#cat net-scr1.service

[Unit]
Description=Network check service
ConditionFileIsExecutable=/etc/init.d/net-scr1
After=network.target 

[Service]
Type=forking
ExecStart=/etc/init.d/net-scr1 start
TimeoutSec=3
ExecStop=/etc/init.d/net-scr1 stop
RemainAfterExit=yes
GuessMainPID=no
StandardOutput=tty

[Install]
 WantedBy=multi-user.target

systemctl enable net-scr1

Synchronizing state of net-scr1.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable net-scr1
service net-scr1 does not support chkconfig

我将脚本移出init.d考虑可能 systemd 假设它是一个旧sysv脚本,但没有改变。我的脚本中应该有什么才能正常工作?
我的脚本看起来像:

#!/bin/bash
[email protected]
[email protected]
dv0=p1p1
ipdv0=`ifconfig $dv0 | grep "inet " | awk '{print $2}'`
if [ "$1" = "stop" ]; then
  cat $msg | mail $EMFR -s "$srv-shut_down-ip-$ipdv0" $eml
fi
if [ "$1" = "start" ]; then
  cat $msg | mail $EMFR -s "$srv-booted_up-ip-$ipdv0" $eml  

fi

我应该包含旧 sysv 系统中的函数还是其他什么?谢谢

scripting bash systemd systemd-service
  • 2 个回答
  • 264 Views
Martin Hope
CrazyRabbit
Asked: 2021-03-24 02:52:00 +0800 CST

Systemd 计时器 OnCalendar 每分钟以 5 结尾

  • 1

使用OnCalendarsystemd 计时器,我可以创建这样的东西,每 5 分钟运行一次。

OnCalendar=*:0/5

是否可以仅在 5 (00:05, 00:15, 00:25...)结束的每一分钟运行它?

和/或每分钟仅以 0 (00:00, 00:10, 00:20...)结尾?

主要目标是在 2 台服务器上有一个计时器,因此每个服务器都在空闲时间运行;如果一个失败,另一个将至少每 10 分钟运行一次(而不是 5 分钟)。

cron systemd-service
  • 2 个回答
  • 2363 Views
Martin Hope
Paulo Coghi
Asked: 2021-02-04 07:39:33 +0800 CST

无法在 Ubuntu Server 20.04.2 上将 Redis 初始化为 systemd 服务(受监督的 systemd)

  • 0

supervised systemd在 Ubuntu Server 20.04 上,Redis (5.0.7) 设置为 on后不会启动/etc/redis/redis.conf,但使用 . 手动运行时不会打印错误/usr/bin/redis-server /etc/redis/redis.conf。

此外,当手动运行时,可能会发现它正在侦听 6379 端口netstat -tulpn。

重现

作为根:

  • 更新软件包并安装 Redisapt update && apt install redis-server
  • 上/etc/redis/redis.conf,将行更改supervised no为supervised systemd
  • 尝试使用service redis-server restartor重启 Redissystemctl restart redis

上述命令的输出是:

Job for redis-server.service failed because the control process exited with error code.
See "systemctl status redis-server.service" and "journalctl -xe" for details.

的输出systemctl status redis-server.service是:

● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Wed 2021-02-03 12:15:56 -03; 28s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
    Process: 3851 ExecStart=/usr/bin/redis-server /etc/redis/redis.conf (code=exited, status=1/FAILURE)

Feb 03 12:15:56 mywebsite.com systemd[1]: redis-server.service: Scheduled restart job, restart counter is at 5.
Feb 03 12:15:56 mywebsite.com systemd[1]: Stopped Advanced key-value store.
Feb 03 12:15:56 mywebsite.com systemd[1]: redis-server.service: Start request repeated too quickly.
Feb 03 12:15:56 mywebsite.com systemd[1]: redis-server.service: Failed with result 'exit-code'.
Feb 03 12:15:56 mywebsite.com systemd[1]: Failed to start Advanced key-value store.

尝试重新启动 Redis 服务时不会打印任何日志/var/log/redis/redis-server.log,但手动运行时会打印以下文本:

4231:C 03 Feb 2021 12:27:52.053 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
4231:C 03 Feb 2021 12:27:52.053 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=4231, just started
4231:C 03 Feb 2021 12:27:52.053 # Configuration loaded
4232:M 03 Feb 2021 12:27:52.063 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 5.0.7 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 4232
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

4232:M 03 Feb 2021 12:27:52.065 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
4232:M 03 Feb 2021 12:27:52.065 # Server initialized
4232:M 03 Feb 2021 12:27:52.066 * Ready to accept connections

软件版本:

Redis 服务器 v=5.0.7 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=636cde3b5c7a3923

Ubuntu 20.04.2 LTS - 64 位

系统 245 (245.4-4ubuntu3.4)

systemd ubuntu-20.04 redis systemd-service
  • 2 个回答
  • 6179 Views
Martin Hope
Laurent
Asked: 2020-09-25 23:12:50 +0800 CST

Systemd:在 ZFS 导入之前解锁驱动器

  • 0

除此之外,我还有 LUKS 加密驱动器和 ZFS。我使用脚本在启动时解锁驱动器。我为此做了一个 systemd 服务,但是脚本需要一些时间,并且 zfs-import-cache.service 在我的脚本完成之前启动。

  • zfs-import-cache.service Journalctl
# journalctl -e -u cryptdisks-unlock.service -u zfs-import-cache.service
Sep 25 15:53:45 server systemd[1]: Starting Unlock LUKS drives...
Sep 25 15:53:45 server boot[1216]: Decrypting evo850m21-crypt ...
Sep 25 15:53:47 server systemd[1]: Starting Import ZFS pools by cache file...
Sep 25 15:53:47 server boot[1216]: Device evo850m21-crypt decrypted.
Sep 25 15:53:47 server boot[1216]: Decrypting evo850m22-crypt ...
Sep 25 15:53:49 server boot[1216]: Device evo850m22-crypt decrypted.
Sep 25 15:53:49 server boot[1216]: Decrypting st30001-crypt ...
Sep 25 15:53:50 server zpool[1390]: cannot import 'data': no such pool or dataset
Sep 25 15:53:51 server zpool[1390]:         Destroy and re-create the pool from
Sep 25 15:53:51 server zpool[1390]:         a backup source.
Sep 25 15:53:51 server systemd[1]: zfs-import-cache.service: Main process exited, code=exited, status=1/FAILURE
Sep 25 15:53:51 server systemd[1]: zfs-import-cache.service: Failed with result 'exit-code'.
Sep 25 15:53:51 server systemd[1]: Failed to start Import ZFS pools by cache file.
Sep 25 15:53:52 server boot[1216]: Device st30001-crypt decrypted.
Sep 25 15:53:52 server boot[1216]: Decrypting st30002-crypt ...
Sep 25 15:53:54 server boot[1216]: Device st30002-crypt decrypted.
Sep 25 15:53:54 server systemd[1]: cryptdisks-unlock.service: Succeeded.
Sep 25 15:53:54 server systemd[1]: Finished Unlock LUKS drives.

cryptdisks-unlock.service

[Unit]
Description=Unlock LUKS drives
Before=zfs-import.target

[Service]
Type=oneshot
ExecStart=/usr/local/cryptdisks-tools/boot

[Install]
WantedBy=zfs-import-cache.service
systemd systemd-service
  • 1 个回答
  • 348 Views
Martin Hope
ywiyogo
Asked: 2020-09-24 06:15:51 +0800 CST

如何在 Ubuntu 20.04 上使用来自 systemd 服务的命令启动 gnome-terminal?

  • 0

我编写了名为/etc/systemd/system/mytest.service的服务文件。然后我想用一些在新终端控制台上打印的命令启动一个新的终端窗口。

文件 mytest.service 包含以下内容:

[Unit]
Description= Test
After= network.target

[Service]
ExecStart=/usr/bin/gnome-terminal -- "echo 'test' > /home/me/test.log; echo 'abcd';"

StandardOutput=journal+console

[Install]
WantedBy=default.target

运行sudo systemctl start mytest并打印状态后,我收到以下错误消息:

Sep 23 21:09:50 ub20 gnome-terminal[4205]: Unable to init server: Could not connect: Connection refused
Sep 23 21:09:50 ub20 gnome-terminal[4205]: # Failed to parse arguments: Cannot open display:
Sep 23 21:09:50 ub20 systemd[1]: ethminer.service: Main process exited, code=exited, status=1/FAILURE

这里有什么问题?

terminal ubuntu-20.04 systemd-service
  • 1 个回答
  • 1549 Views

Sidebar

Stats

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

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve