librelist archives

« back to archive

Could not configure Flask + uWSGI emperor

Could not configure Flask + uWSGI emperor

From:
Andrey Zhidenkov
Date:
2013-05-08 @ 06:50
I'm trying to configure my Flask application to work through uWSGI emperor
+ nginx.

Here is my configs:

cat /etc/uwsgi/emperor.ini
[uwsgi]
emperor = /etc/uwsgi/apps
master = 1
uid = http
gid = http
logto = /var/www/emperor.log

cat /etc/uwsgi/apps/blog.ini
[uwsgi]
chdir=/var/www/unix-blog.com
app=runserver
#wsgi-file=runserver.py
socket=/var/www/unix-blog.com/sock/blog.sock
#module=
callable=app
logto=/var/www/unix-blog.com/uwsgi.log
logformat=[%(ctime)] %(addr) - %(host) %(method) %(uri) %(status) %(msecs)ms

When I start emperor service, I got this in logs:

Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
*** Python threads support is disabled. You can enable it with
--enable-threads ***
Python main interpreter initialized at 0x2532aa0
your server socket listen backlog is limited to 100 connections
mapped 144848 bytes (141 KB) for 1 cores
*** Operational MODE: single process ***
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***

When I use wsgi-file configuration directive I got this:

Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
*** Python threads support is disabled. You can enable it with
--enable-threads ***
Python main interpreter initialized at 0x1d61620
The -s/--socket option is missing and stdin is not a socket.

My application is simple:

cat runserver.py
#!/usr/bin/env python2

from application import app

app.debug = True
app.run()

Application folder:

ll .
total 568K
drwxr-xr-x 7 mutex wheel 4.0K May  8 10:45 .
drwxr-xr-x 6 mutex wheel 4.0K May  8 00:37 ..
drwxr-xr-x 4 mutex wheel 4.0K May  8 00:34 application
drwxr-xr-x 2 mutex wheel 4.0K May  7 22:11 data
drwxr-xr-x 4 mutex wheel 4.0K May  7 22:11 db
drwxr-xr-x 4 mutex wheel 4.0K May  7 22:16 .hg
drwxr-xr-x 2 http  http  4.0K May  8 10:48 sock
-rw-r--r-- 1 mutex wheel  335 May  8 10:45 blog.ini
-rw-r--r-- 1 mutex wheel   44 May  7 22:11 .hgignore
-rw-r--r-- 1 mutex wheel    0 May  7 22:11 __init__.py
-rw-r--r-- 1 mutex wheel   29 May  7 22:11 README
-rwxr-xr-x 1 mutex wheel   80 May  8 01:00 runserver.py
-rw-r--r-- 1 root  root   201 May  8 00:34 runserver.pyc
-rw-r--r-- 1 http  http  513K May  8 10:48 uwsgi.log

Please, help me... I think, I've tryied all posiible configuration options
but it still doesn't work...

-- 
С уважением, Андрей Жиденков.

                       _
ASCII ribbon campaign ( )
 against HTML e-mail   X
                      / \

Re: [flask] Could not configure Flask + uWSGI emperor

From:
Roberto De Ioris
Date:
2013-05-08 @ 06:59
> I'm trying to configure my Flask application to work through uWSGI emperor
> + nginx.
>
> Here is my configs:
>
> cat /etc/uwsgi/emperor.ini
> [uwsgi]
> emperor = /etc/uwsgi/apps
> master = 1
> uid = http
> gid = http
> logto = /var/www/emperor.log
>
> cat /etc/uwsgi/apps/blog.ini
> [uwsgi]
> chdir=/var/www/unix-blog.com
> app=runserver
> #wsgi-file=runserver.py
> socket=/var/www/unix-blog.com/sock/blog.sock
> #module=
> callable=app
> logto=/var/www/unix-blog.com/uwsgi.log
> logformat=[%(ctime)] %(addr) - %(host) %(method) %(uri) %(status)
> %(msecs)ms
>
> When I start emperor service, I got this in logs:
>
> Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
> *** Python threads support is disabled. You can enable it with
> --enable-threads ***
> Python main interpreter initialized at 0x2532aa0
> your server socket listen backlog is limited to 100 connections
> mapped 144848 bytes (141 KB) for 1 cores
> *** Operational MODE: single process ***
> *** no app loaded. going in full dynamic mode ***
> *** uWSGI is running in multiple interpreter mode ***
>
> When I use wsgi-file configuration directive I got this:
>
> Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
> *** Python threads support is disabled. You can enable it with
> --enable-threads ***
> Python main interpreter initialized at 0x1d61620
> The -s/--socket option is missing and stdin is not a socket.
>
> My application is simple:
>
> cat runserver.py
> #!/usr/bin/env python2
>
> from application import app
>
> app.debug = True
> app.run()
>
> Application folder:
>


