Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Deployment
Lecture: uWSGI as a service
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
You saw that we could copy this command and run it. And that is super good news. Because that means we're basically having this work.
0:07
However, there are plenty of times when our system unit here won't run even though that works. There's weird things about like
0:15
the working path and other stuff. So what we need to do is get this so that when we start our Linux server
0:21
this automatically launches that and just runs. And if there's some kind of error it will restart our service. Things like that.
0:28
And basically to make this happen we just need this file copied into the correct location. So I have a little command here
0:34
that's going to say, copy that over to etc/systemd/system and let's try that. Alright, that worked. Pretty good. And then what we can do is we can
0:43
issue commands to systemctl. We can say, start we can ask for the status we can say, stop. Let's try start first of all here.
0:50
It's pretty good. Let's look at the status. Looks good, looks good. Alright, things are running we probably shouldn't run as root. Don't do that.
1:02
Now, over here, we're got our four worker processes running. That's all good. Let's get out of here and just try our HTTP again.
1:11
Alright, it looks like it's working. Everything is great. However, if we reboot, it's not going to persist. Why? Because we have to run this enable.
1:20
This tells it to run. Now, it's going just prove it let's do a reboot real quick log back in, and see that we can still access it.
1:28
Alright, that's probably long enough. Let's try to go back. Let's try to request a page again. Beautiful. Still working.
1:36
Now we can't access it yet outside the server. Remember, only ports we're exposing are 80 and 443 as far as the web's concerned
1:44
5000 properly blocked off as it should be. But now we have it running in uWSGI as a system service and whatever the lifecycle of the server is
1:54
it's going to keep our app running. I'm just going to start it up whenever we turn it on we turn off, obviously it turns off with the server.
2:00
So this is perfect. Just leave it like this and let it go.