标签: systemd

SELinux 阻止 systemd 单元中的执行

我使用 Fedora 31 并尝试设置 Teamspeak 服务器。当我查看时,journalctl -u teamspeak出现以下错误:

mar 09 22:22:46 melchior systemd[1]: Started Teamspeak server.
mar 09 22:22:46 melchior systemd[20187]: teamspeak.service: Failed to execute command: Permission denied
mar 09 22:22:46 melchior systemd[20187]: teamspeak.service: Failed at step EXEC spawning /srv/teamspeak/3.11.0/ts3server: Permission denied
mar 09 22:22:46 melchior systemd[1]: teamspeak.service: Main process exited, code=exited, status=203/EXEC
mar 09 22:22:46 melchior systemd[1]: teamspeak.service: Failed with result 'exit-code'.
Run Code Online (Sandbox Code Playgroud)

我的 systemd 单元如下所示:

[Unit]
Description=Teamspeak server
After=network-online.target

[Service]
User=teamspeak
Group=teamspeak
WorkingDirectory=/srv/teamspeak/data/
ExecStart=/srv/teamspeak/versions/3.11.0/ts3server dbsqlpath=/srv/teamspeak/versions/3.11.0/sql/ serverquerydocs_path=/srv/teamspeak/versions/3.11.0/serverquerydocs/ license_accepted=1 …
Run Code Online (Sandbox Code Playgroud)

fedora selinux systemd

8
推荐指数
2
解决办法
2万
查看次数

显示一个 systemd 单元文件及其合并的覆盖

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

systemd systemd-service

8
推荐指数
1
解决办法
3855
查看次数

链接自定义 systemd 服务

我有一个计时器A,每隔几个小时运行一个运行服务的脚本B(其中包含脚本systemctl start)。然后我想在完成C后运行服务。B

这是我的服务C

[Unit]
Description=lorem ipsum
Requires=B.service
After=B.service

[Service]
Type=oneshot
ExecStart=echo
Run Code Online (Sandbox Code Playgroud)

B也是Type=oneshot。

问题:我调用后不会自动启动systemctl start B.serviceC我没有 [Install] 部分,因为我不希望它们在启动时启动。

systemd

7
推荐指数
1
解决办法
2031
查看次数

如何按特定顺序停止systemd服务

当特定的 systemd 服务停止时,如何确保遵循特定的顺序?我有几个正在运行的 systemd 服务/单元,但使用了各种挂载分区上的资源。这些分区使用自定义服务挂载和卸载。在自定义挂载程序停止之前,需要按特定顺序停止正在运行的服务(例如 ProgramA.service 和 ProgramB.service)。

设置启动依赖项相当简单,但我一直无法弄清楚如何确保在我的挂载服务停止之前停止服务。

mountCustomPartitions.service

[Unit]
Description=My Custom Partition Mounting Service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/mountCustomPartitions.sh mount
ExecStop=/usr/bin/mountCustomPartitions.sh unmount

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

程序A.服务

[Unit]
Description=My Generic Program A Service
Wants=mountCustomPartitions.service
After=mountCustomPartitions.service

[Service]
Type=simple
ExecStart=/usr/bin/ProgramA

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

程序B.服务

[Unit]
Description=My Generic Program B Service
Requires=ProgramA.service
Wants=mountCustomPartitions.service
After=mountCustomPartitions.service ProgramA.service

[Service]
Type=simple
ExecStart=/usr/bin/ProgramB

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

在我上面的场景中, mountCustomPartitions.service 必须在程序服务之前启动,但也必须在它们之后停止。如果 mountCustomPartitions.service 被明确停止,那么它应该导致其他人也停止(但必须等待它们被停止)。我还需要确保 ProgramB 在 ProgramA 之后启动,但也在 ProgramA 之前停止。希望这不会太令人困惑。

我能想到的唯一解决方案是让每个服务都有一个 ExecStop 行,该行为特定服务执行systemctl stop [service]命令,该服务必须在停止之前停止。我遇到的问题是我实际上目前有六个服务使用已安装的分区,并且必须在尝试卸载之前停止。在这六个中,有些需要按特定顺序停止。由于这是用于商业产品,我希望有一个更清洁的解决方案。

linux systemd

7
推荐指数
1
解决办法
2万
查看次数

在 CentOS 7 SystemD 上创建多个 Apache 实例

我正在尝试在 CentOS 7 上的 systemd 中创建重复的 httpd 服务(为什么?见底部)

这是我到目前为止所做的:

#Copy all the files
cp -pr /etc/httpd /etc/httpd-bobby
cp /usr/lib/systemd/system/httpd.service /usr/lib/systemd/system/httpd-bobby.service
cp /etc/sysconfig/httpd /etc/sysconfig/httpd-bobby

#Just replace /etc/sysconfig/httpd with /etc/sysconfig/httpd-bobby
pico /usr/lib/systemd/system/httpd-bobby.service

