在 Ubuntu 20.04 中,可以通过在 /etc/systemd/system 目录中创建一个systemd服务来实现开机自启动服务。
创建服务文件:在 /etc/systemd/system 目录中创建一个 .service 文件,文件名即为服务名称。
编辑服务文件:在新建的 .service 文件中,输入以下内容:
[Unit]
Description=Service description
[Service]
ExecStart=command to start service
[Install]
WantedBy=multi-user.target