Showing posts with label Server. Show all posts
Showing posts with label Server. Show all posts

Apr 15, 2025

Windows 10/11 : Batch File to Start and Check Windows Services

Create a batch file to check the status of a Windows Service(s) and start it if its not started. The batch file can also be run inside "Task Scheduler" at an interval basis.


1. First, you need to find out the Service Name that you want to monitor, in this example let's say the service you need to monitor is an Exchange Server IMAP4 service.


2. Open --> Services and browse through the list until you found the IMAP4 service.


3. Right-click the Service Name --> Properties.


4. Take note of the "Service name:", copy the name to Notepad. As per below screenshot, the service name is "MSExchangeImap4".



5. Create a batch file as below :-


@ECHO OFF
CLS
SETLOCAL ENABLEDELAYEDEXPANSION
SET /A RETRY_IMAP=0
SET /A MAX_RETRIES=3
SET EXCH_IMAP= MSExchangeImap4

REM To check current status of the service.
:check_imap
SC QUERY %EXCH_IMAP% | FIND "RUNNING" >NUL
IF %ERRORLEVEL%==0 (
    ECHO Exchange IMAP4 Service is Running.
        GOTO end
)

REM To start the service if the status is stopped.
ECHO Exchange IMAP4 Service is Stopped.
SC START %EXCH_IMAP%
TIMEOUT /T 10 >NUL

REM To re-check the service status again for confirmation.
SC QUERY %EXCH_IMAP% | FIND "RUNNING" >NUL
IF %ERRORLEVEL%==0 (
    ECHO Exchange IMAP4 Service is Running.
        GOTO end
)

REM Retrying to start the service with a maximum of 3 retries only.
SET /A RETRY_IMAP+=1
IF !RETRY_IMAP! LSS %MAX_RETRIES% (
    ECHO Retrying Start %EXCH_IMAP% (Attemp: !RETRY_IMAP!).
    GOTO check_imap
) ELSE (
    ECHO Max Retries Reached for %EXCH_IMAP%, will stop retrying.
        GOTO end
)

:end
EXIT



6. You can now test run the batch file and create a "Task Scheduler" to run the check at an interval basis (eg. every 2 hours or at Startup of the server).



!!! HAPPY COMPUTING !!!

Ubuntu : Nginx Proxy Manager (NPM)

Nginx Proxy Manager (NPM) is a user friendly, open source tool that simplifies the management of Nginx Reverse Proxy configurations. It have a Web UI for creating and managing Proxy Hosts, SSL Certificates and User Management and Permissions.

NPM makes managing services exposed to the Internet easily and securely. For easy installation and consistent environment, NPM runs on Docker.

Let's Get Started !

1. Install Docker's GPG Key.

sudo apt install ca-certificates curl gnupg -y


2. Modify the permission for "keyrings".

sudo install -m 0755 -d /etc/apt/keyrings


3. Download Docker's GPG Key.


sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc



4. Grant required permissions.

sudo chmod a+r /etc/apt/keyrings/docker.asc


5. Add Docker to the Repository.

echo \


"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \



$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \


sudo tee /etc/apt/sources.list.d/docker.list > /dev/null


6. Update the Repository.

sudo apt update


7. Install Docker.


sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y



8. Test Docker installation.

sudo docker run hello-world


9. Enable and Start Docker.

sudo systemctl enable docker

sudo systemctl start docker


10. Add "docker" to User group.

sudo usermod -aG docker $USER


11. Install Docker Compose.


sudo curl -SL https://github.com/docker/compose/releases/download/v2.34.0/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose



12. Modify Docker Compose Permission.

sudo chmod +x /usr/local/bin/docker-compose


13. Test the Docker Compose.

sudo docker-compose


14. Create a installation folder for Nginx Proxy Manager.

sudo mkdir ~/nginx-proxy


15. Change directory into the newly created folder.

cd ~/nginx-proxy


16. Create sub-folders inside "nginx-proxy" folder.

sudo mkdir {data,letsencrypt}


17. Create Docker Compose file inside "nginx-proxy" folder.

sudo nano docker-compose.yml


