Show Network Errors with netstat

netstat command is a mightly utility found in majority of Unix and Linux distributions.

Among other things like showing network routes and reporting network connections and ports, netstat can also report if your network interfaces have any trouble sending or receiving packets.

Report network errors with netstat

The basic format for this functionality is shown below:

greys@s5:~ $ netstat -ni

Screen Shot 2019-01-31 at 17.38.31.png

IMPORANT: always double-check the interface name you’re checking. I have highlighted the physical interface in my example, because it’s important: your virtual interfaces are unlikely to provide any useful network reliability info – so you always must be checking the primary, physical interfaces (or primary, virtual ones if you’re looking at a VM).

No errors in RX-ERR (receive errors) or TX-ERR (send errors), which is pretty impressive for a dedicated server that’s been online for a year:

greys@s5:~ $ uptime
17:34:30 up 366 days, 2:39, 1 user, load average: 0.11, 0.14, 0.19

See Also




yum: List and Install Software Groups

yum-group-list.jpg

yum package manager, and dnf package manager in later Red Hat Linux versions, is quite a capable tool. In addition to expertly resolving dependencies when installing and removing individual software packages (RPMs), yum can also be used to manage whole package groups.

List software groups with yum

Here’s how to get a list of available software groups and also get an indication of which groups you already have installed in your RHEL:

[root@rhel8 ~]# yum group list
Updating Subscription Management repositories.
Updating Subscription Management repositories.
Last metadata expiration check: 0:02:40 ago on Tue 29 Jan 2019 18:38:39 EST.
Available Environment Groups:
Custom Operating System
Server
Installed Environment Groups:
Minimal Install
Workstation
Available Groups:
.NET Core Development
RPM Development Tools
Container Management
Smart Card Support
Scientific Support
Security Tools
Development Tools
System Tools
Headless Management
Network Servers
Legacy UNIX Compatibility
Graphical Administration Tools

Install a software group with yum

Simply using the entries from the list in previous section, you can install software groups like shown below.

IMPORTANT: because these are descriptive names and they have multiple words in mostt group’s names, you must use quotes:

