Administering Oracle Linux 7: Part 1—Service Management

Administering Oracle Linux 7: Part 1

This article is Part 1 of a series that explains how to administer Oracle Linux 7. This article focuses on service management.

Read Part II
Read Part III

Introduction to Services

Oracle Linux 7 has changed its framework for starting a system, administering services, and configuring services. Now, all management is performed by the systemddaemon (the new system and service manager), which takes care of processes and server daemons during the boot process and when the system is running. Additionally, systemd is able to automatically resolve service dependencies, reducing troubleshooting time and reducing the time required to start services.

In previous versions of Oracle Linux, the init process had process identifier (PID) 1, but on Oracle Linux 7 this PID is associated with systemd, as show below:

[root@oel73 ~]# ps aux | head -2


root       1   0.4  0.1    52844  6772   ?        Ss   20:25   0:02 /usr/lib/systemd/systemd --switched-root --system --deserialize 23

There are several types of systemd objects, called units, which can be used during service administration, as shown below:

[root@oel73 ~]# systemctl -t help
Available unit types:

From all the units listed above, two of them (service and socket) are commonly handled during service administration. The following summarizes the unit types:

  • service  represents system services (.service extension).
  • socket represents an interprocess communication socket (.socket extension).
  • target represents a group of systemd units (.target extension).
  • device is the representation of a device as a file to support device-based activation (.device extension).
  • mount is used by systemd to monitor system mount points (.mount extension).
  • automountis used by systemd to monitor file system automount points (.automountextension).
  • snapshot is a representation of a system state (.snapshotextension).
  • timer represents a systemd timer (.timer extension).
  • swap represents a swap file or swap device (.swap extension).
  • path is a directory or file representation that is used to delay the start of a service until a determined status happens (.path extension).
  • slice represents a group of organized units to manage system processes (.slice extension).
  • scope represents an externally created process (.scope extension).

All these unit types are involved with Oracle Linux 7 initialization, so for a better understanding of this mechanism, the following is the step-by-step process:

  • The system firmware executes the power-on self-test (POST), and searches for a boot device configured either in the Master Boot Record (MBR) or the Unified Extensible Firmware Interface (UEFI) boot firmware.
  •  The boot loader (GRUB2) takes control.
  • The boot loader reads its configuration file from either the/etc/grub.d directory or the/etc/default/grub or /boot/grub2/grub.cfg files. The content of the /etc/default/grubfile is shown below:
[root@oel73 ~]# more /etc/default/grub 
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_CMDLINE_LINUX="crashkernel=auto  vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet"
  • The boot loader loads the kernel and initramfsfrom disk to memory. Afterwards, all kernel modules from initramfs are also executed.
  • The boot loader hands control over to the kernel.
  • Drivers from initramfs are load by the kernel.
  • The /sbin/init file from initramfs is executed.
  • The systemd daemon from initramfs runs all target units (.target extension), which mounts the /sysroot directory.
  • Control is switched from memory (initramfs) to disk (system root file system).
  • systemd executes a default target (/etc/systemd/system/ file) and all related units (/etc/systemd/system directory) to resolve dependencies. At the end, we have either a text-based screen or a GUI.  The contents of the /etc/systemd/system/ file is shown below:
[root@oel73 ~]# more /etc/systemd/system/
Description=Graphical Interface

