首页 > 我一flask项目部署在gunicorn后无法调用rsync功能

我一flask项目部署在gunicorn后无法调用rsync功能

背景:

使用gunicorn+supervisor部署我的flask项目
gunicorn配置信息:
权限也是使用了root
[program:manage]
user=root
command = /usr/local/python27/bin/gunicorn -b 0.0.0.0:5000 manage:app  
directory = /data/webpro/SoftEnvInit  
autostart=true    
autorestart=true  
startsecs=3 

我这项目中有一个调用rsync功能的

def rsync_file(self,local_dir,online_dir,pro_name):
        logger.info('同步内网%s svn到外网svn' %pro_name)
        logger.info(os.popen('rsync -avrz --exclude=".svn" --delete %s %s' %(local_dir,online_dir)).read().strip())

当我开发模式使用项目时候,即使用python manage.py启动项目

[root@localhost python_project]# python manage.py 
/usr/local/python27/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.
  warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.')
 * Running on http://0.0.0.0:5002/ (Press CTRL+C to quit)
 * Restarting with stat
/usr/local/python27/lib/python2.7/site-packages/flask_sqlalchemy/__init__.py:800: UserWarning: SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.
  warnings.warn('SQLALCHEMY_TRACK_MODIFICATIONS adds significant overhead and will be disabled by default in the future.  Set it to True to suppress this warning.')
 * Debugger is active!
 * Debugger pin code: 135-528-598

启动后,当项目调用到rsync_file这个函数功能时,日志会打印

同步内网web客户端(cdn) svn到外网svn
sending incremental file list
resource/cn/swf/loading/
resource/cn/swf/loading/loadingBg.swf

sent 357239 bytes  received 261 bytes  715000.00 bytes/sec
total size is 160213789  speedup is 448.15

但是单我把项目部署在gunicorn+supervisor后,当调用到rsync_file函数功能时候,貌似根本没起到作用,也就是文件根本没同步

同步内网web客户端(cdn) svn到外网svn
sending incremental file list

后面就没东西了,这是为咋的

PS:两次同步实验都是保持原样来同步的,就是第一次同步后我恢复到原样,再进行第二次同步,所以不存在第一次同步后,第二次要同步时数据已经一致的情况的。

================
最终的问题出现在selinux上了,关了就全部正常了。


打印一下 rsync_file 里的 local_dir,是不是真的是那个。这里要求一个绝对路径。

gunicron 启用时,你最好使用 --chdir 改变一下项目路径。

【热门文章】
【热门文章】