Some useful systemd commands.

Share your own howto's etc. Not for support questions!

Some useful systemd commands.

Postby edbarx » 2015-05-02 08:44

The world is such, that irrespective of one's values and beliefs, one may find oneself faced with having to learn what one may dislike. Posting this doesn't mean I don't appreciate a system employing what GNU/Linux used to be. However, sometimes one may find oneself doing what one never imagines one will do in a thousand years and this is what is happening to me.

I am posting this as a memory aid for myself and others.

First and foremost, systemd has a manpage which can be accessed as usual. Together with that, systemctl also has a manpage. To access them, use the usual: man command.

    Stopping, starting and querying services (daemons):
  • To stop the graphical desktop, ie the X server (I have lightdm installed):
    Code: Select all
    # systemctl stop lightdm.service

    At the time of writing, I was presented with an empty window. Don't panic, access a working terminal by pressing: Ctrl+Alt+F1..F6.

    To restart the graphical desktop do:
    Code: Select all
    # systemctl start lightdm.service

    I am using a resurrected desktop instance right now. This command worked in my case under Jessie.

    To start, say privoxy daemon, use systemctl start daemon.service:
    Code: Select all
    # systemctl start privoxy.service


    To stop, say privoxy daemon, use systemctl stop privoxy.service:
    Code: Select all
    # systemctl stop privoxy.service


    To query the status of a service (daemon):
    Code: Select all
    # systemctl status privoxy.service

    Example:
    If you want to query if udev is running:
    Code: Select all
    # systemctl status udev.service

  • System shutdown, restart, reboot, etc:
    To shutdown the system:
    Code: Select all
    # systemctl poweroff


    To reboot the system:
    Code: Select all
    # systemctl reboot


    To suspend the system:
    Code: Select all
    # systemctl suspend


    To hibernate the system:
    Code: Select all
    # systemctl hibernate

  • Changing the hostname:
    To change the hostname of the local machine:
    Code: Select all
    # hostnamectl set-hostname your-new-host-name

  • To get a listing like dmesg:
    This command is like dmesg (You have to press 'q' to exit the listing.):
    Code: Select all
    # journalctl --dmesg
Last edited by edbarx on 2015-05-02 11:37, edited 5 times in total.
Debian == { > 30, 000 packages }; Debian != systemd
The worst infection of all, is a false sense of security!
It is hard to get away from CLI tools.
User avatar
edbarx
 
Posts: 5389
Joined: 2007-07-18 06:19
Location: 35° 50 N, 14 º 35 E

Re: Some useful systemd commands.

Postby Head_on_a_Stick » 2015-05-02 09:38

The ArchWiki page on systemd is an excellent guide (as usual):
https://wiki.archlinux.org/index.php/Systemd
"Only the mediocre are always at their best." — Jean Giraudoux
User avatar
Head_on_a_Stick
 
Posts: 6790
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Some useful systemd commands.

Postby jesus92gz » 2015-05-26 18:08

How to display debugging messages when restarting services?

I use systemctl restart ssh (for example), but there isn't any debugging output, like in Debian 7.8 running service ssh restart
jesus92gz
 
Posts: 121
Joined: 2015-02-06 18:07

Re: Some useful systemd commands.

Postby Head_on_a_Stick » 2015-05-26 18:15

jesus92gz wrote:How to display debugging messages when restarting services?

Have you tried:
Code: Select all
systemctl status ssh.service

Or use this immediately after you restart the .service:
Code: Select all
journalctl -xn

You will need to add your user to the "systemd-journal" group to view these logs:
Code: Select all
# gpasswd -s <user name> systemd-journal

Log out & back in again to effect this change.

See here for more tips on using journalctl:
http://0pointer.de/blog/projects/journalctl.html
"Only the mediocre are always at their best." — Jean Giraudoux
User avatar
Head_on_a_Stick
 
Posts: 6790
Joined: 2014-06-01 17:46
Location: /dev/chair

Re: Some useful systemd commands.

Postby jesus92gz » 2015-05-26 19:13

Yes, I tried systemctl status ssh and the service's status is being displayed correctly. Then I will have to check if the service restart after running the command.

Thank you.
jesus92gz
 
Posts: 121
Joined: 2015-02-06 18:07


Return to Docs, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 3 guests

fashionable