[root@rhel8 ~]# yum group install "Development Tools"
Updating Subscription Management repositories.
Updating Subscription Management repositories.
Last metadata expiration check: 0:02:59 ago on Tue 29 Jan 2019 18:38:39 EST.
Dependencies resolved
===========================================================
Package Arch Version Repository Size
===========================================================
Installing group/module packages:
source-highlight x86_64 3.1.8-16.el8 rhel-8-for-x86_64-appstream-beta-rpms 657 k
autoconf noarch 2.69-27.el8 rhel-8-for-x86_64-appstream-beta-rpms 710 k
perl-Fedora-VSP noarch 0.001-9.el8 rhel-8-for-x86_64-appstream-beta-rpms 25 k
patchutils x86_64 0.3.4-10.el8 rhel-8-for-x86_64-appstream-beta-rpms 115 k
libtool x86_64 2.4.6-25.el8 rhel-8-for-x86_64-appstream-beta-rpms 709 k
bison x86_64 3.0.4-10.el8 rhel-8-for-x86_64-appstream-beta-rpms 688 k
flex x86_64 2.6.1-9.el8 rhel-8-for-x86_64-appstream-beta-rpms 320 k
valgrind x86_64 1:3.14.0-1.el8 rhel-8-for-x86_64-appstream-beta-rpms 11 M
pesign x86_64 0.112-25.el8 rhel-8-for-x86_64-appstream-beta-rpms 181 k
gdb x86_64 8.2-3.el8 rhel-8-for-x86_64-appstream-beta-rpms 296 k
ctags x86_64 5.8-22.el8 rhel-8-for-x86_64-appstream-beta-rpms 170 k
ltrace x86_64 0.7.91-27.el8 rhel-8-for-x86_64-appstream-beta-rpms 160 k
systemtap x86_64 4.0-0.20180830git.el8 rhel-8-for-x86_64-appstream-beta-rpms 17 k
perl-generators noarch 1.10-7.el8 rhel-8-for-x86_64-appstream-beta-rpms 18 k
byacc x86_64 1.9.20170709-4.el8 rhel-8-for-x86_64-appstream-beta-rpms 91 k
rpm-build x86_64 4.14.2-4.el8 rhel-8-for-x86_64-appstream-beta-rpms 166 k
asciidoc noarch 8.6.10-0.5.20180627gitf7c2274.el8 rhel-8-for-x86_64-appstream-beta-rpms 216 k
automake noarch 1.16.1-6.el8 rhel-8-for-x86_64-appstream-beta-rpms 713 k
intltool noarch 0.51.0-11.el8 rhel-8-for-x86_64-appstream-beta-rpms 66 k
diffstat x86_64 1.61-7.el8 rhel-8-for-x86_64-appstream-beta-rpms 44 k
make x86_64 1:4.2.1-9.el8 rhel-8-for-x86_64-baseos-beta-rpms 498 k
rpm-sign x86_64 4.14.2-4.el8 rhel-8-for-x86_64-baseos-beta-rpms 74 k
Installing dependencies:
perl-Thread-Queue noarch 3.13-1.el8 rhel-8-for-x86_64-appstream-beta-rpms 24 k
docbook-style-xsl noarch 1.79.2-7.el8 rhel-8-for-x86_64-appstream-beta-rpms 1.6 M
libXaw x86_64 1.0.13-10.el8 rhel-8-for-x86_64-appstream-beta-rpms 194 k
dyninst x86_64 9.3.2-12.el8 rhel-8-for-x86_64-appstream-beta-rpms 3.7 M
gdb-headless x86_64 8.2-3.el8 rhel-8-for-x86_64-appstream-beta-rpms 3.7 M
guile x86_64 5:2.0.14-7.el8 rhel-8-for-x86_64-appstream-beta-rpms 3.5 M
graphviz x86_64 2.40.1-37.el8 rhel-8-for-x86_64-appstream-beta-rpms 1.7 M
systemtap-runtime x86_64 4.0-0.20180830git.el8 rhel-8-for-x86_64-appstream-beta-rpms 461 k
libipt x86_64 1.6.1-8.el8 rhel-8-for-x86_64-appstream-beta-rpms 50 k
perl-XML-Parser x86_64 2.44-10.el8 rhel-8-for-x86_64-appstream-beta-rpms 226 k
libdwarf x86_64 20180129-4.el8 rhel-8-for-x86_64-appstream-beta-rpms 172 k
systemtap-devel x86_64 4.0-0.20180830git.el8 rhel-8-for-x86_64-appstream-beta-rpms 2.1 M
systemtap-client x86_64 4.0-0.20180830git.el8 rhel-8-for-x86_64-appstream-beta-rpms 3.5 M
libatomic_ops x86_64 7.6.2-3.el8 rhel-8-for-x86_64-appstream-beta-rpms 38 k
docbook-dtds noarch 1.0-69.el8 rhel-8-for-x86_64-appstream-beta-rpms 377 k
nss-tools x86_64 3.39.0-1.0.el8 rhel-8-for-x86_64-appstream-beta-rpms 558 k
libbabeltrace x86_64 1.5.4-2.el8 rhel-8-for-x86_64-appstream-beta-rpms 201 k
gc x86_64 7.6.4-3.el8 rhel-8-for-x86_64-appstream-beta-rpms 109 k
xorg-x11-fonts-ISO8859-1-100dpi noarch 7.5-19.el8 rhel-8-for-x86_64-appstream-beta-rpms 1.1 M
elfutils x86_64 0.174-1.el8 rhel-8-for-x86_64-baseos-beta-rpms 340 k
patch x86_64 2.7.6-7.el8 rhel-8-for-x86_64-baseos-beta-rpms 138 k
m4 x86_64 1.4.18-7.el8 rhel-8-for-x86_64-baseos-beta-rpms 223 k
sgml-common noarch 0.6.3-50.el8 rhel-8-for-x86_64-baseos-beta-rpms 62 k
kernel-debug-devel x86_64 4.18.0-32.el8 rhel-8-for-x86_64-baseos-beta-rpms 12 M
gettext-devel x86_64 0.19.8.1-14.el8 rhel-8-for-x86_64-baseos-beta-rpms 331 k
gettext-common-devel noarch 0.19.8.1-14.el8 rhel-8-for-x86_64-baseos-beta-rpms 419 k
mokutil x86_64 1:0.3.0-9.el8 rhel-8-for-x86_64-baseos-beta-rpms 44 k
Installing weak dependencies:
gcc-gdb-plugin x86_64 8.2.1-3.3.el8 rhel-8-for-x86_64-appstream-beta-rpms 115 k

Transaction Summary
===========================================================
Install 50 Packages

