⬆️ ⬇️

SystemD sucks, long live SystemD

It seems that systemd is an apple of contention in the Linux community. As if there is no neutral point of view on systemd. Fundamentally opposing opinions suggest that you should either love him or desire destruction. I want to suggest a certain middle ground. To begin with, let's discuss the dreadful properties of systemd.



Bad and nightmarish



systemd-escape



The fact that a systemd-escape exists by itself clearly indicates something terribly wrong. If you have never seen or used this command in business, consider yourself lucky.



In practice, the command is used like this :



/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/325792/



All Articles