How to set the Hostname on a Linux server with Terraform

If you need to set the hostname on a linux server, and you are using Terraform, then you can do the following: Include the provisioner block and set it to remote-exec: provisioner "remote-exec" { inline = ["sudo hostnamectl set-hostname"] }

May 22, 2023 · 1 min · 41 words · AO

How to Change a MariaDB/MySQL Data Directory to a New Location on Linux

Step 1 — Moving the MariaDB Data Directory mysql -u root -p select @@datadir; Output: +-----------------+ | @@datadir | +-----------------+ | /var/lib/mysql/ | +-----------------+ 1 row in set (0.00 sec) exit sudo systemctl stop mariadb sudo systemctl status mariadb Output: mysql systemd[1]: Stopped MariaDB database server. sudo rsync -av /var/lib/mysql /mnt/my-volume-01 sudo mv /var/lib/mysql /var/lib/mysql.bak Step 2 — Pointing to the New Data Location sudo vi /etc/my.cnf [mysqld] . . ....

March 7, 2023 · 1 min · 122 words · AO

How to update NTP to sync clock on Linux

If you need to sync the clock on Linux using the central NTP clock service, you can do the following: sudo service ntp stop sudo ntpd -gq sudo service ntp start The -gg flags do the following: Tell g flag tells the NTP Daemon to correct the time regardless of the offset The q flag tells it to exit immediately after setting the time

January 4, 2023 · 1 min · 64 words · Andrew

Understanding the Network Modes in AWS ECS

If using the EC2 launch type, the allowable network mode depends on the underlying EC2 instance’s operating system. If Linux, awsvpc, bridge, host and none mode can be used. If Windows, only the NAT mode is allowed. If using the Fargate launch type, the ‘awsvpc’ is the only network mode supported. Amazon ECS task networking The networking behavior of Amazon ECS tasks hosted on Amazon EC2 instances is dependent on the network mode defined in the task definition....

September 18, 2022 · 2 min · 311 words · Andrew

AppMesh and ECS with Imported ACM certificates on Envoy Sidecar through EFS

Summary This guide showcases the ability to use imported certificates from a third party provider (e.g. Venafi) in ACM, mount them in EFS and use them as trusted sources on Envoy sidecars with applications running in ECS. AppMesh is used as a passthrough with TLS termination occurring on the application container layer. Prerequisites and limitations Prerequisites A certificate that contains the chain of domains required for the fronted service and micro-services needed....

September 16, 2022 · 5 min · 1036 words · Andrew

How to Check if a Volume is Mounted in Bash

If you need to check if a volume is mounted in a Bash script, then you can do the following. How to Check Mounted Volumes First we need to determine the command that will be able to check. This can be done with the /proc/mounts path. How to Check if a Volume is Mounted in Bash if grep -qs '/mnt/foo ' /proc/mounts; then echo "It's mounted." else echo "It's not mounted....

August 12, 2022 · 1 min · 136 words · Andrew

How to Determine if a Bash Variable is Empty

If you need to check if a bash variable is empty, or unset, then you can use the following code: if [ -z "${VAR}" ]; The above code will check if a variable called VAR is set, or empty. What does this mean? Unset means that the variable has not been set. Empty means that the variable is set with an empty value of "". What is the inverse of -z?...

August 11, 2022 · 2 min · 287 words · Andrew

How to Order by File Size using the du command in Linux

If you use the du command to list all the file sizes on Linux: du # or du -h # Human readable Then you would have noticed that they are not ordered by file size. Instead you can pass that result to the sort command as follows: du -h | sort -h

August 10, 2022 · 1 min · 52 words · Andrew

How to Resize an AWS EBS Volume in Bash

If you need to resize an EBS volume in AWS, you can do so using bash. Step 1 – Create a bash file Create a bash file called #!/bin/bash SIZE=${1:-20} INSTANCEID=$(curl REGION=$(curl -s | sed 's/\(.*\)[a-z]/\1/') VOLUMEID=$(aws ec2 describe-instances \ --instance-id $INSTANCEID \ --query "Reservations[0].Instances[0].BlockDeviceMappings[0].Ebs.VolumeId" \ --output text \ --region $REGION) aws ec2 modify-volume --volume-id $VOLUMEID --size $SIZE while [ \ "$(aws ec2 describe-volumes-modifications \ --volume-id $VOLUMEID \ --filters Name=modification-state,Values="optimizing","completed" \ --query "length(VolumesModifications)"\ --output text)" !...

July 27, 2022 · 2 min · 272 words · Andrew

How to Count Files in Directory on Linux

If you need to count how many files are in a directory on Linux, then you can use a combination of the ls command to list all the files, and the wc command to count how many lines are printed: Option 1 – Using wc ls | wc -l You can specify a directory as follows: ls <directory> | wc -l Option 2 – Using find You can count files recursively by using the find command:...

July 20, 2022 · 1 min · 145 words · Andrew