Total download size: 53 M
Installed size: 193 M
Is this ok [y/N]:

That’s it for today! Will show you a few more really cool tricks with yum some other time.

See Also

 




List RHEL subscriptions

Screen Shot 2019-01-28 at 22.45.00.pngIf you’re lucky to be working with a recent enough version of Red Hat Enterprise Linux (RHEL) – namely, anything after RHEL 5.7 and RHEL 6.1, then you should know what software subscriptions are and how to list them.

List active subscriptions in Red Hat

subscription-manager is a Linux command in RHEL, you run it with the list option to show what current subscriptions are active for your server.

Here’s how this looks on my recently build RHEL8 beta virtual machine:

[root@rhel8 ~]# subscription-manager list
+-------------------------------------------+
Installed Product Status
+-------------------------------------------+
Product Name: Red Hat Enterprise Linux for x86_64 Beta
Product ID: 486
Version: 8.0 Beta
Arch: x86_64
Status: Subscribed
Status Details:
Starts: 23/11/18
Ends: 22/11/19

If you attempt running the same command as a regular user, you’ll probably need to authenticate (tell the root password) first:

[greys@rhel8 ~]$ subscription-manager list
You are attempting to run "subscription-manager" which requires administrative
privileges, but more information is needed in order to do so.
Authenticating as "root"
Password:
...

List all the available subscriptions in Red Hat

It may well be that you have multiple subsriptions available as part of your setup – for instance, you might have additional software installed that is maintained and supported by Red Hat, but uses separate subscription channel instead of being supplied with the default OS one.

You can use the same subscription-manager command to list all the available subscriptions:

[root@rhel8 ~]# subscription-manager list --available
+-------------------------------------------+
Available Subscriptions
+-------------------------------------------+
Subscription Name: Red Hat Developer Subscription
Provides: dotNET on RHEL Beta (for RHEL Server)
Red Hat Enterprise Linux for SAP
Red Hat Enterprise Linux Resilient Storage (for RHEL Server)
Red Hat Ansible Engine
RHEL for SAP HANA - Update Services for SAP Solutions
Red Hat Enterprise Linux Scalable File System (for RHEL Server) - Extended Update Support
RHEL for SAP HANA - Extended Update Support
Red Hat Container Images Beta
Red Hat Enterprise Linux Atomic Host Beta
Red Hat Container Images
Red Hat Enterprise Linux High Availability (for RHEL Server) - Extended Update Support
Red Hat Enterprise Linux Load Balancer (for RHEL Server)
Red Hat Container Development Kit
Red Hat Beta
Red Hat EUCJP Support (for RHEL Server) - Extended Update Support
RHEL for SAP (for IBM Power LE) - Update Services for SAP Solutions
MRG Realtime
Red Hat Enterprise Linux Load Balancer (for RHEL Server) - Extended Update Support
dotNET on RHEL (for RHEL Server)
Red Hat Enterprise Linux High Availability - Update Services for SAP Solutions
Oracle Java (for RHEL Server)
Red Hat Enterprise Linux Server - Update Services for SAP Solutions
Red Hat Software Collections (for RHEL Server)
Red Hat Enterprise Linux for ARM 64
Red Hat Enterprise Linux High Availability (for RHEL Server)
Red Hat Enterprise Linux High Performance Networking (for RHEL Server)
Red Hat Enterprise Linux Scalable File System (for RHEL Server)
Red Hat Enterprise Linux for Real Time
Red Hat Enterprise Linux High Performance Networking (for RHEL Server) - Extended Update Support
RHEL for SAP - Update Services for SAP Solutions
Oracle Java (for RHEL Server) - Extended Update Support
Red Hat Enterprise Linux Atomic Host
Red Hat Enterprise Linux Server - Extended Update Support
Red Hat Developer Tools (for RHEL Server)
Red Hat Software Collections Beta (for RHEL Server)
Red Hat Enterprise Linux Server
Red Hat Developer Tools Beta (for RHEL Server)
RHEL for SAP - Extended Update Support
Red Hat Developer Toolset (for RHEL Server)
Red Hat Enterprise Linux High Performance Networking (for RHEL Compute Node)
Red Hat Enterprise Linux Resilient Storage (for RHEL Server) - Extended Update Support
Red Hat Enterprise Linux for SAP Hana
Red Hat S-JIS Support (for RHEL Server) - Extended Update Support
SKU: RH00798
Contract:
Pool ID: 8a85f99a65c8c8a1016698f9e87423fe
Provides Management: No
Available: 16
Suggested: 1
Service Level: Self-Support
Service Type:
Subscription Type: Standard
Starts: 21/10/18
Ends: 21/10/19
System Type: Physical

