|
6 | 6 | 1. Information only
|
7 | 7 | 1. Information only
|
8 | 8 | 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> |
10 | 10 |
|
11 | 11 | ```bash
|
12 | 12 | scp caleston-code.tar.gz devapp01:~/
|
13 | 13 | ```
|
14 | 14 |
|
15 | 15 | </details>
|
16 | 16 | 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> |
18 | 18 |
|
19 | 19 | Note that the `/opt` directory is owned by root on `devapp01` so we'll need sudo
|
20 | 20 |
|
|
28 | 28 |
|
29 | 29 | </details>
|
30 | 30 | 1. <details>
|
31 |
| - <summary>Delete the tar file from devapp01 webserver.</summary> |
| 31 | + <summary>Delete the tar file from <code>devapp01</code> webserver.</summary> |
32 | 32 |
|
33 | 33 | ```bash
|
34 | 34 | rm caleston-code.tar.gz
|
35 | 35 | ```
|
36 | 36 |
|
37 | 37 | </details>
|
38 | 38 | 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> |
40 | 40 |
|
41 | 41 | Nothing to do here. If you got Q4 right, then this will work too - press OK.
|
42 | 42 |
|
|
48 | 48 |
|
49 | 49 | </details>
|
50 | 50 | 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> |
52 | 52 |
|
53 | 53 | At this point you are still logged into `devapp01`, so first return to Bob's laptop
|
54 | 54 |
|
|
69 | 69 | Don't exit from the ssh session just yet. We need to remain on `devdb01`
|
70 | 70 | </details>
|
71 | 71 | 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> |
73 | 73 |
|
74 | 74 | ```bash
|
75 | 75 | sudo vi /etc/postgresql/10/main/pg_hba.conf
|
|
79 | 79 |
|
80 | 80 | </details>
|
81 | 81 | 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> |
83 | 83 |
|
84 | 84 | ```bash
|
85 | 85 | sudo systemctl start postgresql.service
|
86 | 86 | ```
|
87 | 87 |
|
88 | 88 | </details>
|
89 | 89 | 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> |
91 | 91 |
|
92 | 92 | ```bash
|
93 | 93 | sudo netstat -ptean
|
|
97 | 97 |
|
98 | 98 | </details>
|
99 | 99 | 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> |
101 | 101 |
|
102 | 102 | At this point you are still logged into `devdb01`, so first return to Bob's laptop
|
103 | 103 |
|
|
126 | 126 |
|
127 | 127 | </details>
|
128 | 128 | 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` |
130 | 138 |
|
131 | 139 | 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.
|
132 | 140 |
|
|
144 | 152 |
|
145 | 153 | </details>
|
146 | 154 | 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> |
148 | 156 |
|
149 | 157 | You'll need to be root to reassign ownership
|
150 | 158 |
|
151 | 159 | ```bash
|
152 | 160 | sudo chown -R mercury /opt/caleston-code
|
153 | 161 | ```
|
154 | 162 |
|
| 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 | + |
155 | 165 | </details>
|
156 | 166 | 1. <details>
|
157 | 167 | <summary>Great! Everything should now be in order to restart the application.</summary>
|
158 | 168 |
|
| 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 | + |
159 | 176 | If you've followed all the above steps, you should still be in directory `/opt/caleston-code/mercuryProject`
|
160 | 177 |
|
161 | 178 | Start the app as directed and verify it works, then `CTRL-C` to exit.
|
|
169 | 186 |
|
170 | 187 | Start the app again so the question will validate.
|
171 | 188 |
|
| 189 | + ``` |
| 190 | + python3 manage.py runserver 0.0.0.0:8000 |
| 191 | + ``` |
| 192 | +
|
172 | 193 | **What is this venv stuff?**
|
173 | 194 |
|
174 | 195 | 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 | 198 | 1. <details>
|
178 | 199 | <summary>Well done! Now, for the final task before the client presentation.</summary>
|
179 | 200 |
|
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. |
181 | 202 |
|
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`. |
183 | 207 |
|
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. |
185 | 209 |
|
186 |
| - ```bash |
187 |
| - which python3 |
188 |
| - ``` |
| 210 | + First quit the running webapp by pressing `CTRL-C` |
189 | 211 |
|
190 | 212 | Now create the unit file
|
191 | 213 |
|
|
0 commit comments