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
0:01
copy this command and run it.
0:02
And that is super good news.
0:04
Because that means we're basically having this work.
0:06
However, there are plenty of times
0:08
when our system unit here won't run
0:11
even though that works.
0:12
There's weird things about like
0:14
the working path and other stuff.
0:16
So what we need to do is get this
0:17
so that when we start our Linux server
0:20
this automatically launches that and just runs.
0:23
And if there's some kind of error
0:24
it will restart our service.
0:26
Things like that.
0:27
And basically to make this happen
0:28
we just need this file copied into the correct location.
0:31
So I have a little command here
0:33
that's going to say, copy that over to
0:34
etc/systemd/system and let's try that.
0:39
Alright, that worked. Pretty good.
0:40
And then what we can do is we can
0:42
issue commands to systemctl.
0:44
We can say, start
0:45
we can ask for the status
0:46
we can say, stop.
0:47
Let's try start first of all here.
0:49
It's pretty good. Let's look at the status.
0:56
Looks good, looks good.
0:57
Alright, things are running
0:58
we probably shouldn't run as root.
1:00
Don't do that.
1:01
Now, over here, we're got our four
1:03
worker processes running. That's all good.
1:06
Let's get out of here and just try our HTTP again.
1:10
Alright, it looks like it's working.
1:13
Everything is great.
1:14
However, if we reboot, it's not going to persist.
1:17
Why? Because we have to run this enable.
1:19
This tells it to run.
1:21
Now, it's going just prove it
1:23
let's do a reboot real quick
1:24
log back in, and see that we can still access it.
1:27
Alright, that's probably long enough.
1:28
Let's try to go back.
1:30
Let's try to request a page again.
1:33
Beautiful. Still working.
1:35
Now we can't access it yet outside the server.
1:38
Remember, only ports we're exposing are
1:40
80 and 443 as far as the web's concerned
1:43
5000 properly blocked off as it should be.
1:46
But now we have it running
1:48
in uWSGI as a system service
1:51
and whatever the lifecycle of the server is
1:53
it's going to keep our app running.
1:55
I'm just going to start it up whenever we turn it on
1:57
we turn off, obviously it turns off with the server.
1:59
So this is perfect.
2:00
Just leave it like this and let it go.