Raspberry Pi crontab在启动时启动py脚本->日志记录:错误mysql 2002(无法连接到本地服务器) [英] Raspberry Pi crontab starts py script at bootup -> logging: error mysql 2002 (can't connect to local server)
问题描述
Raspberry Pi(raspian wheezy)有一个cronjob,使用sudo crontab -e作为用户pi创建,因此它应该具有root权限。
ps aux | grep / home /.../ myscript.py
...说它的所有者是用户 pi !? (这是正确的吗?)
如果我从终端调用crontab,python脚本运行良好。
它正在从UART(串行端口)读取数据,并将其保存到mysql数据库中。
我的python脚本获得了 chmod 777补助。
crontab文件:
@reboot sudo python /home/pi/pythonprogram/myscript.py& > /home/pi/pythonprogram/myscript.log
crontab日志文件:
错误mysql:2002无法通过套接字'/var/run/mysqld/mysqld.sock'(2)连接到本地MYSQL服务器
在启动过程中服务器(mysql和apache)运行之前,可能是首先调用了我的脚本吗?有办法防止这种情况吗?
还有哪些原因可能导致这些错误?
以非常难看的方式解决了该问题,但现在可以正常工作。
只需添加:
time.sleep(5)
,然后再尝试连接到mysql db。 p>
如果有人有更好的解决方案,我会很高兴。
A Raspberry Pi (raspian wheezy) has a cronjob, created as user pi with "sudo crontab -e" so it should has root grants.
ps aux | grep /home/.../myscript.py
...say it's owner is user "pi"!? (is this correct?)
The python script called from crontab is working fine if i call it from the terminal. It's reading data from UART (serial port), and save it into a mysql database. My python script got 'chmod 777' grants.
The crontab file:
@reboot sudo python /home/pi/pythonprogram/myscript.py & > /home/pi/pythonprogram/myscript.log
crontab log file:
Error mysql: 2002 Can't connect to local MYSQL server throught socket '/var/run/mysqld/mysqld.sock' (2)
May it be that my script is called first, before the server (mysql and apache) are running during the boot up process? Is there a way to prevent this?
What else could be the reason for those error?
solved the problem in quite ugly way, but it's working now.
Just added:
time.sleep(5)
before trying to connect to mysql db.
I would be pleased if someone has a better solution.
这篇关于Raspberry Pi crontab在启动时启动py脚本->日志记录:错误mysql 2002(无法连接到本地服务器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!