从主管

时间:2015-09-30 16:40:03

标签: python flask permissions supervisord bokeh

我有一个使用bokeh绘图引擎的网络应用程序。我创建了一个基于他们的" Stocks Example"

的交互式绘图应用程序

我已经在我的开发机器上成功运行了它。在我的应用程序服务器上,我正在运行supervisorsupervisorctl)所有内容。

我使用redis作为后端。

根据谁是"驾驶"我有权限问题?各种应用。当我尝试访问服务器上的应用程序时,我的回溯显示了目录创建权限问题。

Traceback (most recent call last):
  ... flask / wsgi stuff ...
  File "/home/webdev/mydevelopment/git/ers_data_app/env/lib/python2.7/site-packages/flask_login.py", line 755, in decorated_view
    return func(*args, **kwargs)
  File "/home/webdev/mydevelopment/git/ers_data_app/webapp/mod_performance/plotting_views.py", line 53, in data_viz
    bs = make_bokeh_session()
  File "/home/webdev/mydevelopment/git/ers_data_app/webapp/mod_performance/plotting_views.py", line 27, in make_bokeh_session
    b_session.login(un, pw)
  File "/home/webdev/mydevelopment/git/ers_data_app/env/lib/python2.7/site-packages/bokeh/session.py", line 244, in login
    self.save()
  File "/home/webdev/mydevelopment/git/ers_data_app/env/lib/python2.7/site-packages/bokeh/session.py", line 180, in save
    data = self.load_dict()
  File "/home/webdev/mydevelopment/git/ers_data_app/env/lib/python2.7/site-packages/bokeh/session.py", line 151, in load_dict
    configfile = self.configfile
  File "/home/webdev/mydevelopment/git/ers_data_app/env/lib/python2.7/site-packages/bokeh/session.py", line 148, in configfile
    return join(self.configdir, "config.json")
  File "/home/webdev/mydevelopment/git/ers_data_app/env/lib/python2.7/site-packages/bokeh/session.py", line 138, in configdir
    makedirs(bokehdir)
  File "/home/webdev/mydevelopment/git/ers_data_app/env/lib64/python2.7/os.py", line 157, in makedirs
    mkdir(name, mode)
OSError: [Errno 13] Permission denied: '/root/.bokeh'

我在flask视图中放置了一条打印语句,以显示当前用户是谁(使用os.getegid()

from bokeh.session import Session as bSession
...
def make_bokeh_session():
    print 'bokeh session group!!!!!!!! {}'.format(os.getegid())
    print 'bokeh session user!!!!!!!! {}'.format(os.path.expanduser('~'))
    un = current_user.username
    pw = current_app.config['BOKEH_SESSION_PW']
    b_session = bSession(root_url=bokeh_url, load_from_config=False)
    try:
        b_session.login(un, pw)
    except RuntimeError as e:
        b_session.register(un, pw)
        b_session.login(un, pw)
    output_server('ers_plots')
    return b_session

print语句显示组1000(基本上运行所有内容的webdev用户)的组ID,尽管os.expanduser('~')将用户显示为root用户。

请参阅下面的supervisor配置代码段。

[program:bokehservergo]
directory = /home/webdev/mydevelopment/git/ers_data_app/webapp/mod_performance
command = /home/webdev/mydevelopment/git/ers_data_app/env/bin/bokeh-server --script=plotting_app.py --backend=redis --no-start-redis -m
user=webdev
...

使用uwsgi emperor

运行webapp
[program:uwsgi_emperor_go]
command = /usr/bin/uwsgi --emperor /etc/uwsgi/emperor.ini
user=webdev
...

redis runner

[program:redisgo]
command=/usr/bin/redis-server /etc/redis.conf
user=webdev
...

来自bokeh/session.py的相关代码(makedirs实际上是在追回追溯)

@property
    def configdir(self):
        """ filename where our config are stored. """
        if self._configdir:
            return self._configdir
        bokehdir = join(expanduser("~"), ".bokeh")
        if not exists(bokehdir):
            makedirs(bokehdir)
        return bokehdir

如何解决此权限问题,以便可以在服务器上部署bokeh?我尝试将user=webdev添加到各种supervisord程序块中无济于事。我之后从user=webdev

supervisor.conf配置中删除了redis

1 个答案:

答案 0 :(得分:0)

我最终创建了自己的app_document装饰器(请参阅stock_app示例),该装置允许我创建一个多用户bokeh session并传入一个config目录,因为这是抛出错误的地方。