Final LAB failed

After changing host in the settings to devdb01 and port to 5432,
cd to /opt/caleston-code/mercuryProject/
I run the command python3 manage.py runserver 0.0.0.0:8000 once again.
but it showed an error
Failed to start mercury.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files
I took the test twice. same error.

Please make sure that you have edited both the host name and the port number as shown below
Then run those commands
$ vi /opt/caleston-code/mercuryProject/mercury/settings.py
$ sudo chown -R mercury /opt/caleston-code
$ cd /opt/caleston-code/mercuryProject
$ python3 manage.py runserver 0.0.0.0:8000
And it will work fine
Screen Shot 2021-05-28 at 14.24.21
Screen Shot 2021-05-28 at 14.27.06

Hi,

Yes. you can see that I have mentioned the same host and port in my post.

I tried twice. Did exactly the same steps. even I tried copying commands from the hint. still it showed same error.

Could you please explain the error

And while I was taking the lab for the second time I changed the host and saved the file in a hurry keeping the port 5433 unchanged. I was able to go to next question without changing the port to 5432. please look into that also.

I took the test once again. still, it shows the same errors.
After changing, host and port, permissions, error is same.

can you please share your steps in all the tasks in this lab

I did try once again. It was my 4th attempt.
I tried the exact same commands in my previous attempts.
Surprisingly it worked without the usual error.
Attaching the commands.
Thanks for the support

bob@caleston-lp10:~$ scp caleston-code.tar.gz devapp01:/home/bob/
bob@devapp01's password: 
caleston-code.tar.gz                                              100% 1439KB  76.1MB/s   00:00 
bob@caleston-lp10:~$ ssh devapp01
bob@devapp01's password: 
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-101-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.
 _______  _______  _        _______  _______ _________ _______  _       
