linux useful commands

The idea of this post is to encapsulate all the commands and posts that I used configuring my new Digital Ocean Droplet

Disclaimer: All those commands were executed under Ubuntu 18.04.1 LTS.

Deploy Dotnet Core Application, long path



> git config --global user.name "whistler092"
> git config --global user.email "iamramiroo@gmail.com"
> git config -l

> mkdir -p ~/src/dotnet-core-app
> git clone https://github.com/Whistler092/market-list-angular.git

> cd ~/src/dotnet-core-app
> dotnet build --configuration Release
Microsoft (R) Build Engine version 17.1.1+a02f73656 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  Restored /home/whistler092/market/market-list-v4/Protocol/Protocol.csproj (in 6.87 sec).
  Restored /home/whistler092/market/market-list-v4/Domain/Domain.csproj (in 3 ms).
  Restored /home/whistler092/market/market-list-v4/Application/Application.csproj (in 40 ms).
  Restored /home/whistler092/market/market-list-v4/Application.Tests/Application.Tests.csproj (in 7.76 sec).
  Domain -> /home/whistler092/market/market-list-v4/Domain/bin/Release/net6.0/Domain.dll
  Application -> /home/whistler092/market/market-list-v4/Application/bin/Release/net6.0/Application.dll
  Application.Tests -> /home/whistler092/market/market-list-v4/Application.Tests/bin/Release/net6.0/Application.Tests.dll
  Protocol -> /home/whistler092/market/market-list-v4/Protocol/bin/Release/net6.0/Protocol.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:39.50

> mkdir -p app/published-app
> dotnet publish -o app/published-app
Microsoft (R) Build Engine version 17.1.1+a02f73656 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
  Domain -> /home/whistler092/market/market-list-v4/Domain/bin/Debug/net6.0/Domain.dll
  Domain -> /home/whistler092/market/market-list-v4/app/published-app/
  Application -> /home/whistler092/market/market-list-v4/Application/bin/Debug/net6.0/Application.dll
  Application -> /home/whistler092/market/market-list-v4/app/published-app/
  Application.Tests -> /home/whistler092/market/market-list-v4/Application.Tests/bin/Debug/net6.0/Application.Tests.dll
  Application.Tests -> /home/whistler092/market/market-list-v4/app/published-app/
  Protocol -> /home/whistler092/market/market-list-v4/Protocol/bin/Debug/net6.0/Protocol.dll
  Protocol -> /home/whistler092/market/market-list-v4/app/published-app/

> cd app/published-app
> dotnet Protocol.dll > out.log 2>&1 &
[1] 297878
> cat out.log
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: /home/whistler092/market/market-list-v4/app/published-app

> sudo ufw allow 5000
> sudo ufw allow 5001

> ps -all
F S   UID     PID    PPID  C PRI  NI ADDR SZ WCHAN  TTY          TIME CMD
0 S  1000  297878  296909  0  80   0 - 783388 futex_ pts/0   00:00:04 dotnet
0 R  1000  298218  296909  0  80   0 -  2633 -      pts/0    00:00:00 ps
> kill 297878

Install .NET on Linux

Install Nginx

> sudo apt-get install nginx
> sudo /etc/init.d/nginx start
> sudo /etc/init.d/nginx reload

> /etc/nginx/sites-available
> sudo vim default
Edit the location configuration 
add the lines in location
    proxy_pass http://localhost:5000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection keep-alive;
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
sudo /etc/init.d/nginx reload

https://www.codeproject.com/Articles/5326406/Create-a-Digital-Ocean-Droplet-for-NET-Core-Web-AP

Generate SSL Certificates


> sudo certbot --nginx -d host.ramirobedoya.me
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Requesting a certificate for host.ramirobedoya.me

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/host.ramirobedoya.me/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/host.ramirobedoya.me/privkey.pem
This certificate expires on 2022-09-01.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

Deploying certificate
Successfully deployed certificate for host.ramirobedoya.me to /etc/nginx/sites-enabled/default
Congratulations! You have successfully enabled HTTPS on https://host.ramirobedoya.me

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
If you like Certbot, please consider supporting our work by:
 * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
 * Donating to EFF:                    https://eff.org/donate-le
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

sudo certbot renew –dry-run

How to Install and Setup PostgreSQL server on Ubuntu 20.04

https://www.cherryservers.com/blog/how-to-install-and-setup-postgresql-server-on-ubuntu-20-04