#100DaysOfWeb in Python Transcripts
Chapter: Days 89-92: Deploying Python web apps to Linux
Lecture: Concept: uWSGI setup

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's review just a few concepts about what we did before we move on from this deployment. Obviously, we set up Linux
0:08 gave you the script, you can go through that but don't want to talk too much more about that. But I do want to touch on the uWSGI setup
0:15 the uWSGI settings in Pyramid's production.ini. Remember when you run cookiecutter and you create a Pyramid Web App, it actually gives you
0:24 a development.ini and production.ini. We've been running the development one forever. Now, we're in production, we're on the internet, woohoo!
0:31 And it's time to use that production.ini. It's really, really important that you use that one not the development one, because it has
0:39 certain settings, like disabling the debug toolbar which can give away too much information and obviously you don't want it there
0:45 on your web app anyway right, it's for development. So we're going to use the production one it's faster, it has some settings for optimizations
0:52 and we're going to put in this uWSGI section here at the top. So we're going to say, listen on this local port
0:58 that we're going to proxy pass over to from Nginx. You can use Linux socket but it turns out that that's a little bit more complicated
1:07 so I'm just going to leave it like this this is totally fine for us. Run in master mode, five processes, enable threads that makes it go really quick.
1:14 Then this harry carry is if it takes too long to respond right now a minute, it'll kill itself and restart. Okay, we also have logging setup.
1:21 There's two levels of logging, we could do logging within our app, and we can do logging from uWSGI right now we're just doing the uWSGI logging
1:28 and all the print statements from our app go there as well but it would be better to separate them.
1:32 Anyway, we're going to save log to this file and we made sure that that folder had a write access from our process.
1:39 Okay, that was part of script we ran along the way. This has to be in our production.ini and this is how we control uWSGI from our code.
1:47 It's really nice, if we want to make a change to how uWSGI runs, we just change its file do a git pull on server, restart the worker processes
1:55 and then it just picks up the new changes, it's great. Here's how we configure and control uWSGI.
2:01 The way it actually runs is we set it up as a system service We can create this unit file. So here's our unit file, and the two most important things
2:09 to pay attention to here are the exec start that is the command that we basically run. If you're going to run Flask or Django, that's the place
2:18 where this would be different. You put a different command there, I'll show you that later but for now, this is the command we give to uWSGI
2:24 to run our app, and when this unit starts it just does that, until it's done. Also, set the runtime directory if you want that can be helpful.
2:32 Okay so, this is pretty easy, you can see the place where this file goes at the bottom /etc/systemd/system/billtracker.service
2:38 The bill tracker part here tells you when you say to start or ask for the status of it through system control
2:45 use the bill tracker name of the service, it's basically the name of the service, which is the name of the file.
2:50 You do those two things, now you have uWSGI running your web app as a system service that starts on boot with your Linux machine, wonderful.

Talk Python's Mastodon Michael Kennedy's Mastodon