首页 > 系统相关 >关于Linux中通过 Systemd Path Unit 监听配置更新自动重启服务的一些笔记

关于Linux中通过 Systemd Path Unit 监听配置更新自动重启服务的一些笔记

时间:2022-12-12 15:32:56浏览次数:77  
标签:Systemd github liruilongs systemd io Linux Path path root


写在前面


  • 在 ​​stackoverflow.com​​​ 的​​Unix & Linux​​ 社区 看到有小伙伴提出相关的问题。
  • 这里整理分享给小伙伴,博文内容涉及:
  • ​Systemd​​​ 的 ​​Path Units​​常用命令手册学习
  • ​Path Units​​ 的应用
  • 通过​​httpd​​服务演示监听配置文件自动重启服务
  • 食用方式:需要了解一点 ​​Systemd​
  • 理解不足小伙伴帮忙指正

在路上,我们永远年轻,永远热泪盈眶。 ——杰克·凯鲁亚克

​《在路上》​​ 这本书买了好久,大概是离我的生活太远了,看了几页就在没看过,或者应该这年少的时候读…


了解 ​​Systemd​​​ 的 ​​Path Units​

在这之前,需要简单的了解一下 ​​Systemd​​​ 的 ​​Path Units​​​ ,大概熟悉下是什么,​​Path Units​​​ 和我们经常讲的服务 ​​Service units​​​(sshd.service) 同属于 ​​Systemd​​ 的 Units。

┌──[[email protected]]-[~]
└─$systemctl status sshd.service
● sshd.service - OpenSSH server daemon
Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
Active: active (running) since 一 2022-10-24 09:41:59 CST; 1 day 2h ago
Docs: man:sshd(8)
man:sshd_config(5)
Main PID: 984 (sshd)
Memory: 4.5M
CGroup: /system.slice/sshd.service
└─984 /usr/sbin/sshd -D

10月 24 09:41:58 vms83.liruilongs.github.io systemd[1]: Starting OpenSSH server daemon...
10月 24 09:41:59 vms83.liruilongs.github.io sshd[984]: Server listening on 0.0.0.0 port 22.
10月 24 09:41:59 vms83.liruilongs.github.io sshd[984]: Server listening on :: port 22.
10月 24 09:41:59 vms83.liruilongs.github.io systemd[1]: Started OpenSSH server daemon.
..........

​Service Units​​​ 用于封装一个后台服务进程,而 ​​Path Units​​ 用于根据文件或目录变化来启动其他服务,类似一个监听器,面向对象里的观察者设计模式。这里他的通知对象时一个服务(service units)

常用命令

看一些常用的命令,查看当前 ​​Systemd​​​ 的所有 ​​Path Units​

┌──[[email protected]]-[~]
└─$systemctl list-unit-files -t path
UNIT FILE STATE
brandbot.path disabled
systemd-ask-password-console.path static
systemd-ask-password-plymouth.path static
systemd-ask-password-wall.path static

4 unit files listed.

查看单元配置文件

┌──[[email protected]]-[~]
└─$systemctl cat brandbot.path
# /usr/lib/systemd/system/brandbot.path
[Unit]
Description=Flexible branding

[Path]
PathExists=/var/lib/rhsm/branded_name
PathChanged=/var/lib/rhsm/branded_name

[Install]
WantedBy=multi-user.target
┌──[[email protected]]-[~]
└─$

正向依赖

┌──[[email protected]]-[~]
└─$systemctl list-dependencies brandbot.path
brandbot.path
● ├─-.mount
● └─sysinit.target
● ├─dev-hugepages.mount
.........
● ├─sys-kernel-debug.mount
● ├─systemd-ask-password-console.path
.......
● ├─local-fs.target
● │ ├─-.mount
● │ ├─rhel-import-state.service
● │ ├─rhel-readonly.service
● │ └─systemd-remount-fs.service
● └─swap.target

反向依赖

┌──[[email protected]]-[~]
└─$systemctl list-dependencies brandbot.path --reverse
brandbot.path
● └─multi-user.target
● └─graphical.target
┌──[[email protected]]-[~]
└─$

