系统服务路径:
root@firefly:/lib/systemd/system#
与之交互的工具 systemctl
列出linux上所有单元:
root@firefly:/lib/systemd/system# systemctl list-unit-files
root@firefly:/lib/systemd/system# systemctl list-unit-files --type-service
enable 不代表正在运行,表可以被启用的单元,
disable是被金庸的单元,
static 的不能直接启用,它们是其他单元所依赖的对象。
启动停止:
systemctl stop xx.service
systemctl start xx.service
如果某单元被禁用,可以先 systemctl enable该单元,将其启用
systemctl restart & systemctl reload + xx.service
自定义系统服务:
在相应路径下创建service文件:
systemd-qljown.service:
文件内容:
root@firefly:/lib/systemd/system# nl systemd-qljown.service
1 # SPDX-License-Identifier: LGPL-2.1+
2 #
3 # This file is part of systemd.
4 #
5 # systemd is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation; either version 2.1 of the License, or
8 # (at your option) any later version.
9 [Unit]
10 Description=qlj define service
11 #After=systemd-udevd.service
12 #Before=systemd-networkd.service
13 [Service]
14 Type=oneshot
15 ExecStart=/bin/bash /home/firefly/udev.sh
16 [Install]
17 WantedBy=multi-user.target
root@firefly:/lib/systemd/system#
systemctl daemon-reload
systemctl start systemd-qljown.service
systemctl enable systemd-qljown.service