简单 systemd 单元的编写

以下命令以 root 权限操作。

第一步

/etc/systemd/system 目录编写一个新的文件。比如说要开机自启动,命名为 your-service.service

[Unit]
Description=Your Service

[Service]
WorkingDirectory=/path/of/the/binary/file
ExecStart=/path/of/the/binary/file --someparam A --mode prod --data /path/of/the/dir --port 8888

[Install]
WantedBy=multi-user.target

为了正常运行,需要留心 WorkingDirectoryExecStart

第二步

运行 systemdctl daemon-reload,接着是 systemdctl enable your-service.service

第三步

运行 systemctl start your-service 看看结果。

发布于 par izfsk dans «linux». Mots-clés: Linux