18. Copy and Paste the following codes into the file. You might want to check for the latest configuration at (https://nginxproxymanager.com/setup/#using-mysql-mariadb-database)


services:
    app:
        image: 'jc21/nginx-proxy-manager:latest'
        restart: unless-stopped
        ports:
            # These ports are in format <host-port>:<container-port>
            - '80:80' # Public HTTP Port
            - '443:443' # Public HTTPS Port
            - '81:81' # Admin Web Port
            # Add any other Stream port you want to expose
            # - '21:21' # FTP
        environment:
            # Mysql/Maria connection parameters:
            DB_MYSQL_HOST: "db"
            DB_MYSQL_PORT: 3306
            DB_MYSQL_USER: "npm"
            DB_MYSQL_PASSWORD: "npm"
            DB_MYSQL_NAME: "npm"
            # Uncomment this if IPv6 is not enabled on your host
            # DISABLE_IPV6: 'true'
        volumes:
            - ./data:/data
            - ./letsencrypt:/etc/letsencrypt
        depends_on:
            - db

    db:
        image: 'jc21/mariadb-aria:latest'
        restart: unless-stopped
        environment:
            MYSQL_ROOT_PASSWORD: 'npm'
            MYSQL_DATABASE: 'npm'
            MYSQL_USER: 'npm'
            MYSQL_PASSWORD: 'npm'
            MARIADB_AUTO_UPGRADE: '1'
        volumes:
            - ./mysql:/var/lib/mysql



19. Create Docker Network for Nginx Proxy Manager.

sudo docker network create npm-nw


20. Start Nginx Proxy Manager.

sudo docker-compose up -d


21. Check the Docker Status.

sudo docker ps


22. Open favorite browser (eg. Google Chrome) and browse the following address. You should be able to see a Nginx Proxy Manager Welcome Page.

http://[IP Address]


23. Now login to Nginx Proxy Manager Admin Web UI, please note the port number is 81.

http://[IP Address]:81


24. Login with the default Username and Password as below.


Default Username    : admin@example.com

Default Password    : changeme



25. After successfully login, you will be prompted to change the Username and Password, please proceed to change it accordingly and remember the new Username and Password.



!!! HAPPY COMPUTING !!!

Nov 27, 2024

AntMedia Server : Install and Configure in Ubuntu Server

AntMedia Server (AMS) is an Open-Source, Self-Hosted Video Streaming Platform. It supports steaming of pre-recorded videos to supported website such as Youtube, Twitch, HTML etc.

For more information, visit their official website at (https://antmedia.io/)


1. Ensure that you already have Ubuntu installed and updated with the latest packages. Also you need to have Apache2 web server pre-installed, up and running.


2. First, download the latest version of AntMedia Server Community Edition.


sudo wget https://github.com/ant-media/Ant-Media-Server/releases/download/ams-v2.11.3/ant-media-server-community-2.11.3.zip



3. Next is to download Installer Script file from AntMedia.


sudo wget -O install_ant-media-server.sh https://raw.githubusercontent.com/ant-media/Scripts/master/install_ant-media-server.sh



4. Now change the installer file to executable format.

sudo chmod +x install_ant-media-server.sh


5. To install the Community Edition, run the following command.

sudo ./install_ant-media-server.sh -i ant-media-server-community-2.11.3.zip


6. Configure the Apache Web Server.

sudo nano /etc/apache/sites-available/[domain.com].conf

Add the following configuration


<VirtualHost *:80>
   ServerAdmin webmaster@localhost
   ServerName [domain.com]

   ErrorLog /var/log/apache2/[domain.com]/error.log
   CustomLog /var/log/apache2/[domain.com]/access.log

   ProxyRequest off
   ProxyPass / http://127.0.0.1:5080/
   ProxyPassReverse / http://127.0.0.1:5080/

</VirtualHost>



7. Enable Apache modules accordingly.

sudo a2enmod proxy proxy_http


8. Enable the new virtual site.

sudo a2ensite [domain.com].conf


9. Enable SSL for AntMedia Server.

cd /usr/local/antmedia

sudo ./enable_ssl.sh -d [domain.com]


10. Ensure the following ports is accessible to the server.

Port Number

Protocol

Descriptions

80

TCP

SSL

5080

TCP

HTTP

5443

TCP

HTTPS

4200

UDP

SRT

1935

TCP

RTMP

50000 - 60000

UDP

WebRTC

5000

TCP

Multi-Nodes Cluster (optional)



11. Restart Apache Server.

sudo systemctl restart apache2


12. Open your favorite browser (eg. Google Chrome), browse the following URL.

http://[domain.com]:5080


13. Once the page have been loaded, you will be prompted to create the first administrator account. Procced to create the admin account and login afterward.


Added tutorial video.





!!! HAPPY COMPUTING !!!

Nov 21, 2024

Proxmox Backup Server (PBS) : Setup No Subscription Repository

For the Proxmox Backup Server (PBS), to use it as a Community Edition. We need to setup the "No Subscriptions" repository.

This methods is only for Hobbyist, Developer and alike, not recommended for Production environment.


1. Login to PBS WebUI and select "Console", then type the following command.

nano /etc/apt/sources.list.d/pve-enterprise.list


2. Comment out the Enterprise Repository by adding a "#" sign at the front.


3. Then add the following line for the No Subscription Repository.

deb http://download.proxmox.com/debian/pbs bookworm pbs-no-subscription

* The "bookworm" is the debian release code name and may change, thus change the name accordingly.


4. Next, is to run the Update.

apt update && apt upgrade -y


5. Finally, restart the server.

reboot



!!! HAPPY COMPUTING !!!

Nov 18, 2024

NextCloud Install in Ubuntu Server

NextCloud is an Open Source, Self-Hosted or Cloud Hosted, File Sync and Sharing Platform. It's Secure, Private and Easy to use. Compatible with Windows, Linux, Android and Apple iOS devices.

This is assuming that you already have Ubuntu Server installed, patched and updated.

1. Download the latest version of NextCloud.

sudo wget https://download.nextcloud.com/server/releases/latest.zip


2. Install some required packages.


sudo apt install libmagickcore-6.q16-6-extra php php-apcu php-bcmath php-cli php-common php-curl php-gd php-gmp php-imagick php-intl php-mbstring php-mysql php-zip php-xml -y



3. Install Marid DB Server.

sudo apt install mariadb-server -y


4. Secure Marid DB installation, follow on-screen prompt and instructions.

sudo mysql_secure_installation


5. Configure Maria DB Server.


CREATE DATABASE nextcloud;

SHOW DATABASES;

GRANT ALL PRIVILEGES ON nextcloud.* TO 'ncuser'@'localhost' IDENTIFIED BY 'ncpass';

FLUSH PRIVILEGES;

QUIT;



6. Enable PHP Modules.

sudo phpenmod apcu bcmath gmp imagick intl


7. Install Unzip Apps.

sudo apt install unzip -y


8. Unzip the downloaded NextCloud file.

sudo unzip latest.zip


9. Copy and Rename the extracted NextCloud folder.

sudo cp nextcloud demo.com


10. Move the renamed folder to Apache server path.

sudo mv demo.com /var/www/


11. Grant permissions to NextCloud folder.

sudo chwon -R www-data:www-data /var/www/demo.com


12. Create Apache configuration file for NextCloud.


<VirtualHost *:80>
   ServerAdmin webmaster@local.com
   ServerName demo.com
   DocumentRoot /var/www/demo.com

   <Directory /var/www/demo.com>
     Options MultiViews FollowSymlinks
     AllowOverride All
     Order allow,deny
     Allow from all
   </Directory>

   ErrorLog /var/log/apache2/demo.com/error.log
   TransferLog /var/log/apache2/demo.com/access.log

  <IfModule mod_headers.c>
     Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
   </IfModule>

</VirtualHost>



13. Configure and modify PHP file. Modify the value according to your requirements.


memory_limit = 512M

upload_max_filesize = 512M

max_execution_time = 360

post_max_size = 512M

date.timezone = Asia/Kuala_Lumpur

opcache.enable = 1

opcache.interned_strings_buffer = 16

opcache.max_accelerated_files = 10000

opcache.memory_consumption = 128

opcache.save_comments = 1

opcache.revalidate_freq = 1



14. Enabled Apache modules for NextCloud use.

sudo a2enmod dir env headers mime rewrite ssl


15. Enable APCU module in PHP.

sudo nano /etc/php/8.3/mods-available/apcu.ini

add the following line :-

apc.enable_cli = 1


16. Open your favorite browser, such as Google Chrome browser. And type the URL of NextCloud server (eg. http://demo.com). At the main screen, you need to configure the NextCloud Database (eg. nextcloud) created earlier including its username (eg. ncuser) & password (eg. ncpass). You also need to create the First Administrator account with a valid email address too.


17. NextCloud screen will auto refresh upon successful connection to the database, now login with the new administrator account created in earlier step.


18. Secure NextCloud with Let's Encrypt SSL.

sudo certbot --apache


19. Fix missing Indices in NextCloud.

sudo chmod +x /var/www/demo.com/occ

sudo /var/www/demo.com/occ db:add-missing-indices

sudo chmod -x /var/www/demo.com/occ


20. Change permissions of NextCloud config file.

sudo chmod 660 /var/www/demo.com/config/config.php

sudo chown root:www-data /var/www/demo.com/config/config.php


21. Modify NextCloud configuration file.

sudo nano /var/www/demo.com/config/config.php

Modify the following lines according to you needs :-


'memcache.local' => '\OC\Memcache\APCu',

'default_phone_region' => 'MY',

'maintenance_window_start' => 1,

'filelocking.enabled' => true,

'memcache.locking' => '\OC\MemCache\APCu',



22. Restart Apache server.

sudo systemctl restart apache2


23. Configure Crontab.

sudo crontab -u www-data -e

Add the following line :-

00 * * * 1 php -f /var/www/demo.com/cron.php



OPTIONAL STEPS

24. Remove Skeleton Files and Folders when User account is created.

sudo rm -R /var/www/demo.com/core/skeleton/Templates


25. Remove Work Flow Engine, to prevent User from installing WorkFlow.


sudo /var/www/demo.com/occ config:app:set workflowengine user_scope_disabled --value yes



26. Install "Redis" as MemCache for NextCloud.

sudo apt install redis php-redis -y

sudo systemctl enable redis

sudo systemctl start redis

sudo nano /var/www/demo.com/config/config.php


'memcache.local' => '\OC\Memcache\Redis',

'memcache.locking' => '\OC\Memcache\Redis',

'redis' => array(
     'host' => '/var/run/redis/redis.sock'.
     'port' => 0,
     'timemout' => 0.0,
     ),


sudo nano /etc/redis/redis.conf


unixsocket /var/run/redis/redis.sock

unixsocketperm 660


sudo usermod -aG redis www-data

sudo systemctl restart redis


27. If Redis is distributed, add following line into NextCloud config file :-

'memcache.distributed' => '\OC\Memcache\MemCached',


28. To clear all NextCloud log entries.

sudo -u www-data truncate /var/www/demo.com/data/nextcloud.log --size=0



!!! HAPPY COMPUTING !!!


Jul 29, 2024

Ubuntu : Install Samba Server

How to install Samba Server in Ubuntu Server v.22.04.4

1. As usual, update Ubuntu's repositories.

sudo apt update && sudo apt upgrade -y


2. Install the Samba server.

sudo apt install samba -y


3. To verify the Samba installation.

sudo whereis samba

OR

sudo samba -v

OR

sudo systemctl status smbd


4. Make a backup of Samba's configuration file.

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak


5. Edit the Samba's configuration file.

sudo nano /etc/samba/smb.conf


6. Browse to the end of the file and add in the following configurations.

[global]
   server string = [Hostname]

[samba_share]
   comment = Samba Shared Folder
   path = /mnt/samba_share
   browsable = yes
   writable = yes
   read only = no
   guest ok = no
   valid users = [Samba Username]




7. Assign the proper permissions to the shared folder.

sudo chmod -R 755 /mnt/samba_share


8. Create a new Samba user.

sudo smbpasswd -a [Username]
*Note : you will be prompted to key-in the user's password.


9. Enable the created User for Samba access.

sudo smbpasswd -e [Username]


10. Test the Samba configuration.

sudo testparm


11. Restart Samba service for the new configurations.

sudo systemctl restart smbd


12. Test the Samba connections using another computer and with the credentials created.


!!! HAPPY COMPUTING !!!

Jun 27, 2024

Proxmox : PCIe Passthrough

How to passthrough a PCIe or On-Board device/controller in Proxmox VE v.8.2.4.

At times you might want to passthrough certain devices or controller to a VM Guest for full access and control. This can be a GPU, RAID Controller, NIC etc. This is very useful in scenario such as testing a NAS (TrueNAS).

Pre-requisites :-

1. System CPU must support IOMMU (I/O Memory Management Unit) interrupt remapping. Usually this is called Intel VT-d or AMD-Vi or similar names. Most newer Mainboard and CPU already have such features.

2. This passthrough methods means the entire device or controller is no longer in use by Proxmox VE itself and only manage by the VM Guest. This means you cannot passthrough a controller where the "Boot-Pool" is connected. It must be a separate controller or device.


Scenario :-

My test system or home lab system is a HP Z800 WorkStation series with the following hardware configurations, if your system is newer than mine then most probably it will works too :-

  • Dual Intel Xeon X5660 2.80Ghz, 6-Cores, 12-Threads, 12MB-Cache.
  • 96GB DDR3 1333Mhz ECC RAM.
  • Intel 5520 Chipset.
  • On-board Intel Matrix 6-ports SATA/RAID Controller.
  • On-board LSI 1068E 8-ports SAS/SATA Controller.
  • LSI 9212-4i SAS/SATA 4-ports PCIe Controller.

The "LSI 9212-4i SAS/SATA 4-ports PCIe Controller" is where Proxmox VE is installed, thus I cannot passthrough this controller.


Let's Get Started :-

1. Login to the Proxmox VE's WebUI.


2. Select the Node, in this case I have only a single node.


3. Open --> Shell


4. Verify that your system have IOMMU enabled.

 dmesg | grep -e DMAR -e IOMMU -e AMD-Vi

The results should shows "DMAR: IOMMU enabled" OR "DMAR: Intel(R) Virtualization Technology for Directed I/O". If either of these is missing then you need to check your BIOS/UEFI whether those virtualization technology are enabled.


5. Edit the "Kernel" file.

nano /etc/kernel/cmdline

Add the following line to the file.

root=ZFS=rpool/ROOT/pve-1 boot=zfs intel_iommu=on

If your CPU is and AMD type, then add "amd_iommu=on" to it.


6. Next is to edit the "Modules" file.

nano /etc/modules

Add the following into the file.

vfio
vfio_iommu_type1
vfio_pci
vfio_virqfd


7. Now we also need to edit the "GRUB" file.

nano /etc/default/grub

Look for the following line and append the line as shown.

GRUB_CMDLINE_LINUX_DEFAULT="quiet intel_iommu=on"

If your CPU is and AMD type, then add "amd_iommu=on" to it.


8. Once all done, we need to refresh the "Proxmox" boot.

proxmox-boot-tool refresh


9. Update the "initfamfs" also.

update-initramfs -u -k all


10. Next is to update "GRUB" also.

update-grub


11. Finally, we need to REBOOT the Proxmox VE host server.


12. After reboot, verify the "IOMMU" configuration.

dmesg | grep -e DMAR -e IOMMU -e AMD-Vi

Results :-
DMAR: IOMMU enabled OR DMAR: Intel(R) Virtualization Technology for Directed I/O


13. Verify "vfio" configuration.

lsmod | grep vfio

Results :-
vfio_pci          49152    0
vfio_virqfd          16384    1 vfio_pci
irqbypass                  16384    2 vfio_pci,kvm
vfio_iommu_type1   32768    0
vfio                           32768    2 vfio_iommu_type1,vfio_pci


14. Verify "Interrupt Remapping" configuration.

dmesg | grep 'remapping'

Results :-
AMD-Vi: Interrupt remapping enabled OR DMAR-IR: Enabled IRQ remapping in 2xapic mode (only for older CPU model)

If you encounter an error message on the remapping interrupts, type the following command and reboot the Proxmox server again.

echo "options vfio_iommu_type1 allow_unsafe_interrupts=1" > /etc/modprobe.d/iommu_unsafe_interrupts.conf



15. Now you can create a VM and passthrough a PCIe device to that VM. Take note you need to ensure the "Machine = q35" else it will not work.

Also note that the device must not be in the same IOMMU Group, if the device is in the same group of another device then high chances it will not work or the entire group will also be passthrough to the VM.


For more information :-
!!! HAPPY COMPUTING !!!


Mar 11, 2024

Ubuntu : Install Piwigo Server

Piwigo is an Open Source Photo Management Server, it allows you to self-host your very own photo management, organizing and share your photo easily on the web.

More information about Piwigo can be found at (https://piwigo.org)

Let's get started.....


1. As always, ensure that your Ubuntu Server is up-to-date.

sudo apt update && sudo apt upgrade -y


2. Next is to install the Web Server, Database Server and some utilities.

sudo apt install apache2 libapache2-mod-php mariadb-server unzip curl imagemagick -y


3. We also need to install the following dependencies.

sudo apt install php php-common php-intl php-mysql php-gd php-xml php-ldap php-zip php-mbstring php-xmlrpc php-cli php-curl -y


4. After installation completed, we need to modify the PHP Configurations.

sudo nano /etc/php/8.1/apache2/php.ini

Inside the "php.ini" configuration file, look for the following settings and modify it accordingly.

memory_limit = 256M

upload_max_filesize = 200M

post_max_size = 200M



5. Then restart the Apache2 Server.

sudo systemctl restart apache2


6. Now, we need to create the Database for Piwigo to work, just press [ENTER] key when prompted for password.

sudo mysql -u root -p

Follow the below to create the database.

CREATE DATABASE piwigo_db;

CREATE USER 'piwigo_user'@'localhost' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON piwigo_db.* TO 'piwigo_user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

FLUSH PRIVILEGES;

QUIT;



7. Download the latest Piwigo version.

sudo curl -o piwigo.zip https://piwigo.org/download/dlcounter.php?code=latest


8, After download complete, extract the zip file to the web server.

sudo unzip piwigo.zip -d /var/www/html


9. Next is allow the appropriate credentials for the Piwigo folder.

sudo chown -R www-data:www-data /var/www/html/piwigo/

sudo chomod -R 755 /var/www/html/piwigo/


10. Next is to create the Apache configuration file.

sudo nano /etc/apache2/sites-available/piwigo.conf

Create the configuration file as per below.

<VirtualHost *:80>
   ServerAdmin webmaster@localhost
   ServerName piwigo.localhost
   DocumentRoot /var/www/html/piwigo
   ErrorLog ${APACHE_LOG_DIR}/error.log
   CustomLog ${APACHE_LOG_DIR}/access.log combined

   <Directory /var/www/html/piwigo/>
       Options FollowSymlinks
       AllowOverride All
       Require all granted
   <\Directory>
<\VirtualHost>


11. Then we need to enable the newly created site.

sudo a2ensite piwigo.conf


12. We also need to enable Apache module as below.

sudo a2enmod rewrite


13. Finally we need to restart Apache Server.

sudo systemctl restart apache2


14. Once done, open any preferred browser and browse to Piwigo site.

http://[IP Address]/piwigo


15. You will need to perform initial configurations of piwigo, enter all the relevant information as required. This includes the Database Name and Credentials, also you will need to create an administrator user (to manage the Piwigo) which are not "Root".


16. Once everything are successfully configured, you will be able to login to the Piwigo site and you can start to create your first album and start uploading photos.

Note : It is recommended to install a Plugin called "Community" which allows your "Users" to create their own albums and upload photos.





!!! HAPPY COMPUTING !!!