<aside> <img src="/icons/emoji_gray.svg" alt="/icons/emoji_gray.svg" width="40px" />

Retrieving Username

Of course after 4 weeks of not entering my virtual host, I forgot my username. Fortunately ssh key is setup. Retrieving passwords would be much harder than username.

I entered the droplet console using "root", and type the below command and retrieve my username:

ls /home

</aside>

<aside> <img src="/icons/ghost_gray.svg" alt="/icons/ghost_gray.svg" width="40px" />

APT Zombie Process

(My username and host name is masked as “username” and “virtualhost” below )

Below error showed up when I tried to update apt:

username@virtualhost:~$ sudo apt update
[sudo] password for username: 
Error: Could not get lock /var/lib/apt/lists/lock. It is held by process 161877 (apt-get)
Notice: Be aware that removing the lock file is not a solution and may break your system.
Error: Unable to lock directory /var/lib/apt/lists/

This error is process 161877 holding APT lock file.

<aside> <img src="/icons/light-bulb_gray.svg" alt="/icons/light-bulb_gray.svg" width="40px" />

ChatGPT: What is APT lock file

APT uses lock files to make sure that only one package management process runs at a time.

This prevents conflicts or database corruption.

Typical lock files include:

/var/lib/apt/lists/lock
/var/lib/dpkg/lock-frontend
/var/cache/apt/archives/lock

When you run apt update, APT tries to “lock” those files.

</aside>

<aside> <img src="/icons/light-bulb_gray.svg" alt="/icons/light-bulb_gray.svg" width="40px" />

ChatGPT: What cause the background APT hanging

APT (the Advanced Package Tool) sometimes runs automatically in the background, not just when you manually use apt.

There are two main reasons:

a. Automatic system updates

b. Interrupted or stuck manual commands

So even though you’re not actively running APT, the system (or an old session) might still have it open in the background.

</aside>

So I checked to see the detail of process 161877, and found that it’s an old APT background process started at 9/23.

username@virtualhost:~$ ps aux | grep apt
root      161845  0.0  0.1   2888  1904 ?        Ss   Sep23   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily update
root      161849  0.0  0.2   2888  1968 ?        S    Sep23   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held update
root      161877  0.0  1.1  25312 11080 ?        S    Sep23   7:57 apt-get -qq -y update
_apt      161887  0.0  0.9  23520  9468 ?        S    Sep23   0:00 /usr/lib/apt/methods/http
_apt      161888  0.0  0.9  23524  9468 ?        S    Sep23   0:00 /usr/lib/apt/methods/http
_apt      161889  0.0  1.2  24720 11888 ?        S    Sep23   0:00 /usr/lib/apt/methods/https
_apt      161891  0.0  0.5  21960  5512 ?        S    Sep23   0:00 /usr/lib/apt/methods/gpgv
_apt      161901  0.0  0.9  38748  9444 ?        S    Sep23   0:00 /usr/lib/apt/methods/store
username  560918  0.0  0.2   7300  2188 pts/0    S+   11:57   0:00 grep --color=auto apt

It seems like the “root” gave command to run daily apt updates on 9/23, _apt proceed the command. However, interruption happened and the system stuck till now. Thus, I killed this zombie process and checked again. It showed that the apt isn’t occupied anymore. “apt update” can be conducted smoothly afterwards.

username@virtualhost:~$ sudo kill -9 161887
username@virtualhost:~$ ps aux | grep apt
root      161845  0.0  0.1   2888  1904 ?        Ss   Sep23   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily update
root      161849  0.0  0.2   2888  1968 ?        S    Sep23   0:00 /bin/sh /usr/lib/apt/apt.systemd.daily lock_is_held update
root      161877  0.0  1.2  25312 12248 ?        S    Sep23   7:57 apt-get -qq -y update
root      560974  0.0  0.5  25312  5340 ?        S    12:05   0:00 apt-get -qq -y update
root      561030 87.3  9.5 108944 93784 ?        RN   12:05   0:04 /usr/bin/python3 /usr/lib/update-notifier/apt-check --human-readable
username      561040  0.0  0.2   7300  2292 pts/0    S+   12:05   0:00 grep --color=auto apt

I checked to see if there’s any incidents happening during 9/23 that might lead to this interruption. Sadly it’s just a local error. 🫤 I know this is evil, but I was so ready to trace it back to an outage happening in the network, Holmes style.

</aside>

<aside> <img src="/icons/rename_gray.svg" alt="/icons/rename_gray.svg" width="40px" />

Nginx up and running

username@virtualhost:~$ curl -4 138.197.66.181
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
html { color-scheme: light dark; }
body { width: 35em; margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="<http://nginx.org/>">nginx.org</a>.<br/>
Commercial support is available at
<a href="<http://nginx.com/>">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

“Not Secure” since it’s run by HTTP.

“Not Secure” since it’s run by HTTP.

</aside>

<aside> <img src="/icons/rename_gray.svg" alt="/icons/rename_gray.svg" width="40px" />

Domain Name purchase and setup

I purchased a free .me domain name with student account in Namecheap.

To setup an A record for linking my DigitalOcean droplet with the domain name, I have 2 options: either set it up on Namecheap, or on DigitalOcean. I went for DigitalOcean since there’s potential for me to set up multiple server blocks for single droplet, I figured it’s more convenient to manage them all on the same platform.

<aside> <img src="/icons/row_gray.svg" alt="/icons/row_gray.svg" width="40px" />

Different types of DNS records

Record Type Full Name Purpose Example
A Address Record Maps a domain name to an IPv4 address test.com → 138.197.66.181
AAAA IPv6 Address Record Maps a domain name to an IPv6 address test.com → 2604:a880:400:d0::1
CNAME Canonical Name Record Points one domain name to another domain name(alias) www.test.com → test.com
MX Mail Exchange Record Specifies the mail server responsible for receiving emails test.com → mail.test.com
TXT Text Record Stores text data for verification or email security (SPF, DKIM, etc.) "v=spf1 include:_spf.google.com ~all"
</aside>

<aside> <img src="/icons/row_gray.svg" alt="/icons/row_gray.svg" width="40px" />

Why “www” also need a A record?

In the 1990s, “www” indicated the server that provided World Wide Web services — one of several types of servers on the Internet (alongside mail, ftp, etc.). Over time, this convention became a historical habit, and today “www” is usually just part of the URL.

</aside>

<aside> <img src="/icons/row_gray.svg" alt="/icons/row_gray.svg" width="40px" />

Why are there 2 file in /var/www? (one is html, one is for the domain name)?

If the user entered by IP, it still goes with the nginx default html:

image.png

</aside>

</aside>