In Linux, a daemon is a process that runs in the background without direct user involvement. Daemons are part of the operating system and provide a number of functions, such as network services, disk services, print services, etc.
They are usually started at system startup and remain active in the background until the system is shut down. They do not have a direct user interface and are usually managed via configuration files or command line commands.
Daemons in Linux usually have a name ending with the letter "d", for example, httpd, named and sshd. They are run using special commands such as systemctl, service, or daemon. They are an important part of the Linux operating system because they provide functionality and operability of various services and applications in the background.
Daemons in Linux can be started in several ways. Let's look at the most common startup methods.
Using the "service" command, you can start, stop and restart the daemon on Linux systems using init scripts. For example, to run the Apache HTTP Server daemon, you need to run the following command:
sudo service apache2 start
The "systemctl" command is used to control daemons on Linux systems using systemd. For example, to run the SSH daemon, you need to run the following command:
sudo systemctl start sshd
In some Linux distributions, daemons can be run via init scripts, which are located in the /etc/init.d directory. For example, to run the MySQL daemon, you need to run the following command:
sudo /etc/init.d/mysql start
On Linux systems using systemd, it is recommended to use unit files to run daemons. Unit files are text files that contain a description of the service or process that needs to be started on the system. They specify the daemon startup parameters, such as user, group, working directory, startup command, and other options.
Unit files are stored in the /etc/systemd/system/ directory. In this directory, you can create your own unit files or modify existing ones. After creating or modifying the unit file, you need to reboot systemd using the systemctl daemon-reload command for the changes to take effect.