RestlessMonks’ Cookbook

Abhinav Rai
3 min readMay 26, 2020

How to run rails server (or any server) on a VM?

  1. Make sure nginx is installed. Else follow this simple guide first —
  2. Go to cd /etc/nginx/sites-available
  3. Add below details. Replace your server_name and proxy_pass (Where your server is running) with correct values
location / {
proxy_pass http://localhost:3002;
proxy_http_version 1.1;
listen 80;
listen [::]:80;

4. Create a symlink for it:

sudo ln -s /etc/nginx/sites-available/testapp /etc/nginx/sites-enabled/testapp

5. Restart Nginx:

sudo nginx -s reload

How to run service?

cd /etc/systemd/system/<Create a new file - grambuddy-server.service> and enter the below details in it[Unit]
Description= instance to start grambuddy backend server
ExecStart=/bin/bash -lc 'bundle exec rails server -e production -p 3002'

Then systemctl start grambuddy-server.service

How to make an endpoint http“s” / get certificate for free from let’s encrypt?

  1. Ref:
certbot{and then choose the domain from the nginx}

How to Deploy a static react build in VM?

Here website name is

cp -r  build htmlmv html /var/www/ -R $USER:$USER /var/www/ -R 755 /var/www/framery.innginx -tsystemctl restart nginx

How to copy Postgres data to a CSV and then to your computer

\copy (select * from users order by created_at desc) to '~/users_till_26_may.csv' with csv

And then

scp root@ ~/Desktop/profilebud/data

Postgres Dump

pg_dump -h localhost -p 5432 -U postgres -d db_name -t table_name > name.sqlpsql instagram_tools_backend < 4_NOV_USERS.sql


Moving Files within Server
# In local to copy file from remote to local
scp root@192.123.456.7:~/4_NOV_USERS.sql /home/dell/Downloads/Instagram/4_NOV_USERS.sql# In local to copy file from local to remotescp /home/dell/Downloads/Instagram/4_NOV_USERS.sql root@$192.123.456.7:~/4_NOV_USERS.sql

Check the IP


Sample Dummy JSON Data


Postgres Config: /etc/postgresql/10/main/postgresql.conf

Restart Service:
service postgresql restart
Get a DB Size:
SELECT pg_size_pretty( pg_database_size('leadgen') );
Get Size for Specific Table:
pg_size_pretty( pg_total_relation_size('tablename') );
Show Data Directory
postgres=# SHOW data_directory;

Mounting a volume Digital Ocean:

RAM & Disk Usage in Ubuntu

Disk Usage

df -h

Another killer tool which I would recommend — ncdu

sudo apt-get install ncdu && sudo ncdu /

RAM Usage

htop or free -m

Increasing Digitalocean Volume and Increasing Filesystem

  • Increasing volume is easy. Just go to Digitalocean dashboard and increase the volume size. PS: That is irreversible
  • After that you need to increase the file system too. Check it out here

For RestlessMonk’s case, everytime you increase the volume, increase the filesystem too -> just do

df -h        # to check the volume
resize2fs /dev/sda

Moving Postgres Data to Volume

Nginx as Load Balancer

Remove Duplicate Users from Table W.R.T multiple Column Values

Install Oh-My-Zsh in ubuntu

Rotate Journalctl Logs

For Removing Long running queries in Postgres

World of Tmux



Abhinav Rai

Buliding Engagebud | Guitarist | Traveller | Entrepreneur