Как перечислить все службы, которые запускаются ПОСЛЕ некоторой службы в systemd

Из man bash (где-то после строки 3813):

!      Start  a  history substitution, except when followed by a blank,
          newline, carriage return, = or ( (when the extglob shell  option
          is enabled using the shopt builtin).

[...]

$      The  last  word.   This  is  usually the last argument, but will
          expand to the zeroth word if there is only one word in the line.

Итак, !$ вспомнит последний аргумент из последней команды из истории.

Вот несколько примеров и эквивалентов:

$ echo foo bar
foo bar
$ echo !$ # recall the last argument from the last command from history
echo bar
bar

$ echo foo bar
foo bar
$ echo !:$ # the same like `!$'
echo bar
bar

$ echo foo bar
foo bar
$ echo !:2  # recall the second (in this case the last) argument from the last command from history
echo bar
bar

$ echo foo bar
foo bar
$ echo $_ # gives the last argument from the last command from history
bar

$ echo foo bar
foo bar
$ echo Alt+. # pressing Alt and . (dot) in the same time will automatically insert the last argument from the last command from history
bar

$ echo foo bar
foo bar
$ echo Alt+_ # the same like when you press Alt+.
bar

$ echo foo bar
foo bar
$ echo Esc. # the same like when you press Alt+.
bar

Все они будут работать только внутри интерактивной оболочки. Но если вы используете эту команду из своего вопроса внутри скрипта, как вы сказали, что вы его сеете, то все по-другому: при запуске скрипта это начнется в новой оболочке, неинтерактивной оболочке, поэтому история расширение не имеет никакого эффекта в этом случае, поэтому команда:

echo "An Example" > !$

создает файл !$, если нет (в противном случае перезаписывает его), и записывает в него An Example. [!d7 ]

3
задан 12 August 2017 в 22:59

3 ответа

Я думаю, что команда, которую вы ищете, это:

$ systemctl list-dependencies --reverse NetworkManager-wait-online.service 
NetworkManager-wait-online.service
● └─network-online.target
●   └─hddtemp.service

Из man systemctl:

   list-dependencies [NAME]
       Shows units required and wanted by the specified unit. This
       recursively lists units following the Requires=, Requisite=,
       ConsistsOf=, Wants=, BindsTo= dependencies. If no unit is
       specified, default.target is implied.

       By default, only target units are recursively expanded. When --all
       is passed, all other units are recursively expanded as well.

       Options --reverse, --after, --before may be used to change what
       types of dependencies are shown.

   --reverse
       Show reverse dependencies between units with list-dependencies,
       i.e. follow dependencies of type WantedBy=, RequiredBy=, PartOf=,
       BoundBy=, instead of Wants= and similar.
4
ответ дан 22 May 2018 в 19:31
  • 1
    Спасибо, но я не уверен. Это очень короткий список ... Когда я ставлю - вместо этого, он становится очень длинным списком. Я отключил службу, так как это вызвало длительную задержку загрузки, и теперь я пытаюсь понять, какая служба может пострадать от этого решения. – S.R. 12 August 2017 в 23:45
  • 2
    Обратите внимание, что --after показывает все остальные единицы, которые заданы для запуска упомянутого после себя. Вы либо ищете --reverse, либо, возможно, --before, в котором отображаются все блоки, перед которыми необходимо запустить упомянутый. – Byte Commander 12 August 2017 в 23:51
  • 3
    Да, может быть, прежде. Хорошо видеть, что службы, которые должны запускаться после этой службы, все равно запускаются, даже когда они отключены. Благодаря! :) – S.R. 13 August 2017 в 00:00
  • 4
    Не забудьте принять этот ответ, если он полностью решит ваш вопрос. :-) Спасибо. – Byte Commander 13 August 2017 в 00:14

Я думаю, что команда, которую вы ищете, это:

$ systemctl list-dependencies --reverse NetworkManager-wait-online.service NetworkManager-wait-online.service ● └─network-online.target ● └─hddtemp.service

Из man systemctl:

list-dependencies [NAME] Shows units required and wanted by the specified unit. This recursively lists units following the Requires=, Requisite=, ConsistsOf=, Wants=, BindsTo= dependencies. If no unit is specified, default.target is implied. By default, only target units are recursively expanded. When --all is passed, all other units are recursively expanded as well. Options --reverse, --after, --before may be used to change what types of dependencies are shown. --reverse Show reverse dependencies between units with list-dependencies, i.e. follow dependencies of type WantedBy=, RequiredBy=, PartOf=, BoundBy=, instead of Wants= and similar.
4
ответ дан 18 July 2018 в 08:36

Я думаю, что команда, которую вы ищете, это:

$ systemctl list-dependencies --reverse NetworkManager-wait-online.service NetworkManager-wait-online.service ● └─network-online.target ● └─hddtemp.service

Из man systemctl:

list-dependencies [NAME] Shows units required and wanted by the specified unit. This recursively lists units following the Requires=, Requisite=, ConsistsOf=, Wants=, BindsTo= dependencies. If no unit is specified, default.target is implied. By default, only target units are recursively expanded. When --all is passed, all other units are recursively expanded as well. Options --reverse, --after, --before may be used to change what types of dependencies are shown. --reverse Show reverse dependencies between units with list-dependencies, i.e. follow dependencies of type WantedBy=, RequiredBy=, PartOf=, BoundBy=, instead of Wants= and similar.
4
ответ дан 24 July 2018 в 19:08

Другие вопросы по тегам:

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