kwi*_*ess 4 linux ubuntu boot startup
我有一个python守护进程,它通过rc.local启动.具有相同权限的相同脚本安装在我拥有的其他一些Ubuntu盒子上.它在这些安装上运行没有问题.也就是说,重启框后,守护进程正在运行.
但是,通过此特定安装,守护进程在我登录时未运行并检查进程是否存在.系统之间的rc.local文件是相同的(或至少足够接近):
localaccount@sosms:~$ cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
python /var/www/myDaemon/Main.py > /var/log/somelog.txt
exit 0
Run Code Online (Sandbox Code Playgroud)
权限是:
localaccount@sosms:~$ ls -la /etc/rc.local
-rwxr-xr-x 1 localaccount localaccount 370 Jun 3 11:04 rc.local
Run Code Online (Sandbox Code Playgroud)
我测试了是否通过使用此测试rc.local来执行rc.local进程:
localaccount@sosms:/var/log/sosmsd$ cat /etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo "test" > /home/localaccount/test1
/usr/bin/python /var/www/sosms/sosmsd/Main.py > /var/log/sosmsd/log/log
echo "test" > /home/localaccount/test2
exit 0
localaccount@sosms:/var/log/sosmsd$
Run Code Online (Sandbox Code Playgroud)
重启框后,只创建第一个测试文件(test1).我猜这意味着python行导致某种问题,但我在/ var/log/sosmsd/log/log中没有输出:
localaccount@sosms:~$ ls
test1
Run Code Online (Sandbox Code Playgroud)
更新:
然后我按照larsks的建议,确定我从启动python脚本时得到了这个错误:
mysql_exceptions.OperationalError: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)")
Run Code Online (Sandbox Code Playgroud)
这是否意味着在MySQL有机会初始化之前正在执行rc.local?我从哪里开始?
回答错过的其他人有一件事是你的rc,init等在启动时运行的脚本,PATH变量可能会也可能不会被初始化(从来没有保证),这意味着简单地做"python somescript.py"而不是/ usr/bin/python可能并不总是有效.始终在init脚本和rc脚本中使用绝对路径.
是的,很可能rc.local在mysqld启动之前运行.您需要将其设置为init.d脚本,并在标头中使用insserv样式的注释来告诉它需要哪些依赖项.http://manpages.ubuntu.com/manpages/lucid/man8/insserv.8.html
| 归档时间: |
|
| 查看次数: |
19416 次 |
| 最近记录: |