Pretty impressive, isn’t it? Can’t wait to try some of these out, Red Hat Developer Tools, Red Hat Container Images and Red Hat Enterprise Linux High Availability all sound fun!

See Also




SElinux: Advanced sestatus usage

I learned something new today! Apparently, sestatus command can report security contexts of the key system files – really neat for quickly recognising possible security compromise.

Files and processes in /etc/sestatus.conf

The way this works is you must use the /etc/sestatus.conf file which contains list of files and list of processes that are checked for SElinux contexts. These are the most common security attack vectors, so SElinux notes them and helps you to quickly confirm their contexts using sestatus -v command.

VERY IMPORTANT: at this stage sestatus command does NOT highlight or warn you about any non-standard contextual changes. So the only thing is does is show you all the important files you selected and report their current contexts – if some of these have been changed, the task of recognising or fixing this is still on you.

You can add any files and process you like here, but here’s the default list in RHEL8:

[greys@rhel8 ~]$ cat /etc/sestatus.conf
[files]
/etc/passwd
/etc/shadow
/bin/bash
/bin/login
/bin/sh
/sbin/agetty
/sbin/init
/sbin/mingetty
/usr/sbin/sshd
/lib/libc.so.6
/lib/ld-linux.so.2
/lib/ld.so.1

[process]
/sbin/mingetty
/sbin/agetty
/usr/sbin/sshd

Files and processes contexts with sestatus

[greys@rhel8 ~]$ sestatus -v
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux.png
SELinux root directory: /etc/selinux.png
Loaded policy name: targeted
Current mode: enforcing
Mode from config file: enforcing
Policy MLS status: enabled
Policy deny_unknown status: allowed
Memory protection checking: actual (secure)
Max kernel policy version: 31

Process contexts:
Current context: unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
Init context: system_u:system_r:init_t:s0

File contexts:
Controlling terminal: unconfined_u:object_r:user_devpts_t:s0
/etc/passwd system_u:object_r:passwd_file_t:s0
/etc/shadow system_u:object_r:shadow_t:s0
/bin/bash system_u:object_r:shell_exec_t:s0
/bin/login system_u:object_r:login_exec_t:s0
/bin/sh system_u:object_r:bin_t:s0 -> system_u:object_r:shell_exec_t:s0
/sbin/agetty system_u:object_r:getty_exec_t:s0
/sbin/init system_u:object_r:bin_t:s0 -> system_u:object_r:init_exec_t:s0
/usr/sbin/sshd system_u:object_r:sshd_exec_t:s0

See Also




Unix Diff

unix diff.jpgdiff is a mightly command line tool found in most of Unix and Unix-like operating systems. diff helps you to find differences between files and directories.

Things You Can Do with Unix Diff

How To Use Unix Diff

In its simplest form, compares two text files – you provide their names as command line options.

Let’s create two files first:

greys@maverick:~ $ touch try
greys@maverick:~ $ touch try2

Diff won’t show any difference because they’re exactly the same – empty new files:

greys@maverick:~ $ diff try try2

If we change one of the files by adding the hello word to it, see what happens:

greys@maverick:~ $ echo "hello" >> try2
greys@maverick:~ $ diff try try2
0a1
> hello

Diff spotted the difference and indicated, which file has it (> means second file, the file in the right section of the command line).

Now, let’s add something else to the first file to make things a bit more interesting:

greys@maverick:~ $ echo "hi" >> try
greys@maverick:~ $ diff try ttry2
1c1
< hi
---
> hello

See? diff now highlighted that the first file (< pointing to the file in the left part of the command line you specified) also has a line that’s different from second file.

If we now add exactly the same line to both files, diff will ignore it because it only shows what’s different:

greys@maverick:~ $ echo "test" >> try
greys@maverick:~ $ echo "test" >> try2
greys@maverick:~ $ cat try
hi
test
greys@maverick:~ $ cat try2
hello
test
greys@maverick:~ $
greys@maverick:~ $ diff try try2
1c1
< hi
---
> hello

That’s it for today! I’ll show you some advanced usages of the diff command some other time.