You have to call it as:

wsgi-file = path_to/runserver.py
callable = app

or

pythonpath = path_to_runserver/
module = runserver
callable = app

or

pythonpath = path_to_runserver/
module = runserver:app

the --app option is deprecated since 1.2 and you should use it
only as a placeholder (it will be ignored as an option since 1.4)



-- 
Roberto De Ioris
http://unbit.it

Re: [flask] Could not configure Flask + uWSGI emperor

From:
Andrey Zhidenkov
Date:
2013-05-08 @ 07:12
Roberto, thank you for your answer. I've all tried this, but I've got this
error:

tail uwsgi.log
current working directory: /var/www/unix-blog.com
detected binary path: /usr/bin/uwsgi
your processes number limit is 16011
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
*** Python threads support is disabled. You can enable it with
--enable-threads ***
Python main interpreter initialized at 0x13cf620
The -s/--socket option is missing and stdin is not a socket.



2013/5/8 Roberto De Ioris <roberto@unbit.it>

>
> > I'm trying to configure my Flask application to work through uWSGI
> emperor
> > + nginx.
> >
> > Here is my configs:
> >
> > cat /etc/uwsgi/emperor.ini
> > [uwsgi]
> > emperor = /etc/uwsgi/apps
> > master = 1
> > uid = http
> > gid = http
> > logto = /var/www/emperor.log
> >
> > cat /etc/uwsgi/apps/blog.ini
> > [uwsgi]
> > chdir=/var/www/unix-blog.com
> > app=runserver
> > #wsgi-file=runserver.py
> > socket=/var/www/unix-blog.com/sock/blog.sock
> > #module=
> > callable=app
> > logto=/var/www/unix-blog.com/uwsgi.log
> > logformat=[%(ctime)] %(addr) - %(host) %(method) %(uri) %(status)
> > %(msecs)ms
> >
> > When I start emperor service, I got this in logs:
> >
> > Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
> > *** Python threads support is disabled. You can enable it with
> > --enable-threads ***
> > Python main interpreter initialized at 0x2532aa0
> > your server socket listen backlog is limited to 100 connections
> > mapped 144848 bytes (141 KB) for 1 cores
> > *** Operational MODE: single process ***
> > *** no app loaded. going in full dynamic mode ***
> > *** uWSGI is running in multiple interpreter mode ***
> >
> > When I use wsgi-file configuration directive I got this:
> >
> > Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
> > *** Python threads support is disabled. You can enable it with
> > --enable-threads ***
> > Python main interpreter initialized at 0x1d61620
> > The -s/--socket option is missing and stdin is not a socket.
> >
> > My application is simple:
> >
> > cat runserver.py
> > #!/usr/bin/env python2
> >
> > from application import app
> >
> > app.debug = True
> > app.run()
> >
> > Application folder:
> >
>
>
> You have to call it as:
>
> wsgi-file = path_to/runserver.py
> callable = app
>
> or
>
> pythonpath = path_to_runserver/
> module = runserver
> callable = app
>
> or
>
> pythonpath = path_to_runserver/
> module = runserver:app
>
> the --app option is deprecated since 1.2 and you should use it
> only as a placeholder (it will be ignored as an option since 1.4)
>
>
>
> --
> Roberto De Ioris
> http://unbit.it
>



-- 
С уважением, Андрей Жиденков.

                       _
ASCII ribbon campaign ( )
 against HTML e-mail   X
                      / \

Re: [flask] Could not configure Flask + uWSGI emperor

From:
Roberto De Ioris
Date:
2013-05-08 @ 07:21
> Roberto, thank you for your answer. I've all tried this, but I've got this
> error:
>
> tail uwsgi.log
> current working directory: /var/www/unix-blog.com
> detected binary path: /usr/bin/uwsgi
> your processes number limit is 16011
> your memory page size is 4096 bytes
> detected max file descriptor number: 1024
> lock engine: pthread robust mutexes
> Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
> *** Python threads support is disabled. You can enable it with
> --enable-threads ***
> Python main interpreter initialized at 0x13cf620
> The -s/--socket option is missing and stdin is not a socket.
>