单元状态信息

┌──[[email protected]]-[~]
└─$systemctl status brandbot.path
● brandbot.path - Flexible branding
Loaded: loaded (/usr/lib/systemd/system/brandbot.path; disabled; vendor preset: disabled)
Active: active (waiting) since 一 2022-10-24 09:41:53 CST; 1 day 2h ago

10月 24 09:41:53 vms83.liruilongs.github.io systemd[1]: Started Flexible branding.
10月 24 09:41:53 vms83.liruilongs.github.io systemd[1]: Starting Flexible branding.
┌──[[email protected]]-[~]
└─$

手册中的介绍

┌──[[email protected]]-[~]
└─$man systemd | grep -A 2 "Path units"
10. Path units may be used to activate other services when file system objects change or are modified. See
systemd.path(5).

┌──[[email protected]]-[~]
└─$

path 单元。 用于根据文件系统上特定对象的变化来启动其他服务。参见 systemd.path(5) 手册。看下具体的手册

┌──[[email protected]]-[~]
└─$man systemd.path | cat
SYSTEMD.PATH(5) systemd.path SYSTEMD.PATH(5)
。。。。
NAME
systemd.path - Path unit configuration

SYNOPSIS
path.path

DESCRIPTION
# 以 ".path" 为后缀的单元文件, 封装了一组由 systemd 监视的文件系统路径,以支持基于路径的启动。
A unit configuration file whose name ends in ".path" encodes information about a path monitored by systemd, for
path-based activation.

# 本手册列出了所有专用于此类单元的 配置选项(亦称"配置指令"或"单元属性")。 systemd.unit(5) 中描述了通用于所有单元类型的配置选项,
# 它们位于 [Unit] 与 [Install] 小节。此类单元专用的配置选项 位于 [Path] 小节。
This man page lists the configuration options specific to this unit type. See systemd.unit(5) for the common options of
all unit configuration files. The common configuration items are configured in the generic [Unit] and [Install]
sections. The path specific configuration options are configured in the [Path] section.


# 每个路径单元都必须有一个与其匹配的单元, 以用于在路径发生变化时启动。 匹配的单元可以通过 Unit= 选项(见下文)明确指定。
# 若未指定,则默认是与该单元名称相同的 .service 单元(不算后缀)。 例如 foo.path 默认匹配 foo.service 单元。
For each path file, a matching unit file must exist, describing the unit to activate when the path changes. By default,
a service by the same name as the path (except for the suffix) is activated. Example: a path file foo.path activates a
matching service foo.service. The unit to activate may be controlled by Unit= (see below).

# 因为在单元内部实际上使用内核的 inotify(7) 函数监视文件系统的变化, 所以,受制于 inotify 的缺陷,
# 只能监视本机文件系统的变化, 而不能监视远程网络文件系统的变化。
Internally, path units use the inotify(7) API to monitor file systems. Due to that, it suffers by the same limitations
as inotify, and for example cannot be used to monitor files or directories changed by other machines on remote NFS file
systems.

If a path unit is beneath another mount point in the file system hierarchy, a dependency between both units is created
automatically.

# 除非明确设置了 DefaultDependencies=no ,否则 path 单元将会自动添加下列依赖关系:

#Before=paths.target, After=sysinit.target, Requires=sysinit.target, Conflicts=shutdown.target, Before=shutdown.target ,
# 以确保该单元在关机前可以被干净的关闭。 只有那些在系统启动早期就必须启动的路径,以及那些必须在关机流程结尾才能停止的路径才需要设置

Unless DefaultDependencies=false is used, path units will implicitly have dependencies of type Conflicts= and Before=
on shutdown.target. These ensure that path units are terminated cleanly prior to system shutdown. Only path units
involved with early boot or late system shutdown should disable this option.

OPTIONS
# 路径单元文件必须包含一个 [Path] 部分,其中包含有关它监视的一个或多个路径的信息。
# 特定于路径单元的 [Path] 部分的选项如下:
Path files must include a [Path] section, which carries information about the path(s) it monitors. The options specific
to the [Path] section of path units are the following:

PathExists=, PathExistsGlob=, PathChanged=, PathModified=, DirectoryNotEmpty=
# 定义监视哪种类型的路径变化:
# PathExists= 监视指定的路径是否存在, 若存在则启动匹配单元。
# PathExistsGlob= 监视是否存在至少一个与模式匹配的路径,若存在则启动匹配单元。
# PathChanged= 监视指定路径的写入句柄是否恰好被关闭, 若存在写入句柄且恰好被关闭, 则启动匹配单元。
# PathModified= 监视指定路径的最后修改时间是否发生变化, 若发生变化则启动匹配单元。
# DirectoryNotEmpty= 监视指定的文件夹是否非空,若包含至少一个文件或子目录, 则启动匹配单元。

Defines paths to monitor for certain changes: PathExists= may be used to watch the mere existence of a file or
directory. If the file specified exists, the configured unit is activated. PathExistsGlob= works similar, but
checks for the existence of at least one file matching the globbing pattern specified. PathChanged= may be used to
watch a file or directory and activate the configured unit whenever it changes. It is not activated on every write
to the watched file but it is activated if the file which was open for writing gets closed. PathModified= is
similar, but additionally it is activated also on simple writes to the watched file. DirectoryNotEmpty= may be
used to watch a directory and activate the configured unit whenever it contains at least one file.

# 所有这些选项的值 都必须是绝对路径。
The arguments of these directives must be absolute file system paths.

# 可以多次使用这些选项 以监控多个路径。 如果为某个选项指定了一个空字符串, 则表示清空该选项 之前设置的所有监视路径。
Multiple directives may be combined, of the same and of different types, to watch multiple paths. If the empty
string is assigned to any of these options, the list of paths to watch is reset, and any prior assignments of these
options will not have any effect.


# 如果在启动 path 单元时, 指定的路径已经存在(对于 PathExists= 与 PathExistsGlob= 来说)
# 或者 指定的目录非空(对于 DirectoryNotEmpty= 来说), 那么将会立即同时启动匹配单元。 不过,
# 对于 PathChanged= 与 PathModified= 来说,并不遵守这个规则。
If a path already exists (in case of PathExists= and PathExistsGlob=) or a directory already is not empty (in case
of DirectoryNotEmpty=) at the time the path unit is activated, then the configured unit is immediately activated as
well. Something similar does not apply to PathChanged= and PathModified=.


# 如果没有权限监视指定的路径, 那么 systemd 将会 一直等待权限满足之后 才会开始监视。
If the path itself or any of the containing directories are not accessible, systemd will watch for permission

changes and notice that conditions are satisfied when permissions allow that.

Unit=
# 该路径单元的匹配单元, 也就是被路径的变化启动的单元。 参数是一个不以 ".path" 结尾的单元名。
# 默认值是与此路径单元同名的服务单元(见上文)。
# 建议将路径单元的名字 与被该路径启动的匹配单元的名字 保持一致 (也就是仅单元后缀名不同)。
The unit to activate when any of the configured paths changes. The argument is a unit name, whose suffix is not
".path". If not specified, this value defaults to a service that has the same name as the path unit, except for the
suffix. (See above.) It is recommended that the unit name that is activated and the unit name of the path unit are
named identical, except for the suffix.

MakeDirectory=
# 接受一个布尔值。 设为 yes 表示如果指定的目录不存在则首先创建它然后再监视它。 此选项对 PathExists= 无效。 默认值为 no
Takes a boolean argument. If true, the directories to watch are created before watching. This option is ignored for
PathExists= settings. Defaults to false.

DirectoryMode=
# 选项指定在 MakeDirectory= 时新建目录的权限(八进制表示法)。 默认值是 0755
If MakeDirectory= is enabled, use the mode specified here to create the directories in question. Takes an access
mode in octal notation. Defaults to 0755.

SEE ALSO
systemd(1), systemctl(1), systemd.unit(5), systemd.service(5), inotify(7), systemd.directives(7)



systemd 219 SYSTEMD.PATH(5)
┌──[[email protected]]-[~]
└─$

OK,很全面的一个帮助文档,如果希望了解 Path Units ,需要耐心的看完它

​Path Units​​ 的应用

监控文件变化发送告警邮件

看一个Demo:

这里我们通过 监听 ​​/etc/passwd​​​ 的变化来创建一个 ​​update-user-info.path​​​ Path Units, 实现这文件变化时,发送告警邮件,所以我们需要一个可以发送告警的服务 ​​update-user-info.service​​ Services Units 。用于 Path unids 启动。

需要做下面一些工作:

  • 创建一个 服务单元 ​​update-user-info.service​
  • 创建服务调用的脚本:​​email-alert.sh​
  • 创建一个 路径单元:​​update-user-info.path​

发送邮件,如果没有邮件服务器,可能需要搭建一个空客户端的邮件服务器,如果有的可以忽略这部分,这里主要用到 ​​postfix​​​和​​mailx​

安装 postfix 邮件服务器

┌──[[email protected]]-[/var/spool/mail]
└─$yum -y install postfix

相关配置,下面是没有DNS服务器的配置

┌──[[email protected]]-[~]
└─$postconf mynetworks
mynetworks = 127.0.0.0/8 [::1]/128
┌──[[email protected]]-[~]
└─$postconf -e 'inet_interfaces = loopback-only'
┌──[[email protected]]-[~]
└─$postconf -e ' relayhost = [smtp.vms82.liruilongs.github.io]'
┌──[[email protected]]-[~]
└─$postconf -e 'mydestination = vms82.liruilongs.github.io'
┌──[[email protected]]-[~]
└─$systemctl restart postfix

处理邮件需要的工具

┌──[[email protected]]-[~]
└─$yum -y install mailx

测试一下

┌──[[email protected]]-[~]
└─$mail -s 'init test' [email protected]
test
.
EOT
┌──[[email protected]]-[~]
└─$cat /var/spool/mail/tom
From [email protected] Mon Oct 24 15:39:25 2022
Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: by vms82.liruilongs.github.io (Postfix, from userid 0)
id C7A2A1002EF2A; Mon, 24 Oct 2022 15:39:25 +0800 (CST)
Date: Mon, 24 Oct 2022 15:39:25 +0800
To: [email protected]
Subject: init test
User-Agent: Heirloom mailx 12.5 7/5/10
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <[email protected]>
From: [email protected] (root)

test

OK,测试没有问题的话,我们需要编写一个脚本,这里需要非交互式的方式来发送告警邮件

┌──[[email protected]]-[~]
└─$mail --help
mail: illegal option -- -
Usage: mail -eiIUdEFntBDNHRVv~ -T FILE -u USER -h hops -r address -s SUBJECT -a FILE -q FILE -f FILE -A ACCOUNT -b USERS -c USERS -S OPTION users
┌──[[email protected]]-[~]
└─$vim email-alert.sh
┌──[[email protected]]-[~]
└─$cat email-alert.sh
#!/bin/bash

#@File : bash.sh
#@Time : 2022/10/25 20:47:04
#@Author : Li Ruilong
#@Version : 1.0
#@Desc : None
#@Contact : [email protected]

# -s :指定邮件主题

mail -s "ETC PASSWD CHANGED ON $(hostname) $(date '+%x %X')" [email protected] < /etc/passwd
┌──[[email protected]]-[~]
└─$mv email-alert.sh /usr/local/bin/
┌──[[email protected]]-[~]
└─$

创建服务单元文件以执行脚本, 唯一需要关注的是 ​​ExecStart=/usr/local/bin/email-alert.sh​​ 指定启动进程的命令

┌──[[email protected]]-[~]
└─$cd /usr/lib/systemd/system/
┌──[[email protected]]-[/usr/lib/systemd/system]
└─$vim update-user-info.service
┌──[[email protected]]-[/usr/lib/systemd/system]
└─$cat /usr/lib/systemd/system/update-user-info.service

[Unit]
Description="Run script to send email alert"
After=network-online.target

