Skip to content

Commit 9bcc08f

Browse files
committed
Added instructions for creating a service
1 parent d54a6ec commit 9bcc08f

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,40 @@ add this to the file:
211211

212212
####Setting up Docker
213213
Refer this link for [setting up docker](https://docs.docker.com/engine/install/ubuntu/#install-using-the-repository "setting up docker") (setup via repository).
214+
After successfully installing docker switch to the Docker directory `cd playground/backend/docker`
215+
and build the docker image `sudo docker build -t playground-prod .` .
214216

215217
#### Setting up the backend server
216-
1. Go to the backend folder `cd playground/backend`
217-
2. Make a directory for virtual environment(this will be useful when setting up the service) using `mkdir .venv` and install all required modules using `pipenv install`
218-
3. Start the server using:
218+
1. Go to the backend folder `cd playground/backend`.
219+
2. Install pipenv to install packages from the pipfile
220+
`sudo pip install pipenv`
221+
3. Make a directory for virtual environment(this will be useful when setting up the service) using `mkdir .venv` and install all required modules using `pipenv install`
222+
4. Start the server using:
219223
```sudo pipenv run gunicorn --bind 0.0.0.0:5000 wsgi:app```
220224

221225
You'll now be able to use the app. You should also setup a service for the gunicorn server so that it starts automatically when the server boots.
226+
227+
#### Setting up the service
228+
1. Create a service file for our app `sudo nano /etc/systemd/system/backend.service`
229+
2. Write the following configuration:
230+
```
231+
[Unit]
232+
Description=Gunicorn instance to serve backend for playground
233+
After=network.target
234+
[Service]
235+
User=ubuntu
236+
Group=www-data
237+
WorkingDirectory=/home/ubuntu/playground/backend
238+
Environment="PATH=/home/ubuntu/playground/backend/.venv/bin"
239+
ExecStart=sudo /home/ubuntu/playground/backend/.venv/bin/gunicorn --workers 3 -b :5000 wsgi:app
240+
[Install]
241+
WantedBy=multi-user.target
242+
```
243+
Press Ctrl + X and save the file.
244+
3. Start the service using `sudo systemctl start backend`
245+
4. Then enable it so that it starts at boot:
246+
`sudo systemctl enable myproject`
247+
248+
Now, You'll can directly cater requests to the port and your app should work. I recommend using a
249+
reverse proxy for your requests by altering the nginx configuration and adding an endpoint
250+
for the API.

0 commit comments

Comments
 (0)