The last error is pretty clear, you have not specified a socket to bind
uwsgi on (could be socket, http-socket, scgi, fastcgi whatever you need).

If you do not manage to fix it, please paste the current vassal config you
are using


-- 
Roberto De Ioris
http://unbit.it

Re: [flask] Could not configure Flask + uWSGI emperor

From:
Andrey Zhidenkov
Date:
2013-05-08 @ 07:40
My vassal config is:

cat blog.ini
[uwsgi]
chdir=/var/www/unix-blog.com
pythonpath=/var/www/unix-blog.com/
module=runserver
#wsgi-file=runserver.py
socket=/var/www/unix-blog.com/sock/blog.sock
callable=app
logto=/var/www/unix-blog.com/uwsgi.log
logformat=[%(ctime)] %(addr) - %(host) %(method) %(uri) %(status) %(msecs)ms

And after uwsgi starts it creates a socket:

ll sock/
total 8.0K
drwxr-xr-x 2 http  http  4.0K May  8 11:37 .
drwxr-xr-x 8 mutex wheel 4.0K May  8 11:11 ..
srwxr-xr-x 1 http  http     0 May  8 11:37 blog.sock

But in some reason nginx couldn't connect to it:

2013/05/08 11:38:24 [error] 13367#0: *1 connect() to unix:/var/www/
unix-blog.com/sock/blog.sock failed (111: Connection refused) while
connecting to upstream, client: *.*.*.*, server: unix-blog.com,, request:
"GET / HTTP/1.1", upstream: "uwsgi://unix:/var/www/
unix-blog.com/sock/blog.sock:", host: "www.unix-blog.com"

And I still have "The -s/--socket option is missing and stdin is not a
socket." in uwsgi.log :(




2013/5/8 Roberto De Ioris <roberto@unbit.it>

>
> > Roberto, thank you for your answer. I've all tried this, but I've got
> this
> > error:
> >
> > tail uwsgi.log
> > current working directory: /var/www/unix-blog.com
> > detected binary path: /usr/bin/uwsgi
> > your processes number limit is 16011
> > your memory page size is 4096 bytes
> > detected max file descriptor number: 1024
> > lock engine: pthread robust mutexes
> > Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
> > *** Python threads support is disabled. You can enable it with
> > --enable-threads ***
> > Python main interpreter initialized at 0x13cf620
> > The -s/--socket option is missing and stdin is not a socket.
> >
>
> The last error is pretty clear, you have not specified a socket to bind
> uwsgi on (could be socket, http-socket, scgi, fastcgi whatever you need).
>
> If you do not manage to fix it, please paste the current vassal config you
> are using
>
>
> --
> Roberto De Ioris
> http://unbit.it
>



-- 
С уважением, Андрей Жиденков.

                       _
ASCII ribbon campaign ( )
 against HTML e-mail   X
                      / \

Re: [flask] Could not configure Flask + uWSGI emperor

From:
Roberto De Ioris
Date:
2013-05-08 @ 07:46
> My vassal config is:
>
> cat blog.ini
> [uwsgi]
> chdir=/var/www/unix-blog.com
> pythonpath=/var/www/unix-blog.com/
> module=runserver
> #wsgi-file=runserver.py
> socket=/var/www/unix-blog.com/sock/blog.sock
> callable=app
> logto=/var/www/unix-blog.com/uwsgi.log
> logformat=[%(ctime)] %(addr) - %(host) %(method) %(uri) %(status)
> %(msecs)ms
>
> And after uwsgi starts it creates a socket:
>
> ll sock/
> total 8.0K
> drwxr-xr-x 2 http  http  4.0K May  8 11:37 .
> drwxr-xr-x 8 mutex wheel 4.0K May  8 11:11 ..
> srwxr-xr-x 1 http  http     0 May  8 11:37 blog.sock
>
> But in some reason nginx couldn't connect to it:
>
> 2013/05/08 11:38:24 [error] 13367#0: *1 connect() to unix:/var/www/
> unix-blog.com/sock/blog.sock failed (111: Connection refused) while
> connecting to upstream, client: *.*.*.*, server: unix-blog.com,, request:
> "GET / HTTP/1.1", upstream: "uwsgi://unix:/var/www/
> unix-blog.com/sock/blog.sock:", host: "www.unix-blog.com"
>
> And I still have "The -s/--socket option is missing and stdin is not a
> socket." in uwsgi.log :(
>

