Rescan SCSI bus

Sometimes when you add new storage to a running VM you won’t see it; the SCSI bus needs to be re-scanned to make the new disk visible.

echo "---" > /sys/class/scsi_host/hostX/scan

X is the number of the SCSI host to scan.
"---" tells the SCSI host to rescan all controllers, channels and LUNs.

To force a re-sync of the kernel for all the SCSI devices:

echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan

where 0:0:0:0 is the device you want to sync.

If you increased the size of an existing disk but you are not able to see the new disk size:

echo "1" > /sys/class/block/sdX/device/rescan

"1" is a flag that will trigger re-scan on the SCSI host.

NTP time drift

I had to update a couple of NTP servers and after rebooting Nagios was returning an alert on the check_ntp_peer check, indicating a time drift.

To fix it, I forced a clock update with NTP servers:

systemctl stop ntpd
ntpdate -s ntp1.inrim.it
systemctl start ntpd

httpd: (98)Address already in use

After configuring an Apache server on a CentOS 7.5 server, I tried to start the service but I got this error in return:

systemd[1]: Starting The Apache HTTP Server...
httpd[47662]: (98)Address already in use: AH00072: make_sock: could not bind to address [::]:443
systemd[1]: httpd.service: main process exited, code=exited, status=1/FAILURE

I was pretty sure that nothing was using port 443 but I did a quick check with netstat -tulpn

I double checked my config files, just to be sure that I wasn’t declaring Listen 443 twice:

# grep -ir listen
conf/httpd.conf:Listen 80
conf.d/ssl.conf:# When we also provide SSL we have to listen to the
conf.d/ssl.conf:Listen 443 https
conf.d/custom.conf:Listen 443

That’s it! I forgot to comment the directive in ssl.conf file (in this case). After this tiny fix I was able to start httpd without errors.

Nagios plugin: monitor a systemd service

Here’s a tiny plugin to check if a systemd service is running:

#!/bin/bash
#
# машины
# 
# Check a if a systemd service is running
# 
# Usage: $0 
#
#Nagios exit codes
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3

SERVICE=$1

# Check service status

systemctl -q is-active $SERVICE
if [[ $? -ne 0 ]]; then
    echo "ERROR: service $SERVICE is not running"
    exit $CRITICAL
fi

echo "OK: service $SERVICE is running"
exit $OK

Flushing iptables

You can flush and reset iptables to default running these commands:

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

The -F command flushes all the chains and -X deletes empty (non-default) chains.
You can also create a script:Continue reading

Using sudo without password

When you issue a sudo command you will be asked to type your password to execute it and this can be quite annoying, especially for people like me that open the terminal every 3 minutes and don’t want to login as root every time.

To solve this “problem” you need to edit sudo’s configuration file, located in /etc/sudoers, but it’s not recommended to do it directly. To modify this file, you have to use visudo that makes a temporary copy of the sudoers file and checks for errors before saving.Continue reading