SystemDは吸う、長生きするSystemD

Systemdは、Linuxコミュニティの争点のようです。 systemdに中立的な視点がないかのように。 根本的に反対する意見は、あなたは彼を愛するか、破壊を望みます。 中間点を提供したいと思います。 最初に、systemdの悪夢のような性質について議論します。

悪夢と悪夢


systemd-escape


systemd-escape自体が存在するという事実は、明らかにひどい間違いを示しています。 このコマンドをビジネスで見たことも使用したことがない場合は、幸運を考えてください。

実際には、 コマンドは次のように使用されます

/bin/bash -c 'while true; do \
    /usr/bin/etcdctl set my-container \
        "{\"host\": \"1\", \"port\": $(/usr/bin/docker port my-container 5000 | cut -d":" -f2)}" \
    --ttl 60; \
    sleep 45; \
done'

, , , cloud-init CoreOS, . Escape- .

ExecStart , systemd , . , , systemd. systemd shlex Python Shellwords Ruby, , systemd-escape:

$ man systemd-escape | head
SYSTEMD-ESCAPE(1)                                            systemd-escape                                            SYSTEMD-ESCAPE(1)

NAME
       systemd-escape - Escape strings for usage in system unit names

SYNOPSIS
       systemd-escape [OPTIONS...] [STRING...]

DESCRIPTION
       systemd-escape may be used to escape strings for inclusion in systemd unit names.

SystemD:

$ systemd-escape 'while true;do /usr/bin/etcdctl set my-container "{\"host\": \"1\", \"port\": $(/usr/bin/docker port my-container 5000 | cut -d":" -f2)}" --ttl 60;sleep 45;done'
while\x20true\x3bdo\x20-usr-bin-etcdctl\x20set\x20my\x2dcontainer\x20\x22\x7b\x5c\x22host\x5c\x22:\x20\x5c\x221\x5c\x22\x2c\x20\x5c\x22port\x5c\x22:\x20\x24\x28-usr-bin-docker\x20port\x20my\x2dcontainer\x205000\x20\x7c\x20cut\x20\x2dd\x22:\x22\x20\x2df2\x29\x7d\x22\x20\x2d\x2dttl\x2060\x3bsleep\x2045\x3bdone



, while Bash, , .


, journald . , : tail, cat, less grep . . , vim less . , .

, . . /, , journalctl, .

- , systemd. , journald .


, systemd. , , Linux systemd.


, init- SysV ZooKeeper, 169 , .

# for some reason these two options are necessary on jdk6 on Ubuntu
#   accord to the docs they are not necessary, but otw jconsole cannot
#   do a local attach
...

systemd:

[Unit]
Description=ZooKeeper

[Service]
Type=simple
Restart=always
RestartSec=5
EnvironmentFile=/etc/sysconfig/zookeeper
ExecStart=/usr/bin/java -cp ${ZK_CLASSPATH} ${JVM_FLAGS} org.apache.zookeeper.server.quorum.QuorumPeerMain ${ZOO_CFG_FILE}

[Install]
WantedBy=multi-user.target

. , , :

ZK_CLASSPATH=/opt/zookeeper:/opt/zookeeper/lib:/etc/zookeeper
JVM_FLAGS=-Xmx=2g
ZOO_CFG_FILE=/etc/zookeeper/zoo.cfg

. .

, , , , syslog-ng rsyslog. , .


- supervisord , . systemd , . , init , . segfault , .

systemd:

[Service]
...
Restart=always
RestartSec=1

, , . stop , , , . , systemd , , .


init- SysV, ? , A B, C? :

while true ; do
  if pgrep serviceB ; then
    start_service
    break
  else
    sleep 1
  fi
done

A C init- C while A. , .

systemd:

[Unit]
Description=Service A
After=serviceB.service
Before=serviceC.service

. . systemd , serviceA serviceB, serviceC. , drop-in , . , .

:


systemd :

[Unit]
Description=Service A
ConditionPathExists=/etc/sysconfig/serviceA

Service A /etc/sysconfig/serviceA. , .

:


systemd , Linux systemd , init-. systemd , , .


, systemd , . , rsyslog cloud-final. , cloud-final cloud-init.

rsyslog.service /usr/lib/systemd/system/rsyslog.service, . drop-in /etc/systemd/system/rsyslog.service.d/after-cloudinit.conf:

[Unit]
After=cloud-final.service

, .conf. , . drop-in , rsyslog , cloud-final.service /.

: , systemd . , , , , , %02d-%s.conf.


, ? :

[Service]
ExecStartPre=

, ExecStartPre . ExecStartPre , , .


systemd , . , . :

$ sudo journalctl -u rsyslog.service

less rsyslog.service. :

$ sudo journalctl -u rsyslog.service -f

tail -f .

, logrotate, .

rsyslog syslog-ng , , syslog, syslog.


. systemd, :


, , systemd. systemctl journalctl, :


, «systemd », , systemd. systemd , systemd.


Source: https://habr.com/ru/post/J325792/


All Articles