The systemd target works as a group of systemd units, which must be started to get to a stable end state (very similar to the milestones for Oracle Solaris

  • The more relevant targets are listed below:
  • represents text-based logins with support for multiple users.
  • represents graphical and text-based logins supporting multiple users. This target includes the previous one.
  • indicates the system has transited from initramfs to the system root file system mounted as read-only.
  • indicates the basic system initialization has been completed.

Administering Services

The first changes introduced by Oracle Linux 7 are the commands to stop and reboot the system, as shown below

[root@oel73 ~]# systemctl poweroff
[root@oel73 ~]# systemctl reboot

Both commands have backward compatibility to the old poweroff and reboot commands, respectively, from previous Oracle Linux versions. These old commands are symbolically linked to the new Oracle Linux 7 systemctl commands.

When managing services on Oracle Linux 7, the main operation is to collect the status of all the services. However, before getting the statuses, you need to know all the existing services on the system. Thus, execute the following:

[root@oel73 ~]# systemctl | more
UNIT                                 LOAD   ACTIVE SUB       DESCRIPTION
proc-sys-fs-binfmt_misc.automount    loaded active waiting   Arbitrary Executable File 
Formats File System Automount Point
sda1.device    loaded active plugged   VMware_Virtual_S
sda2.device    loaded active plugged   LVM PV JC02RJ-zNYK-71eq-Ed
3t-GygF-WwTp-sZNbHy on /dev/sda2
loaded active plugged   VMware_Virtual_S
sdb1.device    loaded active plugged   VMware_Virtual_S

Sometimes it is convenient to list only the service units, as shown below:

[root@oel73 ~]# systemctl list-units --type service –all
UNIT                                 LOAD   ACTIVE SUB       DESCRIPTION
abrt-ccpp.service                    loaded active exited    Install ABRT coredump hook
abrt-oops.service                    loaded active running   ABRT kernel log watcher
abrt-xorg.service                    loaded active running   ABRT Xorg log watcher
abrtd.service                        loaded active running   ABRT Automated Bug Reporting
accounts-daemon.service              loaded active running   Accounts Service
alsa-state.service                   loaded active running   Manage Sound Card State (restore and store)
atd.service                          loaded active running   Job spooling tools

Now that the existing services are known, to get the status of the firewall service, execute the following command

[root@oel73 ~]# systemctl status firewalld.service
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
   Active: active (running) since Sat 2015-03-28 02:14:33 BRT; 1h 28min ago
 Main PID: 604 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─604 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
Mar 28 02:14:33 systemd[1]: Started firewalld - dynamic firewall daemon.

The firewalld.service service unit shows that the firewalld daemon is active and running. Nevertheless, other relevant statuses are possible, such as inactive (the service is not running), enabled (the service will be loaded at boot time), disabled (the service won’t be started at boot time), static (the service cannot be enabled, but it can be started by another unit automatically), and active (the service is waiting for an event).

Another easy way to verify the status of each service is by running the following command:

[root@oel73 ~]# systemctl list-unit-files --type service
UNIT FILE                                   STATE   
abrt-ccpp.service                           enabled 
abrt-oops.service                           enabled 
abrt-pstoreoops.service                     disabled
abrt-vmcore.service                         enabled 
abrt-xorg.service                           enabled 
abrtd.service                               enabled 
accounts-daemon.service                     enabled 
alsa-restore.service                        static  
alsa-state.service                          static  
alsa-store.service                          static  
anaconda-direct.service                     static  
anaconda-noshell.service                    static  

To stop a service and to get its status, execute the following:

[root@oel73 ~]# systemctl stop firewalld.service
[root@oel73 ~]# systemctl status firewalld.service
firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
   Active: inactive (dead) since Sat 2015-03-28 03:51:00 BRT; 2s ago
  Process: 604 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 604 (code=exited, status=0/SUCCESS)

To start the firewalld service again, execute the following:

[root@oel73 ~]# systemctl start firewalld.service

To restart and reload a service, run the following commands:

[root@oel73 ~]# systemctl restart firewalld.service
[root@oel73 ~]# systemctl reload firewalld.service

To verify whether a specific service (for example, firewalld) is active at this time and is enabled to start at boot time, run the following commands:

[root@oel73 ~]# systemctl is-active firewalld
[root@oel73 ~]# systemctl is-enabled firewalld

In rare cases, it is necessary to prevent a service from starting because of a possible conflict with another service. However, a disabled service could be enabled accidentally by an administrator and the result could be unpredictable, so this case we could “mask” the service. A masked service doesn’t start automatically, but it starts manually if the administrator runs the systemctl start command. Thus, to mask and unmask a service, execute the following:

[root@oel73 ~]# systemctl mask firewalld
ln -s '/dev/null' '/etc/systemd/system/firewalld.service'
[root@oel73 ~]# systemctl unmask firewalld
rm '/etc/systemd/system/firewalld.service'

During maintenance of s system, it is appropriate to list the failed services and this can be accomplished by executing the following:

[root@oel73 ~]# systemctl --failed --type=service
network.service loaded failed failed LSB: Bring up/down networking
rhnsd.service   loaded failed failed LSB: Starts the Spacewalk Daemon
rngd.service    loaded failed failed Hardware RNG Entropy Gatherer Daemon
LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
3 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.

To find any stuck jobs on the system, run the following:

[root@oel73 ~]# systemctl list-jobs
No jobs running.

Almost all services have required dependencies in order to start, so to list the dependencies of a service, execute the following:

[root@oel73 ~]# systemctl list-dependencies firewalld.service
 │ └─...

To list the dependencies in reverse order, run the following:

[root@oel73 ~]# systemctl list-dependencies --reverse firewalld.service

Previously, we learned about the systemd targets (a set of systemd units). It is easy to list all the available targets by running the following command:

[root@oel73 ~]# systemctl list-units --type=target -all
UNIT                   LOAD   ACTIVE   SUB    DESCRIPTION         loaded active   active Basic System      loaded active   active Encrypted Volumes       loaded inactive dead   Emergency Mode           loaded inactive dead   Final Step           loaded active   active Login Prompts       loaded active   active Graphical Interface    loaded active   active Local File Systems (Pre)        loaded active   active Local File Systems      loaded active   active Multi-User System  loaded inactive dead   Network is Online         loaded active   active Network

Additionally, to list all the existing targets on disk, execute the following:

[root@oel73 ~]# systemctl list-unit-files --type=target -all
UNIT FILE                 STATE           static               static         static          static       disabled             enabled             disabled           static               static  

Picking a relevant target, such as, we can list its dependency on other targets by executing the following

[root@oel73 ~]# systemctl list-dependencies | grep target
  │ ├─
  │ ├─
  │ ├─
  │ ├─
  │ │ ├─
  │ │ ├─
  │ │ └─

  │ └─

In previous Oracle Linux versions, it was possible to go to specific run level. In Oracle Linux 7, to go to a specific target (the equivalent of a run level) and stop all services that are not related to the target, execute the following:

[root@oel73 ~]# sysctl isolate

A question arises: What’s the default target on Oracle Linux 7? To find the answer, execute the following:

[root@oel73 ~]# systemctl get-default

This configuration is shown as being persistent in the /etc/systemd/system directory, as shown below:

[root@oel73 system]# pwd
[root@oel73 system]# ls -al
lrwxrwxrwx. 1 root root 36 Sep 10  2014 -> /lib/systemd/system/

To change the default target, run the following:

[root@oel73 ~]# systemctl set-default

Recovering from Boot Issues and Other Problems

The most common problem when administering an Oracle Linux 7 system is losing the root password. Use the following procedure to reset it:

  • Reboot Oracle Linux 7.
  • Interrupt the boot process by pressing any key.
  • Edit the line that starts with linux16 and, at end, append the string rd.break, as shown below:
linux16 /vmlinuz-3.8.13-55.1.5.el7uek.x86_64 root=/dev/mapper/ol-root ro crashkernel=auto  vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet LANG=en_US.UTF-8 initrd16 /initramfs-3.8.13-55.1.5.el7uek.x86_64.img rd.break
  • Boot by pressing CTRL + x.
  • Execute mount –o remount,rw /sysroot.
  • Execute chroot /root.
  • Execute passwd root.
  • Execute exit.
  • Execute exit.
  • Execute touch /.autorelabel (because of SELinux protection).

Additionally, to select a different target at boot time, it is necessary to include the string systemd.unit at the end of the line starting with linux16, as shown in the procedure below:

  • Reboot Oracle Linux 7
  • Interrupt the boot process by pressing any key.
  • Edit the line that starts with linux16 and, at end, append either or, as shown below:
linux16 /vmlinuz-3.8.13-55.1.5.el7uek.x86_64 root=/dev/mapper/ol-root ro crashkernel=auto  vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet LANG=en_US.UTF-8 initrd16 /initramfs-3.8.13-55.1.5.el7uek.x86_64.img

linux16 /vmlinuz-3.8.13-55.1.5.el7uek.x86_64 root=/dev/mapper/ol-root ro crashkernel=auto  vconsole.font=latarcyrheb-sun16 vconsole.keymap=us rhgb quiet LANG=en_US.UTF-8 initrd16 /initramfs-3.8.13-55.1.5.el7uek.x86_64.img

Remember that waits for to finish before initializing other components from the system, while mounts the root file system as read-only. Both options can be used to fix serious problems that prevent Oracle Linux 7 from booting.

  • Boot by pressing CTRL + x.
  • Execute mount –o remount,rw /sysroot.
  • Execute chroot /root.
  • Perform the required maintenance. For example, we could repair the boot load by executing grub2-mkconfig > /boot/grub2/grub.cfg.
  • Execute exit.
  • Execute systemctl reboot.

I hope you enjoyed this article!

See Also

Here are some links to other things I’ve written:

Deixe um comentário

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detectado !

Verificamos que está usando alguma extensão para bloquear os anúncios. O GPO (Grupo de Profissionais Oracle) obtém a sua renda através dos anúncios, para assim manter toda a estrutura dedicada a universalização do conhecimento.

Se você gosta de nosso trabalho, pedimos por gentileza que desabilite o ads blocker. Trabalhamos somente com o Google Adsense e tentamos ao máximo exibir apenas o necessário.

Agradecemos de antemão ! :)

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock