Systemd now brings logging to one swift program called journalctl & service management to a program called systemctl.

Starting Stopping Services (before systemd this was done with the “service” command or using /etc/init.d/. With systemd installed you can still use /etc/init.d to start services as its just scripts so they will start the actual programs/services for you)

# start service
systemctl start smb
# stop service
systemctl stop smb
# restart service
systemctl restart smb
# reload service
systemctl reload smb
# make service launch on boot
systemctl enable smb
# make service not launch on boot
systemctl disable smb
# check status of service (there is alot of nice information here, including latest logs)
systemctl status smb
# NOTE: services are stored in /lib/systemd/system
# NOTE: services that are started on boot, are symlinked from here, to the above folder: /etc/systemd/system/multi-user.target.wants
# NOTE: multi-user.target.wants, represents the default run level
# show services:
systemctl
# no pager
systemctl -a --no-pager
# same way to achieve no pager (pipe to another command, and it will auto remove the pager - "grep ." discards empty lines, showing only lines with text, useful for screen realestate)
systemctl -a | grep .
# show all service files which are installed
systemctl list-unit-files
# if you edit a /lib/systemd/system file (a unit file/ a service file), then you need to reload it into systemd using this, after that you can do things like "restart","start","stop",etc to that service:
systemctl --system daemon-reload

Looking at logs (All system logs are saved into the journal now, also saved on /var/log/, but in a journal folder which has binary data)

# view logs (each line is short)
journalctl
# view logs with normal line lengths (lines are not contracted), get used to always running -a (For all), a for "showing All of the line".
journalctl -a
# to remove pager (note the pager is removed when command is piped to another one)
journalctl -a --no-pager
# or less words (also no pager & skips blank lines - "grep ." shows only lines with text, so empty lines are discarded)
journalctl -a | grep .
# following the log (synonymous with "tail -f /var/log/syslog"), f for "Following"
journalctl -fa
# follow the log, but also show the 1000 lines before now. n for "Number of lines"
journalctl -fan1000
# show the 100 latest lines of logs
journalctl -an100
# viewing a specific service (kind of like grepping, you can achieve same result with grep). assuming atop is the process we want to monitor
journalctl -a  _SYSTEMD_UNIT=atop.service
# can achieve similar results with
journalctl -a | grep atop

Writing your own systemd service files, and starting them on boot (or whenever you want) using systemctl:

http://www.infotinks.com/readynas-6-x-start-srevice-may-void-warranty/

http://patrakov.blogspot.com/2011/01/writing-systemd-service-files.html

https://coreos.com/docs/launching-containers/launching/getting-started-with-systemd/

Leave a Reply

Your email address will not be published. Required fields are marked *