systemd


The init system that has now made its way into most distributions. systemd refers to services as “units”.

Service and Daemon Management

Status

$ systemctl status postgresql
● postgresql.service - PostgreSQL database server
   Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2017-02-16 04:03:23 AEDT; 2 days ago
  Process: 1170 ExecStart=/usr/libexec/postgresql-ctl start -D ${PGDATA} -s -w -t ${PGSTARTTIMEOUT} (    code=exited, status=0/SUCCESS)
  Process: 1157 ExecStartPre=/usr/libexec/postgresql-check-db-dir %N (code=exited, status=0/SUCCESS)
 Main PID: 1201 (postgres)
    Tasks: 7 (limit: 4915)
   CGroup: /system.slice/postgresql.service
           ├─1201 /usr/bin/postgres -D /var/lib/pgsql/data
           ├─1236 postgres: logger process   
           ├─1240 postgres: checkpointer process   
           ├─1241 postgres: writer process   
           ├─1242 postgres: wal writer process   
           ├─1243 postgres: autovacuum launcher process   
           └─1244 postgres: stats collector process   

Feb 16 04:03:22 think.local systemd[1]: Starting PostgreSQL database server...
Feb 16 04:03:22 think.local postgresql-ctl[1170]: LOG:  redirecting log output to logging collector process
Feb 16 04:03:22 think.local postgresql-ctl[1170]: HINT:  Future log output will appear in directory "pg_log".
Feb 16 04:03:23 think.local systemd[1]: Started PostgreSQL database server.

A good dose of process information, including the last 4 lines of logs.

Start Stop Reload Restart

Services can be managed on-demand with the start, stop, reload and restart commands.

systemctl start nginx etcd3

reload will cause a units configuration files to be re-read.

Start at boot

systemd will start daemons at boot time, given the have been enabled, either through the enable or disable commands.

systemctl enable postgresql etcd3

Log Management

Documentation

systemd-journald.service(8) rsyslog(8) rsyslog.conf(5)

The systemd-journald daemon collects messages from the kernel, boot process, stdout and stderr, and syslog, placing them in a neatly organised events journal. rsyslog (unrelated to systemd) also subscribes to syslog events, and persists them into /var/log.

journalctl -u postgresql

journalctl -xn

journalctl -b journalctl -f journalctl –since “10 min ago”