Как насчет
#!/bin/bash
# userInput - a script that reads in text and outputs it immediately
while true; do
echo "Would you like to input some text? Y/N"
read request
if [[ $request = Y ]]; then
echo "Please input some text"
read input
echo $input
break
elif [[ $request = N ]]; then
echo "Thank You"
break
else
echo "Invalid Input - Please Input Y for yes or N for no"
fi
done
В sysV (init )уровни запуска были просто числом, 0 -6. Система могла быть установлена только на определенный уровень запуска, обычно 3 (сеть + консоль )или 5 (X окна ). Эти уровни выполнения в sysV просто были состояниями, в которых главный процесс init
мог находиться в любой момент времени. В systemd цели служат той же цели, но одновременно можно применять несколько целей.
systemd uses targets which serve a similar purpose as runlevels but act a little different. Each target is named instead of numbered and is intended to serve a specific purpose with the possibility of having multiple ones active at the same time. Some targets are implemented by inheriting all of the services of another target and adding additional services to it. There are systemd targets that mimic the common SystemVinit runlevels so you can still switch targets using the familiar telinit RUNLEVEL command.
Учитывая эту возможность, в systemd типичная система, в которой есть сеть, но нет запущенного X в целевой multi-user.target
.
$ systemctl get-default
multi-user.target
Но цель — это инкапсуляция (группировок )многих целей. Это одно из ключевых преимуществ systemd перед sysV. Вы можете увидеть это, если посмотрите на целевые файлы.
man-страница systemd.targetA unit configuration file whose name ends in ".target" encodes information about a target unit of systemd, which is used for grouping units and as well-known synchronization points during start-up.....
.... They exist merely to group units via dependencies (useful as boot targets), and to establish standardized names for synchronization points used in dependencies between units. Among other things, target units are a more flexible replacement for SysV runlevels in the classic SysV init system. (And for compatibility reasons special target units such as runlevel3.target exist which are used by the SysV runlevel compatibility code in systemd. See systemd.special(7) for details).
Например:
$ grep target /usr/lib/systemd/system/anaconda.target
Requires=basic.target
After=basic.target
ПРИМЕЧАНИЕ.:Здесь anaconda.target
требует запуска basic.target
, и он должен запускаться после basic.target
.
В моей системе CentOS 7.x мы можем видеть, какие цели загружены:
$ systemctl list-units --type=target
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Local Encrypted Volumes
getty-pre.target loaded active active Login Prompts (Pre)
getty.target loaded active active Login Prompts
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
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
rpc_pipefs.target loaded active active rpc_pipefs.target
slices.target loaded active active Slices
sockets.target loaded active active Sockets
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.
19 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
Юнит-файлы в systemd — это просто файлы конфигурации, определяющие одну из пяти вещей. Единицы могут быть, например,:
Вы можете увидеть эти юнит-файлы в этом каталоге в CentOS 7.x:
$ for i in target socket service device mount;do ls -l /usr/lib/systemd/system | grep $i | head -3;done
-rw-r--r-- 1 root root 415 May 3 16:05 anaconda.target
-rw-r--r-- 1 root root 517 Apr 11 03:36 basic.target
drwxr-xr-x. 2 root root 4096 Jul 28 14:56 basic.target.wants
-rw-r--r-- 1 root root 874 Apr 10 23:42 avahi-daemon.socket
-r--r--r-- 1 root root 131 Apr 11 01:03 cups.socket
-rw-r--r-- 1 root root 102 Apr 11 03:23 dbus.socket
-rw-r--r-- 1 root root 275 Apr 27 10:53 abrt-ccpp.service
-rw-r--r-- 1 root root 380 Apr 27 10:53 abrtd.service
-rw-r--r-- 1 root root 361 Apr 27 10:53 abrt-oops.service
-rw-r--r-- 1 root root 169 Apr 12 15:28 clean-mount-point@.service
-rw-r--r-- 1 root root 670 Apr 11 03:36 dev-hugepages.mount
-rw-r--r-- 1 root root 590 Apr 11 03:36 dev-mqueue.mount
Когда система, созданная с помощью systemd, загружается, она обрабатывает юнит-файлы для создания монтирования,настроить сокеты и запустить службы. Порядок этих вещей регулируется юнит-файлами.