Skip to content

Commit 818b37e

Browse files
committed
Updated
1 parent fa45a45 commit 818b37e

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

docs/10-The-Client-Demonstration/02-Troubleshoot-the-Development-Environment.md

+39-17
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
1. Information only
77
1. Information only
88
1. <details>
9-
<summary>Copy the file caleston-code.tar.gz from Bob's laptop to Bob's home directory on the webserver devapp01</summary>
9+
<summary>Copy the file <code>caleston-code.tar.gz</code> from Bob's laptop to Bob's home directory on the webserver <code>devapp01</code></summary>
1010

1111
```bash
1212
scp caleston-code.tar.gz devapp01:~/
1313
```
1414

1515
</details>
1616
1. <details>
17-
<summary>On the devapp01 webserver, unzip and extract the copied file in the directory /opt/.</summary>
17+
<summary>On the <code>devapp01</code> webserver, unzip and extract the copied file in the directory <code>/opt/</code>.</summary>
1818

1919
Note that the `/opt` directory is owned by root on `devapp01` so we'll need sudo
2020
@@ -28,15 +28,15 @@
2828

2929
</details>
3030
1. <details>
31-
<summary>Delete the tar file from devapp01 webserver.</summary>
31+
<summary>Delete the tar file from <code>devapp01</code> webserver.</summary>
3232

3333
```bash
3434
rm caleston-code.tar.gz
3535
```
3636

3737
</details>
3838
1. <details>
39-
<summary>Make sure that the directory is extracted in such a way that the path /opt/caleston-code/mercuryProject/ exists on the webserver.</summary>
39+
<summary>Make sure that the directory is extracted in such a way that the path <code>/opt/caleston-code/mercuryProject/</code> exists on the <code>webserver</code>.</summary>
4040

4141
Nothing to do here. If you got Q4 right, then this will work too - press OK.
4242

@@ -48,7 +48,7 @@
4848

4949
</details>
5050
1. <details>
51-
<summary>For the client demo, Bob has installed a postgres database in devdb01.</br>SSH to the database devdb01 and check the status of the postgresql.service</br>What is the state of the DB?</summary>
51+
<summary>For the client demo, Bob has installed a <code>postgres</code> database in <code>devdb01</code>.</br>SSH to the database <code>devdb01</code> and check the status of the <code>postgresql.service</code></br>What is the state of the DB?</summary>
5252

5353
At this point you are still logged into `devapp01`, so first return to Bob's laptop
5454
@@ -69,7 +69,7 @@
6969
Don't exit from the ssh session just yet. We need to remain on `devdb01`
7070
</details>
7171
1. <details>
72-
<summary>Add an entry host all all 0.0.0.0/0 md5 to the end of the file /etc/postgresql/10/main/pg_hba.conf on the DB server.</br>This will allow the web application to connect to the DB.</summary>
72+
<summary>Add an entry <code>host all all 0.0.0.0/0</code> md5 to the end of the file <code>/etc/postgresql/10/main/pg_hba.conf</code> on the DB server.</br>This will allow the web application to connect to the DB.</summary>
7373

7474
```bash
7575
sudo vi /etc/postgresql/10/main/pg_hba.conf
@@ -79,15 +79,15 @@
7979

8080
</details>
8181
1. <details>
82-
<summary>Start the postgres DB on the devdb01 server.</summary>
82+
<summary>Start the <code>postgres</code> DB on the <code>devdb01</code> server.</summary>
8383

8484
```bash
8585
sudo systemctl start postgresql.service
8686
```
8787

8888
</details>
8989
1. <details>
90-
<summary>What port is postgres running on? Check using the netstat command?</summary>
90+
<summary>What port is <code>postgres</code> running on? Check using the <code>netstat</code> command?</summary>
9191

9292
```bash
9393
sudo netstat -ptean
@@ -97,7 +97,7 @@
9797
9898
</details>
9999
1. <details>
100-
<summary>Back on the devapp01 webserver. Attempt to start the web application by:</br>Navigate to the directory /opt/caleston-code/mercuryProject</br>Next, run the command python3 manage.py runserver 0.0.0.0:8000</summary>
100+
<summary>Back on the <code>devapp01</code> webserver. Attempt to start the web application by:</br>Navigate to the directory <code>/opt/caleston-code/mercuryProject</code></br>Next, run the command <code>python3 manage.py runserver 0.0.0.0:8000</code></summary>
101101
102102
At this point you are still logged into `devdb01`, so first return to Bob's laptop
103103

