Blog

  • How to Auto restart elasticsearch with monit

    monit is a program used to monitor processes and restart them if they failed. If your server don’t have monit installed, see install instructions at Install Monit on Ubuntu or Install Monit on CentOS

    To restart elasticsearch on failure, create a file

    vi /etc/monit/conf-enabled/elasticsearch.conf 
    

    Add the following content to the file

    check process elasticsearch with pidfile "/var/run/elasticsearch/elasticsearch.pid"
       start program = "/bin/systemctl start elasticsearch"
       stop  program = "/bin/systemctl stop elasticsearch"
    

    Reload monit with

    monit reload
    

    To check the status of monit, run

    monit status
    

    Example

    root@sok:~# monit status
    Monit 5.26.0 uptime: 8m
    
    Process 'elasticsearch'
      status                       OK
      monitoring status            Monitored
      monitoring mode              active
      on reboot                    start
      pid                          366866
      parent pid                   1
      uid                          115
      effective uid                115
      gid                          118
      uptime                       6m
      threads                      60
      children                     1
      cpu                          -
      cpu total                    -
      memory                       58.0% [2.2 GB]
      memory total                 58.2% [2.2 GB]
      security attribute           unconfined
      disk read                    0 B/s [97.5 MB total]
      disk write                   0 B/s [2.3 MB total]
      data collected               Mon, 09 Aug 2021 10:07:22
    
    System 'sok.guest'
      status                       OK
      monitoring status            Monitored
      monitoring mode              active
      on reboot                    start
      load average                 [0.02] [0.18] [0.47]
      cpu                          4.4%us 1.4%sy 0.1%wa
      memory usage                 3.1 GB [81.7%]
      swap usage                   774.5 MB [18.9%]
      uptime                       3d 22h 39m
      boot time                    Thu, 05 Aug 2021 11:28:16
      data collected               Mon, 09 Aug 2021 10:07:22
    
    root@sok:~# 
    

    To see other ways of restarting ElasticSearch, see How to auto restart ElasticSearh service on failure

    Back to monit

  • imunify get list of all infected files

    imunify store data in SQLite database. To see a list of malware infected files, start sqllite with

    sqlite3 /var/imunify360/imunify360.db
    

    Data is stored in table malware_hits.

    To find the schema of the table, run

    .schema malware_hits
    

    We only want to orig_file column from the table, so run the SQL command

    select orig_file from malware_hits;
    

    Delete all past scan results

    If you need to clean all past scan results, then first stop imunify

    systemctl stop imunify-antivirus
    

    Start sqlite

    sqlite3 /var/imunify360/imunify360.db
    

    Delete data from the tables

    DELETE FROM malware_history;
    DELETE FROM malware_hits;
    DELETE FROM malware_scans;
    

    Exit from sqlite command prompt and start imunify

    systemctl start imunify-antivirus
    
  • How to Create Custom 404 Error Page in Apache

    A 404 error happens when a visitor comes to your website and the page requested is not found on your website. This happens when a link changed and some other pages or websites still link to your old web page URL.

    When “HTTP/1.1 404 Not Found” error occurs, web servers show a basic error message saying the page is not found on the server. Most visitors will leave your website when this happens. A properly built custom 404 page allows your site to engage the visitor, present them useful information, so they stay on the website, explore other pages instead of leaving the website.

    It is good practice to track 404 errors, set a 301 redirect for these pages to the proper destination, so your site visitors can find whatever they are looking for with fewer efforts.

    To create a custom 404 error page in the Apache web server, create a .htaccess file with the following content

    ErrorDocument 404 /404.html
    

    Create an HTML page with your custom 404 error message, save it as 404.html.

    Now when you access a page that is not present on your website, you will see this custom 404 error page.

    See htaccess

  • Temperature

    To find CPU Temperature, run command sensors

    sensors
    

    Example

    boby@sok-01:~$ sensors
    k10temp-pci-00c3
    Adapter: PCI adapter
    Vcore:       925.00 mV 
    Vsoc:          1.06 V  
    Tctl:         +36.2°C  
    Tdie:         +36.2°C  
    Icore:         4.00 A  
    Isoc:          1.75 A  
    
    boby@sok-01:~$ 
    

    To find the temperature of NVIDIA graphics card, run

    /usr/bin/nvidia-smi -q -d temperature
    

    Example

    boby@sok-01:~$ /usr/bin/nvidia-smi -q -d temperature
    
    ==============NVSMI LOG==============
    
    Timestamp                                 : Mon Aug  2 23:53:27 2021
    Driver Version                            : 460.91.03
    CUDA Version                              : 11.2
    
    Attached GPUs                             : 1
    GPU 00000000:01:00.0
        Temperature
            GPU Current Temp                  : 45 C
            GPU Shutdown Temp                 : 97 C
            GPU Slowdown Temp                 : 94 C
            GPU Max Operating Temp            : 92 C
            GPU Target Temperature            : 83 C
            Memory Current Temp               : N/A
            Memory Max Operating Temp         : N/A
    
    boby@sok-01:~$ 
    
  • sensors

    sensors command shows data from various sensors on your computer like CPU temperature, voltage, etc…

    To install lm-sensors package, run

    apt install lm-sensors
    

    To see sensor data, run the command “sensors”.

    boby@sok-01:~$ sensors
    k10temp-pci-00c3
    Adapter: PCI adapter
    Vcore:       844.00 mV 
    Vsoc:          1.06 V  
    Tctl:         +39.0°C  
    Tdie:         +39.0°C  
    Icore:         5.00 A  
    Isoc:          1.50 A  
    
    boby@sok-01:~$ 
    

    To properly configure sensors, you need to run

    sudo sensors-detect
    

    This only needs to run one time to detect your hardware configuration. It will ask many questions, press enter to use default values.

  • ss

    ss is a tool to investigate sockets. It is similar to netstat, but shows more information. To see list of all open ports, run

    ss -tlnp
    

    Example

    boby@sok-01:~$ sudo ss -lntp
    State   Recv-Q  Send-Q    Local Address:Port     Peer Address:Port  Process                                                                                                                                
    LISTEN  0       128           127.0.0.1:7878          0.0.0.0:*      users:(("ssh",pid=2401,fd=5))                                                                                                         
    LISTEN  0       80            127.0.0.1:3306          0.0.0.0:*      users:(("mysqld",pid=1135,fd=19))                                                                                                     
    LISTEN  0       4096            0.0.0.0:111           0.0.0.0:*      users:(("rpcbind",pid=880,fd=4),("systemd",pid=1,fd=34))                                                                              
    LISTEN  0       511             0.0.0.0:80            0.0.0.0:*      users:(("nginx",pid=1147,fd=10),("nginx",pid=1146,fd=10),("nginx",pid=1145,fd=10),("nginx",pid=1144,fd=10),("nginx",pid=1143,fd=10))  
    LISTEN  0       32        192.168.122.1:53            0.0.0.0:*      users:(("dnsmasq",pid=1528,fd=6))                                                                                                     
    LISTEN  0       4096      127.0.0.53%lo:53            0.0.0.0:*      users:(("systemd-resolve",pid=883,fd=13))                                                                                             
    LISTEN  0       5             127.0.0.1:631           0.0.0.0:*      users:(("cupsd",pid=929,fd=7))                                                                                                        
    LISTEN  0       511           127.0.0.2:443           0.0.0.0:*      users:(("nginx",pid=1147,fd=11),("nginx",pid=1146,fd=11),("nginx",pid=1145,fd=11),("nginx",pid=1144,fd=11),("nginx",pid=1143,fd=11))  
    LISTEN  0       1               0.0.0.0:7070          0.0.0.0:*      users:(("anydesk",pid=1054,fd=32))                                                                                                    
    LISTEN  0       128               [::1]:7878             [::]:*      users:(("ssh",pid=2401,fd=4))                                                                                                         
    LISTEN  0       4096               [::]:111              [::]:*      users:(("rpcbind",pid=880,fd=6),("systemd",pid=1,fd=36))                                                                              
    LISTEN  0       5                 [::1]:631              [::]:*      users:(("cupsd",pid=929,fd=6))                                                                                                        
    boby@sok-01:~$ 
    

    See netstat

  • How to install development tools on Debian/Ubuntu

    Development tools are programs used to build software from its source code. These include compilers, make, and other generally used libraries.

    To install development tools on Ubuntu/Debian, run

    apt install -y build-essential
    apt install -y autoconf automake gdb libffi-dev zlib1g-dev libssl-dev git wget

    See Ubuntu, Debian

  • Create a Debian Container in LXD

    Debian OS templates are available in images:debian/VERSION. To see all available Debian OS templates, run

    lxc image list images: debian

    To create a container with Debian 10 OS, run

    lxc launch  images:debian/10 my-debian

    Example

    lxd debian container

    Create alphine linux container

    lxc launch images:alpine/3.22 test-alpine

    To list all available alphone container versions, use

    lxc image list images: alpine

    See LXD

  • Audacity Import Filter Curve in Ubuntu

    The import feature in Audacity Filter Curve Plugin is disabled on Ubuntu. Save feature worked. So what I did was to save a preset, then edit it, replace it with the preset you need.

    To import Josh Meyer’s Male EQ preset available at

    https://drive.google.com/file/d/163aSM4c-I6REKDqIzD9IzwiyDR4cXqma/view

    First saved one of the preset. It asked for a name, I enter “sevrerok” as the preset name.

    Close Audacity, Edited the file

    /home/boby/.audacity-data/pluginsettings.cfg
    

    Find the entry like

    [pluginsettings/base64\:RWZmZWN0X0F1ZGFjaXR5X0F1ZGFjaXR5X0ZpbHRlciBDdXJ2ZQ\=\=/private/UserPresets/serverok]
    

    Below this, you can add your preset. Here is what I have in the pluginsettings.cfg file

    [pluginsettings/base64\:RWZmZWN0X0F1ZGFjaXR5X0F1ZGFjaXR5X0ZpbHRlciBDdXJ2ZQ\=\=/private/UserPresets/serverok]
    Parameters=f0="62.77682" f1="70.002037" f10="336.65327" f11="492.91565" f12="591.0509" f13="689.68267" f14="776.07428" f15="889.28813" f16="982.67802" f17="9948.9608" f18="11195.196" f19="12597.538" f2="73.252718" f20="14047.435" f21="16096.677" f3="83.938837" f4="97.946153" f5="119.59827" f6="152.81833" f7="195.26572" f8="221.72906" f9="256.39197" FilterLength="8191" InterpolateLin="0" InterpolationMethod="B-spline" v0="-41.952381" v1="-10.904762" v10="0.031745911" v11="-2.984127" v12="-1.3650789" v13="-0.015872955" v14="0.469841" v15="0.469841" v16="-0.015872955" v17="-0.015872955" v18="-0.031746864" v19="-0.031746864" v2="-5.2349215" v20="-1.7301588" v21="-41.885715" v3="-1.6888895" v4="0.13650751" v5="1.1746035" v6="2" v7="2" v8="1.3015871" v9="0.031745911"
    
  • How to uninstall the PowerShell Module?

    To uninstall a PowerShell module use the Uninstall-Module command. The module should not be in use to uninstall it.

    Uninstall-Module -Name MODULE_NAME_HERE
    

    To force uninstall a module run

    Uninstall-Module -Name MODULE_NAME_HERE -Force -Verbose
    

    To uninstall all versions of a module, use option -AllVersions

    Uninstall-Module -Name MODULE_NAME_HERE -AllVersions -Force -Verbose
    

    If you need to keep a version and uninstall all other versions, run

    Uninstall-Module -Name MODULE_NAME_HERE -RequiredVersion 2.1.2 -Force -Verbose
    
  • ACME (acme.sh) Free SSL Certificate

    ACME (acme.sh) is a shell script for generating LetsEncrypt SSL certificate. acme.sh is written in bash, so it works on any Linux server without special requirements. For getting SSL, another popular option is to use certbot.

    To install, run

    cd /usr/local/src
    git clone https://github.com/acmesh-official/acme.sh.git
    cd ./acme.sh
    ./acme.sh --install -m admin@serverok.in
    source ~/.bashrc

    When you install, it will set a daily cronjob for auto SSL renewal. You can see it with “crontab -l” command.

    Set acme.sh to use LetsEncrypt SSL (Defaul is ZeroSSL)

    acme.sh --set-default-ca --server letsencrypt

    Set to ZeroSSL, run

    acme.sh --set-default-ca --server zerossl

    To issue an SSL certificate, run

    acme.sh --issue -d example.com -d www.example.com -w /home/example.com/html/

    Standalone mode (nginx)

    acme.sh  --issue  -d example.com  --standalone --pre-hook "systemctl stop nginx" --post-hook "systemctl restart nginx"

    Using non-standard port

    acme.sh  --issue  -d example.com  --standalone --httpport 88

    For more ways to issue SSL certificates, see

    https://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

    Install SSL Certificate

    To install the SSL certificate, run

    acme.sh --install-cert -d DOMAIN_NAME \
    --fullchain-file /etc/ssl/DOMAIN_NAME.crt \
    --key-file /etc/ssl/DOMAIN_NAME.key \
    --reloadcmd "systemctl restart nginx"

    For Apache

    acme.sh --install-cert -d DOMAIN_NAME \
    --cert-file /etc/ssl/DOMAIN_NAME.crt \
    --key-file /etc/ssl/DOMAIN_NAME.key \
    --fullchain-file /etc/ssl/DOMAIN_NAME.ca \
    --reloadcmd "service apache2 force-reload"

    If you use Apache, replace “service nginx force-reload” with “service apache2 force-reload”. For CentOS/RHEL, use httpd instead of apache2.

    You can find how to enable SSL on Nginx server at Configure Nginx Server with SSL, For Apache web server, see Configure Apache Webserver with SSL

    See LetsEncrypt