3

Systemd 简单使用

 3 years ago
source link: https://windard.com/blog/2018/03/13/Systemd
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Systemd 简单使用

2018-03-13

Systemd 是 Linux 系统工具,用来启动守护进程,已成为大多数发行版的标准配置。可以通过systemctl --version 命令来查看使用的版本

之前有人问我 supervisor 和 pm2 相比,哪个更好?这两者都是进程管理和进程监控的,为什么不试一下 Linux 下自带的好用的 Systemd 呢 …

centOS 上所有 services 在 /usr/lib/systemd/system/ , Ubuntu 上所有 services 在 /lib/systemd/system/ 或者 /etc/systemd/system/

  • 查看所有服务 systemctl --system 或者 systemctl
  • 重载所有服务 systemctl daemon-reload

  • 启动服务 systemctl start docker 或者 systemctl start docker.service
  • 停止服务 systemctl stop docker
  • 重启服务 systemctl restart docker
  • 重载服务 systemctl reload docker
  • 杀死服务 systemctl kill docker
  • 查看服务 systemctl show docker

  • 开机启动 systemctl enable docker
  • 取消开机启动 systemctl disable docker
  • 检查是否开机启动 systemctl is-enabled docker

创建一个 services

以进程管理工具 supervisor 为例 /usr/lib/systemd/system/supervisord.service

[Unit]
Description=Supervisor daemon

[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target

然后再 systemctl daemon-reload 即可


本文固定链接:https://windard.com/blog/2018/03/13/Systemd
原创文章,转载请注明出处:Systemd 简单使用 By Windard


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK