В чем разница между «работой» и «службой» для systemctl?

Пробовал с нижеуказанными командами awk и sed. Python работал нормально

awk-решение:

awk  '{print "CRE_ff_Nodes_abc,"$0}' filename

выход

CRE_ff_Nodes_abc,abc,Nodes.csv
CRE_ff_Nodes_abc,def,Nodes.csv
CRE_ff_Nodes_abc,ghi,Nodes.csv
CRE_ff_Nodes_abc,jkl,Nodes.csv

команда2:

sed "s/^/CRE_ff_Nodes_abc,/g" filename

выход

CRE_ff_Nodes_abc,abc,Nodes.csv
CRE_ff_Nodes_abc,def,Nodes.csv
CRE_ff_Nodes_abc,ghi,Nodes.csv
CRE_ff_Nodes_abc,jkl,Nodes.csv

питон

#!/usr/bin/python
o=open('filename','r')
for i in o:
    print "CRE_ff_Nodes_abc,{0}".format(i).strip()

выход

CRE_ff_Nodes_abc,abc,Nodes.csv
CRE_ff_Nodes_abc,def,Nodes.csv
CRE_ff_Nodes_abc,ghi,Nodes.csv
CRE_ff_Nodes_abc,jkl,Nodes.csv
1
07.05.2021, 21:42
1 ответ

TLDR:«Работы» представляют запрошенные изменения состояния «сервисов» или других модулей systemd. Они существуют только во время запуска/остановки/перезапуска службы и т. д.

Услуги

На языке systemd «сервисы» — это контролируемые группы процессов, (в первую очередь )определяемые через.serviceфайлы конфигурации модулей.

Каждая служба (, как и любой другой тип модуля systemd ), имеет состояние, как описано на справочной странице systemd (1):

Units may be "active" (meaning started, bound, plugged in, …, depending on the unit type, see below), or "inactive" (meaning stopped, unbound, unplugged, …), as well as in the process of being activated or deactivated, i.e. between the two states (these states are called "activating", "deactivating"). A special "failed" state is available as well, which is very similar to "inactive" and is entered when the service failed in some way (process returned error code on exit, or crashed, an operation timed out, or after too many restarts). If this state is entered, the cause will be logged, for later reference. Note that the various unit types may have a number of additional substates, which are mapped to the five generalized unit states described here.

(К настоящему времени к пяти состояниям юнитов были добавлены «перезагрузка» и «техническое обслуживание», так что всего их семь, но это мало что меняет)

systemctl --type=service --state=runningотображает все службы, которые находятся в подсостоянии «работает» «активного» состояния и, таким образом, завершили активацию.

Работа

«Задания» — это запросы на изменение состояния к systemd. Они существуют только в оперативной памяти и только до тех пор, пока обрабатывается запрос.

Что происходит, когда запрашивается изменение состояния (при загрузке или выключении с использованием systemctl start, systemctl stopи т. д. )описано в оригинальном проектном документе systemd :

.

if a unit is requested to start up or shut down we will add it and all its dependencies to a temporary transaction. Then, we will verify if the transaction is consistent (i.e. whether the ordering via After/Before of all units is cycle-free). If it is not, systemd will try to fix it up, and removes non-essential jobs from the transaction that might remove the loop. Also, systemd tries to suppress non-essential jobs in the transaction that would stop a running service. Non-essential jobs are those which the original request did not directly include but which where pulled in by Wants type of dependencies. Finally we check whether the jobs of the transaction contradict jobs that have already been queued, and optionally the transaction is aborted then. If all worked out and the transaction is consistent and minimized in its impact it is merged with all already outstanding jobs and added to the run queue.

По существу, хотя, например,. systemctl start ssh.serviceработает, создаются задания запуска для ssh.serviceи всех его (еще не запущенных )зависимостей, а устройство ssh.serviceпереводится в состояние «активация».

Вы увидите эти задания в выходных данных systemctl list-jobs, пока служба не завершила запуск или не удалось выполнить задание, необходимое для изменения состояния. После этого сервис переводится в состояние «активен» или «сбой».

2
28.07.2021, 11:34

Теги

Похожие вопросы