[Service]
ExecStart=/usr/local/bin/email-alert.sh
ExecStop=/bin/kill -WINCH ${MAINPID}


[Install]
WantedBy=multi-user.target
┌──[[email protected]]-[/usr/lib/systemd/system]
└─$

创建路径单元文件,具体的参数小伙伴可以看上面的帮助文档,简单说明:​​PathModified​​​ 指定监控的文件,​​Unit​​指定激活的服务

┌──[[email protected]]-[/usr/lib/systemd/system]
└─$fg
vim update-user-info.path
┌──[[email protected]]-[/usr/lib/systemd/system]
└─$cat /usr/lib/systemd/system/update-user-info.path
[Unit]
Description="Monitor the /etc/passwd file for changes"

[Path]
PathModified=/etc/passwd
Unit=update-user-info.service

[Install]
WantedBy=multi-user.target
┌──[[email protected]]-[/usr/lib/systemd/system]
└─$

文件语法校验

┌──[[email protected]]-[/usr/lib/systemd/system]
└─$systemd-analyze verify /usr/lib/systemd/system/update-user-info.*
update-user-info.service: command /usr/local/bin/email-alert.sh is not executable: 权限不够
┌──[[email protected]]-[/usr/lib/systemd/system]
└─$chmod +x /usr/local/bin/email-alert.sh
┌──[[email protected]]-[/usr/lib/systemd/system]
└─$systemd-analyze verify /usr/lib/systemd/system/update-user-info.*
┌──[[email protected]]-[/usr/lib/systemd/system]
└─$

启动 ​​update-user-info.path ​​ 并设置开启自启

┌──[[email protected]]-[/usr/lib/systemd/system]
└─$systemctl enable update-user-info.path --now
Created symlink from /etc/systemd/system/multi-user.target.wants/update-user-info.path to /usr/lib/systemd/system/update-user-info.path.

添加用户测试

┌──[[email protected]]-[/usr/lib/systemd/system]
└─$useradd shanheyiwuyang
┌──[[email protected]]-[/usr/lib/systemd/system]
└─$

查看服务路径启动情况

┌──[[email protected]]-[/usr/lib/systemd/system]
└─$journalctl -u update-user-info.path
-- Logs begin at 一 2022-10-24 09:41:47 CST, end at 二 2022-10-25 17:57:25 CST. --
10月 25 16:37:42 vms82.liruilongs.github.io systemd[1]: Started "Monitor the /etc/passwd file for chang
10月 25 16:37:42 vms82.liruilongs.github.io systemd[1]: Starting "Monitor the /etc/passwd file for chan
┌──[[email protected]]-[/usr/lib/systemd/system]
└─$journalctl -u update-user-info.service
-- Logs begin at 一 2022-10-24 09:41:47 CST, end at 二 2022-10-25 17:57:31 CST. --
10月 25 16:38:26 vms82.liruilongs.github.io systemd[1]: Started "Run script to send email alert".
10月 25 16:38:26 vms82.liruilongs.github.io systemd[1]: Starting "Run script to send email alert"...

邮件发送情况

┌──[[email protected]]-[/usr/lib/systemd/system]
└─$tail -n 5 /var/mail/tom
tomcat:x:53:53:Apache Tomcat:/usr/share/tomcat:/sbin/nologin
sy:x:1004:1004::/home/sy:/bin/bash
shanhewuyang:x:1005:1005::/home/shanhewuyang:/bin/bash
shanheyiwuyang:x:1006:1006::/home/shanheyiwuyang:/bin/bash

监听配置文件自动重启服务

来看另一个 path units 的应用,对于监听配置文件跟新自动重启服务来讲,只需要两个操作:

  • 创建一个监听配置文件的 路径单元
  • 创建一个重启指定服务的服务单元

这里我们以httpd服务为Demo

服务准备

