Linux 拨号vps windows公众号手机端

ubuntu中systemd自启动怎么配置

lewis 1年前 (2024-03-13) 阅读数 18 #网络运维
文章标签 Systemdubuntu

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

  1. 创建一个unit文件,通常以.service为扩展名,比如my_service.service
  2. 编辑该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
  1. 将该unit文件复制到/etc/systemd/system/目录下。
  2. 运行以下命令启用该服务并使其自启动:
sudo systemctl daemon-reload
sudo systemctl enable my_service.service
sudo systemctl start my_service.service

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

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门