Run the vassal manually

uwsgi --ini blog.ini

if you still get the "socket" error, you probably have garbage in the file

Just to be sure, how you are running the emperor ?

-- 
Roberto De Ioris
http://unbit.it

Re: [flask] Could not configure Flask + uWSGI emperor

From:
Andrey Zhidenkov
Date:
2013-05-08 @ 08:10
I've tried run uwsgi without emperor and I'v got this:

*** Starting uWSGI 1.4.9 (64bit) on [Wed May  8 12:09:23 2013] ***
compiled with version: 4.7.2 on 02 April 2013 01:27:44
os: Linux-3.8.7-1-ARCH #1 SMP PREEMPT Sat Apr 13 09:01:47 CEST 2013
nodename: arch
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /var/www/unix-blog.com
detected binary path: /usr/bin/uwsgi
setgid() to 33
setuid() to 33
your processes number limit is 16011
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to UNIX address /var/www/unix-blog.com/sock/blog.sockfd 3
uwsgi socket 1 bound to UNIX address sock/blog.sock fd 4
Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
*** Python threads support is disabled. You can enable it with
--enable-threads ***
Python main interpreter initialized at 0x21daaa0
your server socket listen backlog is limited to 100 connections
mapped 217272 bytes (212 KB) for 2 cores
*** Operational MODE: preforking ***
added /var/www/unix-blog.com/ to pythonpath.
 * Running on http://127.0.0.1:5000/
 * Restarting with reloader
*** Starting uWSGI 1.4.9 (64bit) on [Wed May  8 12:09:23 2013] ***
compiled with version: 4.7.2 on 02 April 2013 01:27:44
os: Linux-3.8.7-1-ARCH #1 SMP PREEMPT Sat Apr 13 09:01:47 CEST 2013
nodename: arch
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /var/www/unix-blog.com
detected binary path: /usr/bin/uwsgi
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 16011
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
The -s/--socket option is missing and stdin is not a socket.


Before I run emperor via systemd:

cat /etc/systemd/system/emperor.uwsgi.service
[Unit]
Description=uWSGI Emperor
After=syslog.target

[Service]
ExecStart=/usr/bin/uwsgi --ini /etc/uwsgi/emperor.ini
Restart=always
Type=notify
StandardError=syslog
NotifyAccess=all

KillSignal=SIGINT
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target


2013/5/8 Roberto De Ioris <roberto@unbit.it>

>
> > My vassal config is:
> >
> > cat blog.ini
> > [uwsgi]
> > chdir=/var/www/unix-blog.com
> > pythonpath=/var/www/unix-blog.com/
> > module=runserver
> > #wsgi-file=runserver.py
> > socket=/var/www/unix-blog.com/sock/blog.sock
> > callable=app
> > logto=/var/www/unix-blog.com/uwsgi.log
> > logformat=[%(ctime)] %(addr) - %(host) %(method) %(uri) %(status)
> > %(msecs)ms
> >
> > And after uwsgi starts it creates a socket:
> >
> > ll sock/
> > total 8.0K
> > drwxr-xr-x 2 http  http  4.0K May  8 11:37 .
> > drwxr-xr-x 8 mutex wheel 4.0K May  8 11:11 ..
> > srwxr-xr-x 1 http  http     0 May  8 11:37 blog.sock
> >
> > But in some reason nginx couldn't connect to it:
> >
> > 2013/05/08 11:38:24 [error] 13367#0: *1 connect() to unix:/var/www/
> > unix-blog.com/sock/blog.sock failed (111: Connection refused) while
> > connecting to upstream, client: *.*.*.*, server: unix-blog.com,,
> request:
> > "GET / HTTP/1.1", upstream: "uwsgi://unix:/var/www/
> > unix-blog.com/sock/blog.sock:", host: "www.unix-blog.com"
> >
> > And I still have "The -s/--socket option is missing and stdin is not a
> > socket." in uwsgi.log :(
> >
>
> Run the vassal manually
>
> uwsgi --ini blog.ini
>
> if you still get the "socket" error, you probably have garbage in the file
>
> Just to be sure, how you are running the emperor ?
>
> --
> Roberto De Ioris
> http://unbit.it
>



