facebook youtube pinterest twitter reddit whatsapp instagram

Managing System Processes (Daemons) In Ubuntu

System processes or Mr. daemons are processes that run in the background on your server, most of the time, they start automatically when your server boots.

An example is the OpenSSH Daemon (sshd) which is the daemon for each incoming connection, it listens to the incoming connection without needing input from the user.

Ubuntu 16.04 and above use systems to manage services, with systems services are known as units. The good thing about systems is that it features lots of great tools for managing the services, an example is systemctl command, which allows users to start, stop, and view the status of units on your server.

We would be using OpenSSH as an example, to check the status of a unit, we would use the status keyword, which shows you information regarding the unit, for example, it shows you whether the unit is active(meaning currently running), enabled (meaning its configured to start at boot time), and a host of others, so, let's check the status of ssh:

systemctl status ssh

Output

user@server:~$ systemctl status ssh
● ssh.service - OpenBSD Secure Shell server
   Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2020-06-17 13:24:59 UTC; 2h 28min ago
  Process: 902 ExecStartPre=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS)
 Main PID: 1070 (sshd)
    Tasks: 1 (limit: 2317)
   CGroup: /system.slice/ssh.service
           └─1070 /usr/sbin/sshd -D

Jun 17 13:24:50 blog.devsrealm.com systemd[1]: Starting OpenBSD Secure Shell server...
Jun 17 13:24:59 blog.devsrealm.com sshd[1070]: Server listening on 0.0.0.0 port 22.
Jun 17 13:24:59 blog.devsrealm.com sshd[1070]: Server listening on :: port 22.
Jun 17 13:24:59 blog.devsrealm.com systemd[1]: Started OpenBSD Secure Shell server.
Jun 17 13:27:31 blog.devsrealm.com sshd[1357]: Accepted publickey for pascal from 192.168.43.205 port 49836 ssh2
Jun 17 13:27:31 blog.dev

You can see how it displays useful information regarding the units, so, in the above output, the name of the ssh unit is actually ssh.service, but it already understood that it is part of the name, so, you don't need to include that.

If the output is condensed, that it is saving the space on the screen, you can append the -l to the see the full log entries, e.g systemctl status -l ssh

Most services in ubuntu will enable it automatically, which means, it would start by itself if your reboot the system, but other services might not, in the case of ssh example above, you can see the vendor preset is set to enabled, which means the next we start the server, ssh will be loaded automatically.

Starting and Stopping a Unit

To stop unit, you use the stop keyword along side the systemctl command, e.g

sudo systemctl stop ssh

and to start, you chang the keyword to start:

sudo systemctl start ssh

The one I like is the restart keyword, this takes care of the start, and stop, it stop the unit, and automatically start it:

sudo systemctl restart ssh

Another useful keyword is the reload command, this is useful with Apache, apache serves web pages to local or remote users, so, you won't want to stop it as this would be disconnected from the website you are serving, so, if you've added some configuration or a new site, and want to only apply the changes you've made with disrupting it from the existing connection, use the reload command:

sudo systemctl reload apache2

If you want to enabled a unit, so, it can start automatically when the server boots, you use the enable keyword, and to disable, you use the disable keyword:

sudo systemctl enable ssh -- to enable

and

sudo systemctl disable ssh -- to disable

The systemd also features a host of other powerful features, I'll write more guide about it in the future.

Related Post(s)

  • Monitoring Multiple Log Files In RealTime With MultiTail (Ubuntu)

    Oh my... I really find scanning through the logs file time consuming, and painful. Luckily for me, I founded Multitail, which is an awesome, and powerful tool for not only browsing through several f

  • How To Find Files Using Locate in Ubuntu

    It's kind of frustrating when you are searching for a particular file, and you have no idea of how to find it, In this guide, I'll walk you through on two different ways you can find a file in your G

  • Managing MariaDB Databases (Ubuntu Server)

    In this guide, you'll learn how to manage MariaDB databases in your terminal, from connecting to the database server using the mariadb command, creating a database, removing (drop) database, and mana

  • Viewing Disk Usage in Ubuntu

    There are several ways to view disk usage in your Linux system, and that is what we would be going over in this guide... Out of the box, Linux provides us the df command, which is the standard Unix c

  • Understanding & Using Symbolic & Hard Links (Ubuntu)

    Have you ever wondered how you can create shortcuts that link to other files in Linux? Well, let me introduce you to symbolic and hard links. The two types of links in Linux are symbolic links and ha

  • Installing and Using dig in Ubuntu

    dig is an awesome utility for querying DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that were queried. In this guide, you'll learn how