(  ____ \(  ___  )( \      (  ____ \(  ____ \\__   __/(  ___  )( (    /|
| (    \/| (   ) || (      | (    \/| (    \/   ) (   | (   ) ||  \  ( |
| |      | (___) || |      | (__    | (_____    | |   | |   | ||   \ | |
| |      |  ___  || |      |  __)   (_____  )   | |   | |   | || (\ \) |
| |      | (   ) || |      | (            ) |   | |   | |   | || | \   |
| (____/\| )   ( || (____/\| (____/\/\____) |   | |   | (___) || )  \  |
(_______/|/     \|(_______/(_______/\_______)   )_(   (_______)|/    )_)
Last login: Wed Apr 15 08:19:16 2020 from 172.16.238.3
bob@devapp01:~$ 
bob@devapp01:~$ ls
caleston-code.tar.gz
bob@devapp01:~$ gunzip caleston-code.tar.gz 
bob@devapp01:~$ tar -xf caleston-code.tar 
bob@devapp01:~$ ls
caleston-code  caleston-code.tar
bob@devapp01:~$ sudo mv caleston-code /opt/
bob@devapp01:~$ ls /opt/
caleston-code
bob@devapp01:~$ rm caleston-code.tarĂž
bob@devapp01:/opt/caleston-code$ ls mercuryProject/
admin.json  blog  db.json  manage.py  media  mercury  portfolios  templates
bob@devapp01:/opt/caleston-code$ ssh devdb01
The authenticity of host 'devdb01 (172.16.239.10)' can't be established.
ECDSA key fingerprint is SHA256:woXXNAlu0TpKdmqZk8EA+qhTQqKNPZtSNs4M0/lAWmw.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'devdb01,172.16.239.10' (ECDSA) to the list of known hosts.
bob@devdb01's password: 
Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 4.15.0-101-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

This system has been minimized by removing packages and content that are
not required on a system that users do not log into.

To restore this content, you can run the 'unminimize' command.

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

 _______  _______  _        _______  _______ _________ _______  _       
(  ____ \(  ___  )( \      (  ____ \(  ____ \\__   __/(  ___  )( (    /|
| (    \/| (   ) || (      | (    \/| (    \/   ) (   | (   ) ||  \  ( |
| |      | (___) || |      | (__    | (_____    | |   | |   | ||   \ | |
| |      |  ___  || |      |  __)   (_____  )   | |   | |   | || (\ \) |
| |      | (   ) || |      | (            ) |   | |   | |   | || | \   |
| (____/\| )   ( || (____/\| (____/\/\____) |   | |   | (___) || )  \  |
(_______/|/     \|(_______/(_______/\_______)   )_(   (_______)|/    )_)

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

Last login: Thu Apr 16 02:53:14 2020 from 172.16.239.3
bob@devdb01:~$ 
Last login: Thu Apr 16 02:53:14 2020 from 172.16.239.3.
bob@devdb01:~$ systemctl status postgresql
* postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sat 2021-05-29 14:32:52 UTC; 1min 49s ago
  Process: 357 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 357 (code=exited, status=0/SUCCESS)
bob@devdb01:~$ sudo vi /etc/postgresql/10/main/pg_hba.conf 
[sudo] password for bob:
bob@devdb01:~$ sudo systemctl start postgresql
bob@devdb01:~$ netstat -an | grep postgresql | grep LISTEN
unix  2      [ ACC ]     STREAM     LISTENING     54460    /var/run/postgresql/.s.PGSQL.5432
bob@devdb01:~$ exit
logout
Connection to devdb01 closed.
bob@devapp01:/opt/caleston-code$ cd mercuryProject/
bob@devapp01:/opt/caleston-code/mercuryProject$ python3 manage.py runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
Exception in thread django-main-thread:
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5433?
could not connect to server: Cannot assign requested address
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5433?


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.6/threading.py", line 864, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.6/dist-packages/django/utils/autoreload.py", line 54, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/commands/runserver.py", line 120, in inner_run
    self.check_migrations()
  File "/usr/local/lib/python3.6/dist-packages/django/core/management/base.py", line 453, in check_migrations
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
  File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
  File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/loader.py", line 49, in __init__
    self.build_graph()
  File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/loader.py", line 212, in build_graph
    self.applied_migrations = recorder.applied_migrations()
  File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py", line 73, in applied_migrations
    if self.has_table():
  File "/usr/local/lib/python3.6/dist-packages/django/db/migrations/recorder.py", line 56, in has_table
    return self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor())
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 256, in cursor
    return self._cursor()
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 233, in _cursor
    self.ensure_connection()
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.6/dist-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 217, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/base/base.py", line 195, in connect
    self.connection = self.get_new_connection(conn_params)
  File "/usr/local/lib/python3.6/dist-packages/django/db/backends/postgresql/base.py", line 178, in get_new_connection
    connection = Database.connect(**conn_params)
  File "/usr/local/lib/python3.6/dist-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5433?
could not connect to server: Cannot assign requested address
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5433?


^Cbob@devapp01:/opt/caleston-code/mercuryProject$ grep -ir "DATABASES = {" /opt/caleston-code/
/opt/caleston-code/mercuryProject/mercury/settings.py:DATABASES = {
bob@devapp01:/opt/caleston-code/mercuryProject$ vi mercury/settings.py 
bob@devapp01:/opt/caleston-code/mercuryProject$ sudo chown -R mercury /opt/caleston-code/
bob@devapp01:/opt/caleston-code/mercuryProject$ pwd   
/opt/caleston-code/mercuryProject
bob@devapp01:/opt/caleston-code/mercuryProject$ python3 manage.py runserver 0.0.0.0:8000
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
May 29, 2021 - 14:43:49
Django version 2.2.6, using settings 'mercury.settings'
Starting development server at http://0.0.0.0:8000/
Quit the server with CONTROL-C.
[29/May/2021 14:43:53] "GET / HTTP/1.1" 200 4525
^Cbob@devapp01:/opt/caleston-code/mercuryProject$ 

bob@devapp01:~$ sudo vi /etc/systemd/system/mercury.service
bob@devapp01:~$ systemctl status mercury.service
* mercury.service - Project Mercury Web Application
   Loaded: loaded (/etc/systemd/system/mercury.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
bob@devapp01:~$ sudo systemctl start mercury.service
bob@devapp01:~$ sudo systemctl enable mercury.service
Created symlink /etc/systemd/system/multi-user.target.wants/mercury.service -> /etc/systemd/system/mercury.service.
bob@devapp01:~$

@pvsaroop Great!
You’re welcome

1 Like

Thanks for the full list of commands, i am able to complete the lab and pass all the checks.
I did the python3 manage.py migrate before the runserver, the webpage shows something but empty.
Can anyone help? thanks

Hello @subhajeetsur,
Can you please provide us with a screenshot of the issue?

Thanks,
KodeKloud Support

Hi, here is the screenshot of the web server. I went to caleston-code folder, activate the venv, run the migrate command, exit the environment, go to folder mercuryProject, run manage.py.

Hello,I have this problem
You have 19 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, blog, contenttypes, portfolios, sessions.
Run ‘python manage.py migrate’ to apply them.

I have tried to complete the project but the application did not work.
Can someone help me fix this problem of unapplied migration?
thanks

The solution to this lab is here.
It works - I have just run through it.

I still can’t complete the lab correctly.I see this blank page at th end of the lab
.See attached proof.Can some one help me please on how to create mercury.service and execute the lab test correctly.

That’s what you’re meant to see. How did you get it to show that? By running it from the command line as in an earlier step?

The problem is that,the sample of project mercury shows “webpage with photos” as per the last q.17.But i don’t get it that way,this is my problem,what i see is just Caleston Technologies at the end lab.Can you tell me .if this is correct?

Yes it’s correct. I’ve never seen that page actually have images.
If the lab goes green when you press the check button then it’s working.

The marking script is only checking that the site doesn’t have an error, which it will if the database isn’t connected or if the migrate hasn’t been run.