@@ -126,7 +126,15 @@
126126

127127
</details>
128128
1. <details>
129-
<summary>It appears that Bob did not configure his app to connect a postgres database running on a different server.</summary>
129+
<summary>It appears that Bob did not configure his app to connect a <code>postgres</code> database running on a different server.</summary>
130+
131+
That explains why things are working on his laptop and not in the `DEV` servers.
132+
133+
It also appears that he is using the `wrong` port for postgres!
134+
135+
1. Find the file in the directory under `/opt/caleston-code` that has a string matching DATABASES = {.
136+
1. Replace the value of `localhost` to `devdb01`
137+
1. In the same file fix the postgres port to match the port being used on `devdb01`
130138

131139
For this, we need to first find the file we need to edit, so we're going to use `find` to find _files_ and use `grep` to find the specific text, with the `-l` switch to print the file path the text was found in.
132140
@@ -144,18 +152,27 @@
144152
145153
</details>
146154
1. <details>
147-
<summary>Now that has been set up, change the ownership of ALL files and directories under /opt/caleston-code to user mercury.</summary>
155+
<summary>Now that has been set up, change the ownership of ALL files and directories under <code>/opt/caleston-code</code> to user <code>mercury</code>.</summary>
148156
149157
You'll need to be root to reassign ownership
150158

151159
```bash
152160
sudo chown -R mercury /opt/caleston-code
153161
```
154162

163+
Note that sometimes this step is marked incorrect even though it *is* correct! Ignore this and move on. It has been reported to the lab team.
164+
155165
</details>
156166
1. <details>
157167
<summary>Great! Everything should now be in order to restart the application.</summary>
158168

169+
On the devapp01 server start the webserver again by running the command:
170+
171+
1. Navigate to the directory `/opt/caleston-code/mercuryProject`
172+
1. Next, run the command `python3 manage.py runserver 0.0.0.0:8000`
173+
174+
Note:- Make sure to activate the virtual environment using source `../venv/bin/activate` within the current project before executing `python3 manage.py migrate`.
175+
159176
If you've followed all the above steps, you should still be in directory `/opt/caleston-code/mercuryProject`
160177
161178
Start the app as directed and verify it works, then `CTRL-C` to exit.
@@ -169,6 +186,10 @@
169186
170187
Start the app again so the question will validate.
171188
189+
```
190+
python3 manage.py runserver 0.0.0.0:8000
191+
```
192+
172193
**What is this venv stuff?**
173194
174195
If you're considering learning Python (highly recommended as it is required in many DevOps jobs), this means Virtual ENVironment. It allows you to install Python packages on a project-by-project basis, thus not polluting the main Python installation. This is especially useful on your development environment where you may have multiple Python projects all with different package requirements.
@@ -177,15 +198,16 @@
177198
1. <details>
178199
<summary>Well done! Now, for the final task before the client presentation.</summary>
179200

180-
Here we have to create a [systemd unit file](https://kodekloud.com/topic/creating-a-systemd-service/) to make the Python app be runnable as a service.
201+
Create a new service called mercury.service with the following requirements.
181202

182-
First quit the running webapp by pressing `CTRL-C`
203+
1. Service name: - `mercury.service`, WorkingDirectory: - `/opt/caleston-code/mercuryProject/`, Command to run: `/usr/bin/python3 manage.py runserver 0.0.0.0:8000`.
204+
1. Restart `on failure` and enable for `multi-user.target`.
205+
1. Run as user `mercury`.
206+
1. Set description: `Project Mercury Web Application`.
183207

184-
Note that in unit files, the process to execute (in this case `python3`) we must use its fully qualified path, as `systemd` does not have a search path. Get this like this
208+
Here we have to create a [systemd unit file](https://kodekloud.com/topic/creating-a-systemd-service/) to make the Python app be runnable as a service.
185209

186-
```bash
187-
which python3
188-
```
210+
First quit the running webapp by pressing `CTRL-C`
189211

190212
Now create the unit file
191213

0 commit comments

Comments
 (0)