******************** Systemd ******************** :github: https://github.com/systemd/systemd :参考文档: https://blog.csdn.net/watch_wchao/article/details/128819185 在wsl系统启用systemd =================================== https://learn.microsoft.com/zh-cn/windows/wsl/systemd Example =================================== 配置文件一般存放在/etc/systemd/system/目录下 example.service .. code-block:: ini [Unit] Description=Job that runs the foo daemon After=network.target Documentation=man:foo(1) [Service] Type=forking Environment=statedir=/var/cache/foo ExecStartPre=/usr/bin/mkdir -p ${statedir} ExecStart=/usr/bin/foo-daemon --arg1 "hello world" --statedir ${statedir} ; 运行目录 WorkingDirectory= [Install] WantedBy=multi-user.target 添加到系统自启动项中: .. code-block:: console $ systemctl enable example 列出所有服务 ========================= .. code-block:: console systemctl list-unit-files --type=service 学习范例 ===================== node_exporter的ansible剧本: https://gitee.com/mirrors_prometheus-community/ansible/blob/main/roles/node_exporter/templates/node_exporter.service.j2 执行路径 ========================= 执行路径默认是在 ``/`` 目录 .. code-block:: text [Service] WorkingDirectory=/data/gateway 查看日志 ========================= .. code-block:: console journalctl -u scrapyd