shell编程===》systemctl管理脚本
发布日期:2021-05-10 08:10:36 浏览次数:12 分类:精选文章

本文共 3302 字,大约阅读时间需要 11 分钟。

������ctl������������������

������������ctl������������

���Linux������������������ctl���systemctl������������������������������������������systemd���������systemctl���������������`/usr/lib/systemd/`������������������������������������������������

  • 1���/usr/lib/systemd/system������������������������������������������������������������������������������������������init���������
  • 2���/usr/lib/systemd/user������������������������������������������������������������������������������

������ctl���������������������

  • 1���*.service������������������������������������������������������������
  • 2���*.target���������������������������������������������������������������

���systemd������������������������������������������������

  • Type���������������������������������������`forking`���������`simple`���`oneshot`���`dbus`���`notify`���`idle`������������
  • EnvironmentFile������������������������������������������������-������������������������������������`Environment=-/path/to/config`���������������������������������������
  • KillMode���������������������������������������������������������`control-group`���������`process`���`mixed`���`none`������
  • Restart���������������������������������������`no`���������`on-failure`���`on-abort`������
  • ExecStart���`ExecReload`���������������������������������������������������������������������������������
  • PrivateTmp���������������������������������������������

������[Install]������������������������������������������`WantedBy=multi-user.target`���

������������������������������������`*.service`���������������`systemctl daemon-reload`���systemd���������������������

������������������

������������systemctl���������������������������������������Nginx���������������ctl���������������

#!/bin/bash
case $1 in
start)
systemctl start nginx
check_status nginx
;;
stop)
systemctl stop nginx
check_status nginx
;;
reload)
systemctl reload nginx
check_status nginx
;;
status)
check_status nginx
;;
*)
echo "Usage: $0 {start|stop|reload|status}"
exit 1
esac

������������������`check_status`������������������������������������������������������������������������

```bash chmod +x nginx.sh ```

������������������������������������

```bash systemctl enable nginx ```

���������������/usr/lib/systemd/system/nginx.service������

```ini [Unit] Description=Nginx������

[Service] Type=forking ExecStart=/usr/local/nginx/bin/nginx ExecStop=/usr/local/nginx/bin/nginx stopping PrivateTmp=true

[Install] WantedBy=multi-user.target

���������������������

```bash
systemctl start nginx
systemctl status nginx

������������ctl������������������

1.���������������

```bash systemctl start # ������������ systemctl stop # ������������ systemctl restart # ������������������ systemctl reload # ������������������������ systemctl status # ������������������ ```

2.���������������

```bash systemctl enable # ������������������������������ systemctl disable # ��������������������������� ```

3.���������������

```bash systemctl list-unit-files # ������������������������������������ systemctl disable --now # ������������������ systemctl kill # ������������������������������������ ```

���������������������������������������Linux������������systemd���������������������������������������������������������������������������������������������������������������������������������

上一篇:shell编程===》进程锁
下一篇:shell编程===》三剑客之awk命令

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2025年04月22日 00时03分43秒