19 systemd multi-user.target graphical.target default.target systemctl list-units --type=target | emergency gives less than rescue

for services started in multi-user.target, the same services will be started in graphical.target

service - starts things
target - collections of services 
target itself defines dependencies with other targets
in order to put services in a target, we create .wants
wants is a symbolic link created automatically when we do systemctl enable servicename


Comparison of SysV Runlevels with systemd Targets
RunlevelTarget UnitsDescription
0runlevel0.targetpoweroff.targetShut down and power off the system.
1runlevel1.targetrescue.targetSet up a rescue shell.
2runlevel2.targetmulti-user.targetSet up a non-graphical multi-user system.
3runlevel3.targetmulti-user.targetSet up a non-graphical multi-user system.
4runlevel4.targetmulti-user.targetSet up a non-graphical multi-user system.
5runlevel5.targetgraphical.targetSet up a graphical multi-user system.
6runlevel6.targetreboot.targetShut down and reboot the system.

Comparison of SysV init Commands with systemctl
Old CommandNew CommandDescription
runlevelsystemctl list-units --type targetLists currently loaded target units.
telinit runlevelsystemctl isolate name.targetChanges the current target.
[bit@localhost ~]$ systemctl get-default 
graphical.target

To configure the system to use a different target unit by default, type the following at a shell prompt as root:
systemctl set-default name.target
To change to a different target unit in the current session, type the following at a shell prompt as root:
systemctl isolate name.target

Rescue mode provides a convenient single-user environment and allows you to repair your system in situations when it is unable to complete a regular booting process. In rescue mode, the system attempts to mount all local file systems and start some important system services, but it does not activate network interfaces or allow more users to be logged into the system at the same time. In Red Hat Enterprise Linux 7, rescue mode is equivalent to single user mode and requires the root password.

To change the current target and enter rescue mode in the current session, type the following at a shell prompt as root:
systemctl rescue

Emergency mode provides the most minimal environment possible and allows you to repair your system even in situations when the system is unable to enter rescue mode. In emergency mode, the system mounts the root file system only for reading, does not attempt to mount any other local file systems, does not activate network interfaces, and only starts a few essential services. In Red Hat Enterprise Linux 7, emergency mode requires the root password.
To change the current target and enter emergency mode, type the following at a shell prompt as root:
systemctl emergency
systemd is a new feature in RHEL7

systemd - starts things

after kernel loading, systemd is started

systemd is not the same like runlevel in previous versions

systemd starts:
-services
-mount
-automount

in order to understand systemd, you should understand the UNIT file

UNIT file is a replacement of old init script

UNIT file defines how to:
- start services
- mount filesystems
- automount filesystems

UNIT scripts are stored in 2 different paths:
default /usr/lib/systemd
/etc/systemd
=========================
to start services you need systemd

service scripts are stored in
[bit@localhost ~]$ ll /usr/lib/systemd/system

default scripts are stored in  /usr/lib/systemd/system, don't touch those scripts
[bit@localhost ~]$ ls  /usr/lib/systemd/system
abrt-ccpp.service                        numad.service
abrtd.service                            oddjobd.service
abrt-oops.service                        packagekit-offline-update.service
abrt-pstoreoops.service                  packagekit.service
abrt-vmcore.service                      paths.target

if you want to change, go to /etc/systemd/system

basic unit in systemd is a service
========================================

[bit@localhost ~]$ cat /usr/lib/systemd/system/sshd.service 
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.service
Wants=sshd-keygen.service

[Service]
Type=forking
PIDFile=/var/run/sshd.pid
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s

[Install]
WantedBy=multi-user.target
[bit@localhost ~]$ 


========================================
services are assigned to target and target takes care of starting the services

to manage services, we use systemctl command

[bit@localhost ~]$ systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2017-09-10 16:33:32 EDT; 3 days ago
     Docs: man:sshd(8)
           man:sshd_config(5)
  Process: 973 ExecStart=/usr/sbin/sshd $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 987 (sshd)
   CGroup: /system.slice/sshd.service
           └─987 /usr/sbin/sshd
[bit@localhost ~]$ 


========================================
systemctl stop sshd
systemctl disable sshd - stops completed after systemd or machine reboot

[bit@localhost ~]$ systemctl disable sshd
Removed symlink /etc/systemd/system/multi-user.target.wants/sshd.service.

[bit@localhost ~]$ systemctl enable sshd
Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib/systemd/system/sshd.service.

========================================

different states when machines boots are targets

targets are defined in 2 directories
/usr/lib/systemd/system

[bit@localhost system]$ pwd
/usr/lib/systemd/system
[bit@localhost system]$ ls *target
anaconda.target            local-fs-pre.target     runlevel2.target
basic.target               local-fs.target         runlevel3.target
bluetooth.target           machines.target         runlevel4.target
cryptsetup-pre.target      multi-user.target       runlevel5.target
cryptsetup.target          network-online.target   runlevel6.target
ctrl-alt-del.target        network-pre.target      shutdown.target
default.target             network.target          sigpwr.target
emergency.target           nfs-client.target       sleep.target
final.target               nss-lookup.target       slices.target
getty.target               nss-user-lookup.target  smartcard.target
graphical.target           paths.target            sockets.target


the most important targets are  multi-user.target and graphical.target 

the idea below targets is that sub-service belongs to specific target
when you enable service, symbolic link is created in *wants*

*wants* defines what a specific target really wants

Services that should be available in multi-user target at all times:

[bit@localhost system]$ cd multi-user.target.wants/
[bit@localhost multi-user.target.wants]$ ls -l
total 0
lrwxrwxrwx. 1 root root 16 Sep  9 22:06 brandbot.path -> ../brandbot.path
lrwxrwxrwx. 1 root root 15 Sep  9 22:06 dbus.service -> ../dbus.service
lrwxrwxrwx. 1 root root 15 Sep 10 12:23 getty.target -> ../getty.target
lrwxrwxrwx. 1 root root 24 Sep  9 22:06 plymouth-quit.service -> ../plymouth-quit.service
lrwxrwxrwx. 1 root root 29 Sep  9 22:06 plymouth-quit-wait.service -> ../plymouth-quit-wait.service
lrwxrwxrwx. 1 root root 33 Sep 10 12:23 systemd-ask-password-wall.path -> ../systemd-ask-password-wall.path
lrwxrwxrwx. 1 root root 25 Sep 10 12:23 systemd-logind.service -> ../systemd-logind.service
lrwxrwxrwx. 1 root root 39 Sep 10 12:23 systemd-update-utmp-runlevel.service -> ../systemd-update-utmp-runlevel.service
lrwxrwxrwx. 1 root root 32 Sep 10 12:23 systemd-user-sessions.service -> ../systemd-user-sessions.service
[bit@localhost multi-user.target.wants]$ 


[bit@localhost system]$ pwd
/etc/systemd/system
[bit@localhost system]$ ls
basic.target.wants                                       display-manager.service
bluetooth.target.wants                                   getty.target.wants
dbus-org.bluez.service                                   graphical.target.wants
dbus-org.fedoraproject.FirewallD1.service                multi-user.target.wants
dbus-org.freedesktop.Avahi.service                       printer.target.wants
dbus-org.freedesktop.ModemManager1.service               remote-fs.target.wants
dbus-org.freedesktop.NetworkManager.service              sockets.target.wants
dbus-org.freedesktop.nm-dispatcher.service               spice-vdagentd.target.wants
default.target                                           sssd.service.d
default.target.wants                                     sysinit.target.wants
dev-virtio\x2dports-org.qemu.guest_agent.0.device.wants  system-update.target.wants
[bit@localhost system]$


These are the services which are always started in multi-user target

[bit@localhost multi-user.target.wants]$ pwd
/etc/systemd/system/multi-user.target.wants
[bit@localhost multi-user.target.wants]$ \ls
abrt-ccpp.service     chronyd.service  libstoragemgmt.service     remote-fs.target
abrtd.service      crond.service  libvirtd.service     rngd.service
abrt-oops.service     cups.path  mdmonitor.service     rsyslog.service
abrt-vmcore.service   cups.service  ModemManager.service     smartd.service
abrt-xorg.service     irqbalance.service  netcf-transaction.service  sshd.service
atd.service      kdump.service  NetworkManager.service     sysstat.service
auditd.service      ksm.service  nfs-client.target     tuned.service
avahi-daemon.service  ksmtuned.service  postfix.service     vmtoolsd.service
[bit@localhost multi-user.target.wants]$

     /etc
           System-specific configuration.
 (…)
 VENDOR-SUPPLIED OPERATING SYSTEM RESOURCES
       /usr
            Vendor-supplied operating system resources. 
            Usually read-only, but this is not required. Possibly 
            shared between multiple hosts. This directory should not
            be modified by the administrator, except when installing 
            or removing vendor-supplied packages.
default target is symbolic link to /usr/lib/systemd/system/graphical.target


[bit@localhost ~]$ ls -l /etc/systemd/system/default.target
lrwxrwxrwx. 1 root root 40 Sep 10 12:30 /etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target

you can change graphical.target to multi-user.target, just change symbolic link

[bit@localhost ~]$ systemctl list-units --type=target
UNIT                   LOAD   ACTIVE SUB    DESCRIPTION
basic.target           loaded active active Basic System
cryptsetup.target      loaded active active Encrypted Volumes
getty.target           loaded active active Login Prompts
graphical.target       loaded active active Graphical Interface
local-fs-pre.target    loaded active active Local File Systems (Pre)
local-fs.target        loaded active active Local File Systems
multi-user.target      loaded active active Multi-User System
network-online.target  loaded active active Network is Online
network.target         loaded active active Network
nfs-client.target      loaded active active NFS client services
nss-user-lookup.target loaded active active User and Group Name Lookups
paths.target           loaded active active Paths
remote-fs-pre.target   loaded active active Remote File Systems (Pre)
remote-fs.target       loaded active active Remote File Systems
slices.target          loaded active active Slices
sockets.target         loaded active active Sockets
sound.target           loaded active active Sound Card
swap.target            loaded active active Swap
sysinit.target         loaded active active System Initialization
timers.target          loaded active active Timers

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.
[bit@localhost ~]$ systemctl list-units --type=target

List enables services
systemctl list-unit-files | grep enabled

===============
[bit@localhost ~]$ cat /usr/lib/systemd/system/multi-user.target
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Multi-User System
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes
[bit@localhost ~]$ 

Comments

Popular posts from this blog

HAproxy logging

tomcat catalina coyote jasper cluster

NFS mount add in fstab _netdev instead of default | firewall-cmd --list-all