User Tools

Site Tools


unix:systemd

Systemd cheatsheet

systemctl

"service"

systemctl stop myservice
systemctl start myservice
systemctl restart myservice
systemctl reload myservice
systemctl status myservice

"chkconfig"

systemctl enable myservice
systemctl disable myservice
systemctl is-enabled myservice

"chkconfig --list"

systemctl list-unit-files --type=service

or simply:

systemctl

Reload systemd

Reload systemd, scanning for new or changed units:

systemctl daemon-reload

Restart unit on failure

[Service]
Restart=on-failure
RestartSec=30

cfr systemctl edit

Specifiers

AKA builtin “variables” for unit files(i.e. hostname): see systemd.unit(5)

journalctl

# Logs from last boot
journalctl -b

# Follow logs
journalctl -f

# From kernel
journalctl -k

# From a specific binary
journalctl /usr/bin/pippo

# In reverse order (newest first)
journalctl -r

systemd units in Docker

This requires a fairly recent version of Centos7 / RHEL7

  • If using SElinux enable setsebool -P container_manage_cgroup 1 in the host
  • In the Dockerfile:
    1. Use the latest centos:7 or rhel7 base image
    2. Set the environment variable container=docker
    3. Set STOPSIGNAL to SIGRTMIN+3 to allow for a clean stop
    4. use /sbin/init as a CMD

Example:

FROM centos:7
ENV container docker
STOPSIGNAL SIGRTMIN+3
RUN yum -y install httpd
systemctl enable httpd
EXPOSE 80
CMD [ "/sbin/init" ]
unix/systemd.txt · Last modified: 2018/12/21 09:42 by ap

Informativa sui cookie