See Also




How To: Generate SSH Key

SSH is such an integral part of everyday Linux/Unix life now, that it makes sense to use it for as many remote access and automation tasks as you can. As you probably know, you shouldn’t be using password SSH authentication unless you have a pretty good reason to do so. By default, always use SSH keys. Today I’ll show you how to generate SSH keys.

Generate SSH key with ssh-keygen

ssh-keygen is a standard utility supplied with SSH package. If you have ssh command on your system, you probably have the ssh-keygen command as well.

Without any command line options, ssh-keygen will ask you a few questions and create the key with default settings:

[greys@rhel8 ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/greys/.ssh/id_rsa):
Created directory '/home/greys/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/greys/.ssh/id_rsa.
Your public key has been saved in /home/greys/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Seu7UBogeX+g9+iv01CDJqiXAby740JKZGrZtu1T3oQ greys@rhel8
The key's randomart image is:
+---[RSA 2048]----+
|. |
|.. . |
| .+.o ... |
| +oo.+oooo |
|+.+o.o+.S. |
|o*oo ..E . |
|=.o o *o= |
|oo . +.o.o |
|o.. ..+++. |
+----[SHA256]-----+
[greys@rhel8 ~]$

Specify SSH key size for ssh-keygen

Most likely you’ll have your preferences for SSH keys and it is much easier to just specify them when running the ssh-keygen command.

This is how one can generate 4096-bit key, for example:

[greys@rhel8 ~]$ ssh-keygen -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/greys/.ssh/id_rsa): /home/greys/.ssh/rsa-4k
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/greys/.ssh/rsa-4k.
Your public key has been saved in /home/greys/.ssh/rsa-4k.pub.
The key fingerprint is:
SHA256:4rf1AGIc99L57/xC1PWu7pJpwhkn5YCmZQqua/XdmGA greys@rhel8
The key's randomart image is:
+---[RSA 4096]----+
| |
| .|
| . .. .o|
| .. o=o... . o|
| . .=*S ++ . . |
| ooEo oo.o . .|
| o o.o.=o=.+ . |
| o ..+o=o=oo |
| ... . o.=*o.|
+----[SHA256]-----+

See Also




How To: Confirm Current Kernel Boot Command in Linux

Screen Shot 2019-01-20 at 22.40.22.pngFor those of you using GRUB boot loader, there’s a very cool way of confirming what boot parameters your boot loader supplied when booting your current OS instance:

greys@server:~$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-4.17.0-041700-generic root=/dev/mapper/ubuntu--vg-root ro quiet splash vt.handoff=1

This is super useful for verifying changes to such boot parameters, that you usually make in GRUB or another bootloader.

After making the changes and rebooting your OS, check the same file again, and it should show new parameters.

See Also




Docker: Stop All Containers

docker-containers-unixtutorial

Now and then, especially when working on a development environment, you need to stop multiple Docker containers. Quite often, you need to stop all of the currently running containers. I’m going to show you one of the possible ways.

Docker: Stop a Container

You need to use a container name or container ID with the docker stop command.

For example, I have an nginx load balancer container:

root@s5:~ # docker ps -f name=nginx
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
32cd3e477546 nginx:latest "nginx -g 'daemon of…" 11 months ago Up About a minute 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp nginx

Based on this output, I can stop my nginx container like this:

root@s5:~ # docker stop nginx
nginx

… or like that:

root@s5:~ # docker stop 32cd3e477546
32cd3e477546

Docker: Stop Multiple Containers

Since I also have a MariaDB container named db, I might need stop it together with nginx.

Here’s the info on the db container:

root@s5:~ # docker ps -f name=db
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c745794419a9 mariadb:latest "docker-entrypoint.s…" 9 months ago Up 4 seconds 3306/tcp db

If I ever decide to stop both nginx and db together, I can do it like this:

root@s5:~ # docker stop nginx db
nginx
db

Docker: Stop All Containers

As you can see from previous examples, docker stop simply takes a list of containers to stop. If there’s more than one container, just use space as a delimiter between container names or IDs.

This also allows us to use a clever shell expansion trick: you can some other command, and pass its output to the docker stop container.

For instance, this shows us the list of all the IDs for currently running Docker containers:

root@s5:~ # docker ps -q
510972d55d8c
1b8b1657736e
c745794419a9
32cd3e477546

What we can do now is pass the result of this command as the parameter for the docker stop command:

root@s5:~ # docker stop $(docker ps -q)
510972d55d8c
1b8b1657736e
c745794419a9
32cd3e477546

And just to check, running docker ps now won’t show any running containers:

root@s5:~ # docker ps -q

IMPORTANT: make sure you double-check what you’re doing! Specifically, run docker ps -q, compare it to docker ps, this kind of thing. Because once containers stopped you may not have an easy way to generate the list of same containers to restart.

In my case, I’m just specifying them manually as the parameters for docker start:

root@s5:~ # docker start 510972d55d8c 1b8b1657736e c745794419a9 32cd3e477546
510972d55d8c
1b8b1657736e
c745794419a9
32cd3e477546

That’s it for today! Hope you enjoyed this quick how-to, let me know if you have any questions, Docker and whatnot!

See Also




screenFetch in RHEL 8

Look what I have finally installed in one of my VirtualBox 6.0 virtual machines yesterday:

Screen Shot 2019-01-16 at 16.01.08.png

Yes, you guessed it right – the installation steps for screenFetch CentOS work in Red Hat just fine!

Red Hat Enterprise Linux 8 beta

I’m surprised the screenFetch isn’t reporting release version. Had to use the hostnamectl command to do this:

[greys@rhel8 ~]$ hostnamectl
Static hostname: rhel8
Icon name: computer-vm
Chassis: vm
Machine ID: 02b5e17ce41846fbaa965ee1c3678162
Boot ID: b36e64b343934359843d2e76db34e8af
Virtualization: oracle
Operating System: Red Hat Enterprise Linux 8.0 Beta (Ootpa)
CPE OS Name: cpe:/o:redhat:enterprise_linux:8.0:beta
Kernel: Linux 4.18.0-32.el8.x86_64
Architecture: x86-64

See Also




How To: Restart MySQL

MariaDB-Foundation-vertical.png

If you’re hosting a website using the popular LAMP stack (Linux/Apache/MySQL/PHP), you’re going to have your services restart from time to time as part of maintenace. In this short post I’ll show you how to restart MySQL database.

As you will see from some of the data, I’m actually using MariaDB which aims to stay MySQL compatible in most of the ways, including the name and the syntax of running startup/shutdown scripts.

Confirm Status of MySQL service

On most of the modern Linux systems, you should probably use the systemctl command to confirm MySQL status:

root@dbm1:~ # systemctl status mysql
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf, timeout.conf
Active: active (running) since Mon 2018-08-20 00:43:33 IST; 4 months 27 days ago
Process: 11534 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 11414 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
Process: 11411 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 11501 (mysqld)
Status: "Taking your SQL requests now..."
CGroup: /system.slice/mariadb.service
└─11501 /usr/sbin/mysqld --wsrep_start_position=b70c6b82-9064-11e5-9c67-3e39fe556c8b:45091479

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

What you’re looking for is the Active line of the output, which shows that the MySQL service is happily running since August 2018. Now, if it was stopped just now, you would see that the service is actually inactive:

root@dbm1:~ # systemctl status mysql
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Drop-In: /etc/systemd/system/mariadb.service.d
└─migrated-from-my.cnf-settings.conf, timeout.conf
Active: inactive (dead) since Tue 2019-01-15 23:03:39 GMT; 8s ago
Process: 11534 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 11501 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 11414 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited, status=0/SUCCESS)
Process: 11411 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Main PID: 11501 (code=exited, status=0/SUCCESS)
Status: "MariaDB server is down"

Jan 15 23:03:34 dbm1.ts.im systemd[1]: Stopping MariaDB database server...
Jan 15 23:03:39 dbm1.ts.im systemd[1]: Stopped MariaDB database server.
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

Restart MySQL with systemctl

Just run this command to restart MySQL. If there are any issues, you’ll probably get an error:

root@dbm1:~ # systemctl restart mysql
root@dbm1:~ #

Restart MySQL using startup script

A more traditional and rather old-school approach is to stop or start MySQL using the /etc/init.d/mysql script. There is no point doing it in the systemctl-enabled Linux distros though, because this /etc/init.d/mysql script will actually use systemctl to manage the service, anyway:

root@dbm1:~ # /etc/init.d/mysql stop
Stopping mysql (via systemctl): [ OK ]
root@dbm1:~ # /etc/init.d/mysql start
Starting mysql (via systemctl): [ OK ]

That’s it for today!

See Also