标签: systemctl

service 和 systemctl 有什么区别?

也许这是一个微不足道的问题,但对我来说并不完全清楚。在我们的一台服务器上,我们运行了一些后台进程,它们以 开头,service而其他一些以 开头systemctl,如下所示:

$ service nginx start
$ systemctl start gunicorn
Run Code Online (Sandbox Code Playgroud)

这两个命令有什么区别?哪一种是处理后台服务的首选方式?如何配置首选命令?

service systemctl

67
推荐指数
3
解决办法
4万
查看次数

无法获得 D-Bus 连接:不允许操作

我正在尝试使用在 Docker 中运行的 CentOS 映像列出服务

systemctl list-units  
Run Code Online (Sandbox Code Playgroud)

但我收到此错误消息:

Failed to get D-Bus connection: Operation not permitted
Run Code Online (Sandbox Code Playgroud)

任何建议可能是什么问题?

centos systemd systemctl docker

56
推荐指数
3
解决办法
15万
查看次数

如何允许用户使用 journalctl 查看用户特定的 systemd 服务日志?

我在 Ubuntu 16.04 LTS 中运行用户级服务。例如,我的 test.service 位于~/.config/systemd/user/test.service.

我能够通过这样做来运行服务

systemctl --user start test.target
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用 读取其日志时journalctl,收到以下错误消息:

journalctl --user -u test.service
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)

如何journalctl用于用户的特定单位?

permissions systemd systemctl journalctl ubuntu-16.04

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

使用 systemctl 停止服务后,服务仍处于失败状态

我们有一个简单的 systemd 脚本来以服务方式启动 MineCraft 服务器。SO 是 CentOS 7。这里的脚本:

[Unit]
Description=Minecraft Server
After=syslog.target network.target

[Service]
Type=simple
WorkingDirectory=/root/Minecraft
ExecStart=/bin/java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
Restart=on-failure

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

启动服务工作正常,但停止时,服务仍处于失败状态。看:

systemctl status minecraftd.service
minecraftd.service - Minecraft Server
   Loaded: loaded (/usr/lib/systemd/system/minecraftd.service; disabled)
   Active: active (running) since Mon 2015-06-01 16:00:12 UTC; 18s ago
 Main PID: 20975 (java)
   CGroup: /system.slice/minecraftd.service
           ??20975 /bin/java -Xmx1024M -Xms1024M -jar minecraft_server.jar nogui
systemctl stop minecraftd.service
systemctl status minecraftd.service
minecraftd.service - Minecraft Server
   Loaded: loaded (/usr/lib/systemd/system/minecraftd.service; disabled)
   Active: failed (Result: exit-code) since Mon …
Run Code Online (Sandbox Code Playgroud)

systemd systemctl

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

无法运行 Kubelet:验证服务连接:端点未实现 CRI v1 运行时 API

我已经kubelet 1.26.0使用命令安装在 Ubuntu 22.04 上apt install kubelet,但是当我尝试时journalctl -xeu kubelet得到以下结果:

\n
\xe2\x96\x91\xe2\x96\x91 \n\xe2\x96\x91\xe2\x96\x91 The unit kubelet.service has entered the 'failed' state with result 'exit-code'.\nDec 14 15:41:16 a systemd[1]: kubelet.service: Scheduled restart job, restart counter is at 86.\n\xe2\x96\x91\xe2\x96\x91 Subject: Automatic restarting of a unit has been scheduled\n\xe2\x96\x91\xe2\x96\x91 Defined-By: systemd\n\xe2\x96\x91\xe2\x96\x91 Support: http://www.ubuntu.com/support\n\xe2\x96\x91\xe2\x96\x91 \n\xe2\x96\x91\xe2\x96\x91 Automatic restarting of the unit kubelet.service has been scheduled, as the result for\n\xe2\x96\x91\xe2\x96\x91 the configured Restart= setting for the unit.\nDec 14 15:41:16 a systemd[1]: …
Run Code Online (Sandbox Code Playgroud)

configuration systemd systemctl kubernetes kubeadm

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

systemd 服务中延迟时间的含义是什么?

我已经在 CentOS 7 上安装了 Puppet Enterprise。我可以看到几个 Puppet 服务无法开始说延迟时间结束。这是什么意思?

Sep 03 20:50:16 l-pm1 systemd[1]: pe-puppetdb.service holdoff time over, scheduling restart.
Sep 03 20:50:16 l-pm1 systemd[1]: Starting pe-puppetdb Service...
Run Code Online (Sandbox Code Playgroud)

