Skip to content

Commit cd2a5fb

Browse files
author
Li Yin
committed
Finished DigitalOcean Tutorial
1 parent 114e798 commit cd2a5fb

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

guides/DigitalOcean Tutorial.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,12 +340,20 @@ root /usr/share/nginx/html;
340340

341341
Basically, the above config allows nginx to send the request, coming from our user, to our app. It also sets up some error pages for our service using nginx predefined pages.
342342

343-
And at last, in order to enable our configuration, we need to do something like this:
343+
And then, in order to enable our configuration, we need to do something like this:
344344

345345
```
346346
sudo ln -s /etc/nginx/sites-available/items-rest.conf /etc/nginx/sites-enabled/
347347
```
348348

349+
At last, we need to do this:
350+
351+
```
352+
sudo rm /etc/nginx/sites-available/default
353+
```
354+
355+
Since nginx will look into the default configuration instead of ours unless we delete this file.
356+
349357
### Setting up our app folder
350358

351359
First, we create a folder for our app:
@@ -420,6 +428,8 @@ And we will set up uWSGI in next section and finish deploying our app.
420428

421429
We will be using uWSGI to run the app for us, in this way, we can run it in multiple threads within multiple processes. It also allow us to log more easily. More details on uWSGI can be found [here](https://uwsgi-docs.readthedocs.io/en/latest/).
422430

431+
### Defining a uWSGI service
432+
423433
First, we define a uWSGI service in the system by:
424434

425435
```
@@ -458,7 +468,13 @@ The `ExecStart` property informs uWSGI on how to run our app as well as log it.
458468

459469
At last, the `WantedBy` property in `Install` section allows the service to run as soon as the server boots up.
460470

461-
***important:*** Remember to change the username, password, database name and service name/folder accordingly in your own code.
471+
***Important:*** remember to change the username, password, database name and service name/folder accordingly in your own code.
472+
473+
*Hint:* after editting the above file, press `ESC` to quit insert mode and use `:wq` to write and quit.
474+
475+
### Configuring uWSGI
476+
477+
Our next step is to configure uWSGI to run our app. To do so, we need to create a file named `uwsgi.ini` with the following content:
462478

463479
```
464480
[uwsgi]
@@ -483,3 +499,44 @@ callable = app
483499
484500
logto = /var/www/html/items-rest/log/%n.log
485501
```
502+
503+
Note that you should change the `base` folder accordingly in your own app. For the second entry, `run` is referred to the `run.py` in our sample app, which serves as the entry point of our app, so you may need to change it accordingly in your own project as well. We defined the socket.sock file here which is required in our previous [nginx section](DigitalOcean%20Tutorial.md#configure-nginx-for-our-app). Hopefully everything should link together and starting to make sense now. We asked for 8 processes with 8 threads each for no particular reason, you may adjust them according to your server capacity and data volume. The `harakiri` is a Japanese word for suicide, so in here it means for how long (in seconds) will the `emperor` kill the thread if it has failed. This is also an advantage we have with uWSGI, it allows our service to be resilient to minor failures. And it also specifies the log location.
504+
505+
And at last, after saving the above file, we use the command below to run the uWSGI service we defined earlier:
506+
507+
```
508+
sudo systemctl start uwsgi_items_rest
509+
```
510+
511+
And we should be able to check the uWSGI logs immediately to make sure it's running by using the command:
512+
513+
```
514+
vi /log/uwsgi.log
515+
```
516+
517+
### Running our app
518+
519+
Finally, we can launch our app! We can do so by starting the nginx and uWSGI services we defined.
520+
521+
```
522+
sudo systemctl start nginx
523+
sudo systemctl start uwsgi_items_rest
524+
```
525+
526+
If any of these services is already running, you may use the below commands (taking nginx for example) to reload and restart it so that it has the latest changes:
527+
528+
```
529+
sudo systemctl reload nginx
530+
sudo systemctl restart nginx
531+
```
532+
533+
## Deployment wrap-up
534+
535+
As the tutorial is very detailed, you may find it a bit hard to put the pieces together. Here's a quick wrap-up that may help you sort things up.
536+
537+
- We created a unix user and granted him some privilege.
538+
- We set up PostgreSQL and configured our user to interact with it.
539+
- We used uWSGI to run our app multi-processly and multi-threadly.
540+
- We used nginx to direct requests to our uWSGI service.
541+
542+
Thanks for reading!

0 commit comments

Comments
 (0)