SystemD

Starting with version 16.04, the initialization system in Ubuntu has changed. Sometimes this leads to a 502 error because the iBatyr Monitor service does not start automatically. To solve this problem, you need to explicitly allow this unit to run. sudo systemctl enable ibatyr

Other commands for units: Start a unit immediately:

systemctl start unit

Stop the unit immediately:

systemctl stop unit

Restart unit:

systemctl restart unit

Request a unit to reload its settings:

systemctl reload unit

Show the status of the unit, and whether it is running or not:

systemctl status unit

Check whether the unit is included in autostart when the system boots:

systemctl is-enabled unit

Enable the unit to autostart when the system boots:

systemctl enable unit

Remove a unit from autostart when the system boots:

systemctl disable unit

Mask a unit to make it impossible to launch it:

systemctl mask unit

Remove unit mask:

systemctl unmask unit

Show the man page associated with a unit (this feature must be supported in the specified unit file):

systemctl help unit

Reload systemd to search for new or changed units:

systemctl daemon-reload

all logs since the last download

journalctl -b

filter by date.

$ journalctl ---since yesterday
$ journalctl --since 09:00 --until now
$ journalctl --since 10:00 --until "1 hour ago"

filter by service

journalctl -u nginx.service

by service over a period of time.

journalctl -u nginx.service –since yesterday

journalctl -u nginx.service -u php-fpm.service —since today

by ID

journalctl _PID=381

by ID

journalctl _UID=33

who is in the logs

journalctl -F _UID

all filters

man systemd.journal-fields

look along the way

journalctl /usr/bin/docker

what’s in the core

journalctl -k

by error level

journalctl -k

the errors are:

  • 0 — EMERG (system is inoperative);

  • 1 — ALERT (immediate intervention required);

  • 2 - CRIT (critical condition);

  • 3 - ERR (error);

  • 4 - WARNING (warning);

  • 5 - NOTICE (everything is fine, but you should pay attention);

  • 6 — INFO (information message);

  • 7 - DEBUG (delayed printing).

output without less

journalctl --no-pager

log formats.

journalctl  -u nginx.service -o json

like this

  • cat — only messages from logs without service fields;

  • export - binary format, suitable for exporting or backing up logs;

  • short — syslog output format;

  • short-iso - syslog output format with timestamps in ISO 8601 format;

  • short-monotonic — syslog output format with monotonic timestamps;

  • short-precise — syslog output format with precise time stamps (event times are indicated with microsecond precision);

  • verbose - the most detailed format for presenting data (even includes those fields that are not displayed in other formats).

recent

journalctl -n

real time

journalctl -f

how many logs?

journalctl --disk-usage

compress logs to

sudo journalctl --vacuum-size=1G

compress logs by time

sudo journalctl --vacuum-time=1years

the same in the conf file

/еtc/systemd/journald.conf, which contain next parameters:
  • SystemMaxUse = maximum volume that logs can occupy on disk;

  • SystemKeepFree = amount of free space that should remain on the disk after saving logs;

  • SystemMaxFileSize = size of the log file, upon reaching which it should be deleted from the disk;

  • RuntimeMaxUse = maximum size that logs can occupy in the file system /run;

  • RuntimeKeepFree = amount of free space that should remain in the /run file system after saving logs;

  • RuntimeMaxFileSize = size of the log file, upon reaching which it should be deleted from the file system /run.

Centralized log storage

systemd-journal-remote --url https://some.host:19531/