ubuntu设置服务开机自启动
概要:一般service文件存放在/etc/systemd/system/ 和 /lib/systemd/system/我本来是把文件放在/lib/systemd/system/目录下,执行启动命令的时候一直报错,文件找不到root@ubuntu:/lib/systemd/system# systemctl enable isp.service Failed to issue method cal
概要:一般service文件存放在/etc/systemd/system/ 和 /lib/systemd/system/
我本来是把文件放在/lib/systemd/system/目录下,执行启动命令的时候一直报错,文件找不到
root@ubuntu:/lib/systemd/system# systemctl enable isp.service Failed to issue method call: No such file or directory
后来我拷贝到/etc/systemd/system/目录下就没有这个问题了,理论上放/lib/systemd/system/也是没问题的
下面以设置python服务开机自启动为例
1、准备*.service文件(以下均以myserver.service为例)
[Unit]
Description=Deferred execution scheduler
[Service]
Type=simple
ExecStart=/usr/bin/python /home/zhangsan/manage.py
PrivateTmp=true
[Install]
WantedBy=multi-user.target
关于service文件里的一些选项,在这里有详细的说明。
http://www.ruanyifeng.com/blog/2016/03/systemd-tutorial-part-two.html
2、service准备好之后
执行 systemctl daemon-reload //重新加载服务配置文件
3、启动服务
systemctl start myserver.service//启动服务
4、设置开机自启动
systemctl enable myserver.service //这一步会在/etc/systemd/system/multi-user.target.wants下创建软连接
好了,现在reboot重启就可以看到我们的服务已经自启动了
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)