A bulb working in mod_wsgi cannot write to / tmp

Apache v2.4.12-2

Mod_wsgi v4.4.8-1

Python v3.4.2

python-flask v0.10.1-5

Arch linux - kernel 3.12.36

I use mod_wsgi and flask to host the server. I can reproduce this problem with the following simplified code and a generic .wsgi script:

MainServer.py:

import flask

app = flask.Flask(__name__)

@app.before_first_request
def initstuff():
    test_file = '/tmp/test'
    with open(test_file, 'w') as f:
        f.write('test')

@app.route('/', methods=['GET'])
def rootdir():
    return 'Hello world'

MainServer.wsgi:

from MainServer import app as application

Expected: a file with the contents of 'test' is written to / tmp

Actual result: the file is not written. Errors not reported in the log

If I run the same code, but instead point to any other directory that my user has write permission to, it creates the file as expected. / tmp is the only directory in which I have this problem.

, (app.run), /tmp, , - .

, mod_wsgi , script app.run, /tmp.

- -

httpd . httpd systemd

+4
2

, : https://unix.stackexchange.com/questions/167835/where-apaches-tmp-located

Apache private-tmp, /tmp /var/tmp/systemd-private--httpd.service -/

+1

app DEBUG ( ):

import logging
from logging.handlers import RotatingFileHandler
import flask

app = flask.Flask(__name__)

@app.before_first_request
def initstuff():
    test_file = '/tmp/test'
    with open(test_file, 'w') as f:
        f.write('test')

@app.route('/', methods=['GET'])
def rootdir():
    return 'Hello world'

if __name__ == '__main__':
    handler = RotatingFileHandler('app.log', maxBytes=10000, backupCount=1)
    handler.setLevel(logging.DEBUG)
    app.logger.addHandler(handler)
    app.run(host='0.0.0.0', port=8056, debug=True, use_reloader=False)

app.log, , .

+3

Source: https://habr.com/ru/post/1584658/


All Articles