搬運文
1.1 [/usr]/lib/systemd/system/ (軟件包安裝的單元)
The expectation is that /lib/systemd/system
is a directory that should only contain systemd unit files which were put there by the package manager (YUM/DNF/RPM/APT/etc).
1.2 /etc/systemd/system/(系統管理員安裝的單元, 優先級更高)
Files in /etc/systemd/system
are manually placed here by the operator of the system for ad-hoc software installations that are not in the form of a package. This would include tarball type software installations or home grown scripts.
2. 優先級
systemd的使用大幅提高了系統服務的運行效率, 而unit的文件位置一般主要有三個目錄:
1 |
Table 1. Load path when running in system mode (--system). |
這三個目錄的配置文件優先級依次從高到低,如果同一選項三個地方都配置了,優先級高的會覆蓋優先級低的。
系統安裝時,默認會將unit文件放在/lib/systemd/system
目錄。如果我們想要修改系統默認的配置,比如nginx.service
,一般有兩種方法:
- 在
/etc/systemd/system
目錄下創建nginx.service
文件,里面寫上我們自己的配置。 - 在
/etc/systemd/system
下面創建nginx.service.d
目錄,在這個目錄里面新建任何以.conf結尾的文件,然后寫入我們自己的配置。推薦這種做法。
/run/systemd/system
這個目錄一般是進程在運行時動態創建unit文件的目錄,一般很少修改,除非是修改程序運行時的一些參數時,即Session級別的,才在這里做修改。
參考:https://www.dazhuanlan.com/2020/03/14/5e6cb299378a9/