┌──[[email protected]]-[~]
└─$rpm -q httpd
package httpd is not installed
┌──[[email protected]]-[~]
└─$yum -y install httpd
┌──[[email protected]]-[~]
└─$systemctl start httpd
┌──[[email protected]]-[~]
└─$systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2022-10-25 17:12:10 CST; 4s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 6264 (httpd)
Status: "Processing requests..."
CGroup: /system.slice/httpd.service
├─6264 /usr/sbin/httpd -DFOREGROUND
├─6265 /usr/sbin/httpd -DFOREGROUND
├─6266 /usr/sbin/httpd -DFOREGROUND
├─6267 /usr/sbin/httpd -DFOREGROUND
├─6268 /usr/sbin/httpd -DFOREGROUND
└─6269 /usr/sbin/httpd -DFOREGROUND

10月 25 17:12:09 vms152.liruilongs.github.io systemd[1]: Starting The Apache HTTP Server...
10月 25 17:12:10 vms152.liruilongs.github.io systemd[1]: Started The Apache HTTP Server.
┌──[[email protected]]-[~]
└─$ss -nutlpa | grep http
tcp LISTEN 0 128 :::80 :::* users:(("httpd",pid=6269,fd=4),("httpd",pid=6268,fd=4),("httpd",pid=6267,fd=4),("httpd",pid=6266,fd=4),("httpd",pid=6265,fd=4),("httpd",pid=6264,fd=4))
┌──[[email protected]]-[~]
└─$

创建路径单元

需要监听的配置文件 ​​/etc/httpd/conf/httpd.conf​​​,需要通知的服务​​httpd-restart.service​

┌──[[email protected]]-[~]
└─$fg
vim /usr/lib/systemd/system/httpd-restart.path
┌──[[email protected]]-[~]
└─$cat /usr/lib/systemd/system/httpd-restart.path
[Unit]
Description="change httpd conf"
After=network-online.target

[Path]
Unit=httpd-restart.service
PathChanged=/etc/httpd/conf/httpd.conf

[Install]
WantedBy=multi-user.target
┌──[[email protected]]-[~]
└─$

创建服务单元

重启服务单元: ​​httpd-restart.service​​,

┌──[[email protected]]-[~]
└─$vim /usr/lib/systemd/system/httpd-restart.service
┌──[[email protected]]-[~]
└─$cat /usr/lib/systemd/system/httpd-restart.service
[Unit]
Description= update httpd config , restart httpd service
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl restart httpd.service

[Install]
WantedBy=multi-user.target
┌──[[email protected]]-[~]
└─$

测试单元文件

┌──[[email protected]]-[~]
└─$systemd-analyze verify /usr/lib/systemd/system/httpd-restart.*
┌──[[email protected]]-[~]
└─$

查看当前服务进程ID

┌──[[email protected]]-[~]
└─$systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2022-10-25 17:12:10 CST; 1h 19min ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 6264 (httpd)
Status: "Total requests: 9; Current requests/sec: 0; Current traffic: 0 B/sec"
10月 25 17:12:10 vms152.liruilongs.github.io systemd[1]: Started The Apache HTTP Server.

修改配置文件,替换端口

┌──[[email protected]]-[~]
└─$sed 's/^Listen 80/Listen 8023/g' /etc/httpd/conf/httpd.conf | grep ^Listen
Listen 8023
┌──[[email protected]]-[~]
└─$sed 's/^Listen 80/Listen 8023/g' /etc/httpd/conf/httpd.conf -i

再次查看,PID发生变化,说明重启成功

┌──[[email protected]]-[~]
└─$systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2022-10-25 18:32:55 CST; 2s ago
Docs: man:httpd(8)
man:apachectl(8)
Process: 6420 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
Main PID: 6425 (httpd)
10月 25 18:32:55 vms152.liruilongs.github.io systemd[1]: Starting The Apache HTTP Server...
10月 25 18:32:55 vms152.liruilongs.github.io systemd[1]: Started The Apache HTTP Server.

查看新建单元的日志

┌──[[email protected]]-[~]
└─$journalctl -u httpd-restart.path
-- Logs begin at 三 2022-10-19 16:32:20 CST, end at 二 2022-10-25 18:32:55 CST. --
10月 25 18:32:40 vms152.liruilongs.github.io systemd[1]: Started "change httpd conf".
10月 25 18:32:40 vms152.liruilongs.github.io systemd[1]: Starting "change httpd conf".
┌──[[email protected]]-[~]
└─$journalctl -u httpd-restart.service
-- Logs begin at 三 2022-10-19 16:32:20 CST, end at 二 2022-10-25 18:32:55 CST. --
10月 25 18:32:54 vms152.liruilongs.github.io systemd[1]: Starting update httpd config , restart httpd s10月 25 18:32:55 vms152.liruilongs.github.io systemd[1]: Started update httpd config , restart httpd se
┌──[[email protected]]-[~]
└─$

博文引用的资源


​systemd.path 中文手册:译者:金步国 :http://www.jinbuguo.com/systemd/systemd.path.html​

​systemd.path — Path unit configuration :https://www.freedesktop.org/software/systemd/man/systemd.path.html​

​Using systemd Path Units to Monitor Files and Directories :https://www.putorius.net/systemd-path-units.html​

​How to automatically restart systemd service if file is changed? :https://unix.stackexchange.com/questions/722209/how-to-automatically-restart-systemd-service-if-file-is-changed/722223#722223​


标签:Systemd,github,liruilongs,systemd,io,Linux,Path,path,root
From: https://blog.51cto.com/u_13474506/5929842

相关文章

  • 关于Linux挂载 fstab 和 systemd.mount 使用场景的一些笔记
    写在前面在​​stackoverflow​​​的​​Unix&Linux​​社区看到相关的问题。有大佬做了解答,感觉问题不错,答案也不错,整理分享给小伙伴原问题地址:​​tmpontmpfs:fs......
  • 关于 Linux中systemd的一些笔记
    写在前面嗯,准备​​RHCA​​,学习整理这部分知识博文内容涉及:​​systemd​​简述对于​​unit​​的信息的介绍通过​​systemctl​​​命令控制​​Serviceunit​​......
  • Linux查找find命令全面剖析
    Linux查找find命令全面剖析1.文件查找在文件系统上查找符合条件的文件1.1简述locate命令非实时查找(数据库查找)依赖于事先构建的索引,索引的构建是在系统较为空闲时自动......
  • visual studio 2015/2019下使用gcc调试linux c++开发环境搭建完整详解
    一直以来,相信绝大部分的开发都是windows/mac下做开发,尤其是非嵌入式和qt系的,而开源服务器程序绝大部分都是跑在Linux下,几乎就没有跑在windows下的。一直以来开发人员都......
  • core部署linux、国产化
    前言:本文基于centos7.9操作系统,服务器x86/x64,所有操作在虚拟机中操作,记录部署过程中出现的问题,在此记录解决方案。查看系统版本命令:cat/etc/redhat-releasecat/proc/v......
  • 技术干货 | 漫游Linux块IO
     前言在计算机的世界里,我们可以将业务进行抽象简化为两种场景——计算密集型和IO密集型。这两种场景下的表现,决定这一个计算机系统的能力。数据库作为一个典型的基础软件,它......
  • Python虚拟环境(二):Linux基于Anaconda创建虚拟环境并打包
    1、创建并查看虚拟环境1、创建虚拟环境condacreate-npy37python3.7#创建一个名称为py37的Python版本为3.7的Python虚拟环境#或condacreate-npy37--copyy......
  • Linux 安装及使用 anaconda
    Anaconda安装与卸载Anaconda使用参考TOCAnaconda安装与卸载1、下载Anaconda途经一:官网下载,但速度很慢地址:https://www.continuum.io/downloads途经二:从清华大学镜......
  • linux环境与IDE
    1 Linux上练习和开发 1.1 安装centos环境1.1.1 windows机器上安装虚拟机vmware​​https://www.likecs.com/show-145995.html​​ 1.1.2 下载centos7操作系统光盘......
  • 细说nodejs的path模块
    前言path模块是nodejs中用于处理文件/目录路径的一个内置模块,可以看作是一个工具箱,提供诸多方法供我们使用,当然都是和路径处理有关的。同时在前端开发中path模块出现......