ubuntu中systemd自启动怎么配置

在Ubuntu中,要配置systemd服务自启动,可以按照以下步骤操作:

创建一个unit文件,通常以.service为扩展名,比如my_service.service
编辑该unit文件,指定服务的启动命令、工作目录、PID文件路径等相关信息。示例unit文件内容如下:

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

[Service]
Type=simple
ExecStart=/path/to/your/service
Restart=always
User=your_username

[Install]
WantedBy=multi-user.target

将该unit文件复制到/etc/systemd/system/目录下。
运行以下命令启用该服务并使其自启动:

sudo systemctl daemon-reload
sudo systemctl enable my_service.service
sudo systemctl start my_service.service

这样,你的服务就会在系统启动时自动启动。你也可以通过sudo systemctl status my_service.service命令查看服务的状态。

阅读剩余
THE END