首页 新闻 会员 周边

最新版的linux如何让rc.local中的脚本持久运行

0
悬赏园豆:200 [已关闭问题] 关闭于 2016-10-15 21:54

在ubuntu16.04或者fedora24中
https://github.com/leeyiw/dnspod_ddns 为了运行这段代码,在rc.local中加入了这句 python dnspod_ddns.py -d start 但是程序执行了一下就自动退出了,如何让python脚本持续运行?网上能搜到的方法都试了,还是不行。

在终端输入python dnspod_ddns.py -d start直接运行不会自动退出。

怀疑是权限问题,修改了/usr/lib/systemd/system/rc-local.service

[Service]
User=root
Group=root

并且把相关文件都chmod777,还把文件移动到/etc/rc.d/目录里了,还是不行

问题补充:

不是全路径问题,加全路径 和 cd到脚本所在目录都试过了,nohup和在末尾加&也试过了,都不行。以下是运行结果:

[w@localhost ~]$ systemctl status rc-local.service
● rc-local.service - /etc/rc.d/rc.local Compatibility
Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
Active: active (exited) (Result: exit-code) since 六 2016-10-15 14:38:49 CST; 2min 0s ago
Process: 933 ExecStart=/etc/rc.d/rc.local start (code=exited, status=0/SUCCESS)
Main PID: 948 (code=exited, status=1/FAILURE)
Tasks: 0 (limit: 512)
CGroup: /system.slice/rc-local.service

10月 15 14:38:49 localhost.localdomain systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
10月 15 14:38:49 localhost.localdomain systemd[1]: Started /etc/rc.d/rc.local Compatibility.
10月 15 14:38:49 localhost.localdomain systemd[1]: rc-local.service: Main process exited, code=exited, status=1/FAILUR

如果在开机状态下运行systemctl start rc-local.service是没有问题的,状态会是Active: active (running) 。

nodyhd的主页 nodyhd | 初学一级 | 园豆:16
提问于:2016-10-14 15:04
< >
分享
所有回答(4)
1

crontab

haiwei.sun | 园豆:204 (菜鸟二级) | 2016-10-14 17:38

这个方法不是开机启动用的,我在rc.local里启动svnserve也不行,提示没有权限访问repo目录

支持(0) 反对(0) nodyhd | 园豆:16 (初学一级) | 2016-10-14 18:41
0

查了一下,可能是因为你没有使用全路径。

墨镜带佬星 | 园豆:2294 (老鸟四级) | 2016-10-15 07:26
1

nohup python dnspod_ddns.py -d start

采用nohup命令在将脚本以后台运行的方式启动就可以了,写入rc.local文件

囍。 | 园豆:184 (初学一级) | 2016-10-15 09:30
0

自己百度google解决了

python脚本退出问题解决方法是:前面要加上 sleep 10

启动方式为systemd,在目录/usr/lib/systemd/system下创建runddns.service并写入

[Unit]
After=network.target

[Service]
User=root
Type=forking
ExecStart=/etc/rc.d/dnspod_ddns/test.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

test.sh内容为:

#!/bin/bash
sleep 10
cd /etc/rc.d/dnspod_ddns/
python dnspod_ddns.py -d start


svnserve权限问题要关闭selinux

/usr/bin/svnserve -d -r /var/svn/repo

打开/etc/selinux/config
将enforcing改为disabled.

nodyhd | 园豆:16 (初学一级) | 2016-10-15 21:52
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册