#Changed port and file locations
pico /etc/httpd-bobby/conf/httpd.conf
Run Code Online (Sandbox Code Playgroud)

当我运行它时,我失败了,这是:

[root~]# systemctl status httpd-bobby.service
httpd-bobby.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd-bobby.service; disabled)
   Active: failed (Result: exit-code) since Tue 2016-06-21 17:38:33 BST; 6h ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 21777 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)
  Process: 21775 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=exited, status=0/SUCCESS) …
Run Code Online (Sandbox Code Playgroud)

systemd apache-2.4 centos7

7
推荐指数
1
解决办法
7961
查看次数

如何让 systemd 调用我的“状态”命令?

我们正在用 Ubuntu 16.04 替换 Ubuntu 8.04 服务器。服务器运行我们需要的单个(非操作系统)服务。(我是该服务的开发人员,而不是本周休假的系统管理员)服务脚本如下所示:

#!/bin/sh

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions


# ...

case "$1" in
  start)
    umask 002
    #...
    exit $?
    ;;

  stop)
    # ...
    exit $?
    ;;

  restart)
        stop || exit $?
        start
        exit $?
        ;;

  status)
       # ...
       exit $?
       ;;

  *)
    echo "Usage my_service (start|stop|restart|status)"
    exit 1;;
esac …
Run Code Online (Sandbox Code Playgroud)

systemd ubuntu-16.04

7
推荐指数
1
解决办法
6942
查看次数

systemd - 在另一个服务启动/重新启动后自动启动/重新启动特定的 systemd 服务

正如在 subs 中一样 - 我想在 a.service 启动/重新启动后启动/重新启动 b.service。

有没有一个好的方法来实现这个目标?

谢谢

systemd

7
推荐指数
1
解决办法
4511
查看次数

systemctl start trafficserver 等待启动

我有一个安装和设置流量服务器的脚本:

yum install -y trafficserver
systemctl start trafficserver

traffic_line -s proxy.config.url_remap.remap_required -v 0
traffic_line -s proxy.config.reverse_proxy.enabled -v 0
Run Code Online (Sandbox Code Playgroud)

问题是,traffic_line失败了:

[connect] ERROR (main_socket_fd 3): No such file or directory 错误:无法连接到管理端口,确保traffic_manager正在运行

这是因为systemctl start立即返回,无需等待流量服务器实际启动。

有没有办法告诉systemctl start只有在服务启动后才返回?

如果这是不可能的,是否有我可以运行的命令systemctl start来实际等待服务启动?

apache-traffic-server systemd systemctl

7
推荐指数
1
解决办法
2万
查看次数

PostgreSQL systemd 服务是 /bin/true

postgresql.service 内容是

# systemd service for managing all PostgreSQL clusters on the system. This
# service is actually a systemd target, but we are using a service since
# targets cannot be reloaded.

[Unit]
Description=PostgreSQL RDBMS
[Service]
Type=oneshot
ExecStart=/bin/true
ExecReload=/bin/true
RemainAfterExit=on

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

我尝试通过以下方式启动 PostrgeSQLservice postgresql start并且对postgresql.service内容感到惊讶 ,因为它开始/bin/true

uname -a 输出:

Linux debian 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02) x86_64 GNU/Linux
Run Code Online (Sandbox Code Playgroud)

所以我的问题是:为什么会发生,以及如何解决?

postgresql systemd

7
推荐指数
2
解决办法
2869
查看次数

自动将 systemd 控制组资源限制应用于 gnome-shell 会话中的特定用户应用程序

看到GNOME 现在在 systemd 范围内启动应用程序后,我一直在寻找一种方法让 systemd 将一些 cgroup 资源和内存限制应用到我的浏览器。

\n

我想将 aMemoryMax和应用于每个CPUShare的所有app-gnome-firefox-*.scope实例systemd.resource-control

\n

但 GNOME 不会使用实例化的单元格式启动 Firefox app-gnome-firefox-@.scope,因此我不知道如何创建一个自动应用于所有app-gnome-firefox-*.scope实例的 systemd 单元文件。

\n

我可以在单元启动后手动将资源限制应用于实例systemctl set-property --user app-gnome-firefox-92450.scope(例如),但这很痛苦。

\n

有没有办法通过名称模式匹配来注入瞬态作用域的属性?

\n

这并不gnome-shell具体;它也适用于调用命令的用户终端会话systemd-run --user --scope

\n

细节

\n

Firefox 肯定是在 systemd 范围内启动的,并且它有自己的 cgroup:

\n
$ systemctl --user status app-gnome-firefox-92450.scope\n\xe2\x97\x8f app-gnome-firefox-92450.scope - Application launched by gnome-shell\n     Loaded: loaded (/run/user/1000/systemd/transient/app-gnome-firefox-92450.scope; transient)\n  Transient: yes\n     Active: active (running) since Wed …
Run Code Online (Sandbox Code Playgroud)

linux gnome cgroup systemd

7
推荐指数
0
解决办法
1686
查看次数