-- 
С уважением, Андрей Жиденков.

                       _
ASCII ribbon campaign ( )
 against HTML e-mail   X
                      / \

Re: [flask] Could not configure Flask + uWSGI emperor

From:
Roberto De Ioris
Date:
2013-05-08 @ 08:33
> I've tried run uwsgi without emperor and I'v got this:
>
> *** Starting uWSGI 1.4.9 (64bit) on [Wed May  8 12:09:23 2013] ***
> compiled with version: 4.7.2 on 02 April 2013 01:27:44
> os: Linux-3.8.7-1-ARCH #1 SMP PREEMPT Sat Apr 13 09:01:47 CEST 2013
> nodename: arch
> machine: x86_64
> clock source: unix
> pcre jit disabled
> detected number of CPU cores: 1
> current working directory: /var/www/unix-blog.com
> detected binary path: /usr/bin/uwsgi
> setgid() to 33
> setuid() to 33
> your processes number limit is 16011
> your memory page size is 4096 bytes
> detected max file descriptor number: 1024
> lock engine: pthread robust mutexes
> uwsgi socket 0 bound to UNIX address
> /var/www/unix-blog.com/sock/blog.sockfd 3
> uwsgi socket 1 bound to UNIX address sock/blog.sock fd 4
> Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
> *** Python threads support is disabled. You can enable it with
> --enable-threads ***
> Python main interpreter initialized at 0x21daaa0
> your server socket listen backlog is limited to 100 connections
> mapped 217272 bytes (212 KB) for 2 cores
> *** Operational MODE: preforking ***
> added /var/www/unix-blog.com/ to pythonpath.
>  * Running on http://127.0.0.1:5000/
>  * Restarting with reloader
>


Wait wait, what is this ?? :)

You are spawning the flask webserver, check the big "watch out" here:

http://flask.pocoo.org/docs/deploying/uwsgi/


-- 
Roberto De Ioris
http://unbit.it

Re: [flask] Could not configure Flask + uWSGI emperor

From:
Andrey Zhidenkov
Date:
2013-05-08 @ 09:11
It works now! Thank you :)


2013/5/8 Roberto De Ioris <roberto@unbit.it>

>
> > I've tried run uwsgi without emperor and I'v got this:
> >
> > *** Starting uWSGI 1.4.9 (64bit) on [Wed May  8 12:09:23 2013] ***
> > compiled with version: 4.7.2 on 02 April 2013 01:27:44
> > os: Linux-3.8.7-1-ARCH #1 SMP PREEMPT Sat Apr 13 09:01:47 CEST 2013
> > nodename: arch
> > machine: x86_64
> > clock source: unix
> > pcre jit disabled
> > detected number of CPU cores: 1
> > current working directory: /var/www/unix-blog.com
> > detected binary path: /usr/bin/uwsgi
> > setgid() to 33
> > setuid() to 33
> > your processes number limit is 16011
> > your memory page size is 4096 bytes
> > detected max file descriptor number: 1024
> > lock engine: pthread robust mutexes
> > uwsgi socket 0 bound to UNIX address
> > /var/www/unix-blog.com/sock/blog.sockfd 3
> > uwsgi socket 1 bound to UNIX address sock/blog.sock fd 4
> > Python version: 2.7.4 (default, Apr  6 2013, 19:20:36)  [GCC 4.8.0]
> > *** Python threads support is disabled. You can enable it with
> > --enable-threads ***
> > Python main interpreter initialized at 0x21daaa0
> > your server socket listen backlog is limited to 100 connections
> > mapped 217272 bytes (212 KB) for 2 cores
> > *** Operational MODE: preforking ***
> > added /var/www/unix-blog.com/ to pythonpath.
> >  * Running on http://127.0.0.1:5000/
> >  * Restarting with reloader
> >
>
>
> Wait wait, what is this ?? :)
>
> You are spawning the flask webserver, check the big "watch out" here:
>
> http://flask.pocoo.org/docs/deploying/uwsgi/
>
>
> --
> Roberto De Ioris
> http://unbit.it
>



-- 
С уважением, Андрей Жиденков.

                       _
ASCII ribbon campaign ( )
 against HTML e-mail   X
                      / \