systemctl 基本用法

基本

创建的启动项存放在 /etc/systemd/system/ 目录下

常用命令:

启动服务: sudo systemctl start service_name
停止服务: sudo systemctl stop service_name
重启服务: sudo systemctl restart service_name
查看服务状态: systemctl status service_name
启用服务自动启动: sudo systemctl enable service_name
禁用服务自动启动: sudo systemctl disable service_name

查看所有正在运行的服务: systemctl list-units --type=service --state=running
查看所有已启用的服务: systemctl list-unit-files --type=service --state=enabled
查看服务日志: journalctl -u service_name
重载 systemd 配置: systemctl daemon-reload
查看系统默认 target: systemctl get-default
设置系统默认 target: systemctl set-default target_name

常用启动脚本:

[Unit]
Description=Nginx Service
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
Restart=on-failure

[Install]
WantedBy=multi-user.target
[Unit]
Description=chfs Service
After=network.target

[Service]
Type=simple
ExecStart=/home/cl/chfs/chfs-linux-amd64-3.1 -path="/data|/home/cl/downloads" -port=9006
Restart=on-failure

[Install]
WantedBy=multi-user.target
posted @ 2024-09-10 09:35  LiuChengloong  阅读(19)  评论(0编辑  收藏  举报