puppet systemctl

15
推荐指数
1
解决办法
3万
查看次数

Redis 不以 systemctl 开头

我已经在 ubuntu 16.04 机器上安装了 redis,如果我运行/usr/local/bin/redis-server /etc/redis/cluster/7000/redis.conf它,它会启动并且我可以毫无问题地连接到它。

但是我想使用它来启动它systemctl start redis,所以我在以下位置创建了以下文件/etc/systemd/system/redis7000.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/redis-server /etc/redis/cluster/7000/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

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

并且 redis 配置已supervised systemd设置

我认为看起来不错,但我收到以下错误:

Jan 19 14:54:27 ip-172-31-42-18 systemd[1]: Started Redis In-Memory Data Store.
Jan 19 14:54:27 ip-172-31-42-18 redis-server[21661]: 21661:C 19 Jan 14:54:27.680 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
Jan 19 14:54:27 ip-172-31-42-18 redis-server[21661]: 21661:C 19 Jan 14:54:27.680 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=21661, just started …
Run Code Online (Sandbox Code Playgroud)

ubuntu redis systemd systemctl

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

为什么 systemctl 在 CentOS 7 上不启动 redis-server?

我已经在新的 CentOS 7 机器上安装了 redis,但无法使用 systemctl 启动它。

它是这样安装的:

rpm -i http://dl.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm
yum install redis
Run Code Online (Sandbox Code Playgroud)

尝试像这样启动它似乎默默地失败了(没有输出):

systemctl start redis-server # also tried redis-server.service
Run Code Online (Sandbox Code Playgroud)

以下是尝试连接时发生的情况:

redis-cli
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
Run Code Online (Sandbox Code Playgroud)

但是手动启动它是有效的:

[root@redis ~]# redis-server /etc/redis.conf
[root@redis ~]# redis-cli
127.0.0.1:6379>
Run Code Online (Sandbox Code Playgroud)

任何人都知道出了什么问题,或者如何调试?

更新:输出/var/log/redis/redis.log如下。顺便说一句,这是一个 512mb RAM VPS。

[1972] 29 Jul 18:52:16.258 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
[1972] 29 Jul 18:52:16.258 # Redis can't set maximum open files to …
Run Code Online (Sandbox Code Playgroud)

redis systemctl centos7

13
推荐指数
1
解决办法
3万
查看次数

Nginx 使用“service nginx start”挂起

我已经为我的生产服务器编译了带有自定义路径的 nginx,当我尝试使用以下命令启动/重新启动服务时:

service nginx start
Run Code Online (Sandbox Code Playgroud)

或者

service nginx restart
Run Code Online (Sandbox Code Playgroud)

它进入一个新行而不返回shell: 运行命令时的终端图片

所以问题是我无法使用service命令控制nginx 。该服务实际上在运行,但它不会向我返回一个 shell,所以我总是必须按ctrl+c才能将其取回。

我还必须提到 nginx 在通过自己的nginx命令调用它时运行得很好,并且使用nginx -s stop/reload.

这个问题在使用systemctl start nginx中仍然存在,但systemctl stop nginx工作得很好。

信息:

$ lsb_release -a
    Distributor ID: Ubuntu
    Description:    Ubuntu 15.10
    Release:    15.10
    Codename:   wily

$ uname -r
    4.2.0-27-generic

$ nginx -V
    nginx version: nginx/1.9.11
    built by gcc 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2) 
    built with OpenSSL 1.0.2d 9 Jul 2015
    TLS SNI support enabled
    configure …
Run Code Online (Sandbox Code Playgroud)

ubuntu nginx service systemctl docker

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

如何预测 systemd 的关闭顺序?

有没有办法systemd告诉我当我干净地关闭整个系统时它将关闭服务粗略顺序?由于systemd将并行关闭,我很欣赏没有办法知道确切的顺序,但了解systemd关闭顺序会施加哪些约束仍然会非常有帮助,最好是在某种易于理解的可视化中。

动机是为了服务文件的开发和调试,拿到这个会方便很多 提前预测列表,而不是每次我想确定的时候都要真正关机再开机再检查日志对服务单元文件或 systemd 配置的其他方面的更改将对关闭顺序产生什么影响。

我希望像

systemctl list-dependencies --before shutdown.service
Run Code Online (Sandbox Code Playgroud)

会做这项工作,但它只发出:

shutdown.service
Run Code Online (Sandbox Code Playgroud)

dependencies systemd shutdown systemctl

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