๐Ÿ”ง๐Ÿš€ DevOps 1.4: Unraveling Services and Processes

"Managing Services and Processes in DevOps: Understanding the Heartbeat of Systems"

ยท

5 min read

๐Ÿ”ง๐Ÿš€ DevOps 1.4: Unraveling Services and Processes

Services in Linux:

In Linux, services are background programs that run automatically when your system starts. They manage various tasks, like handling network connections or running applications. For example, the "SSH" service allows remote login to a computer, while the "Apache" service powers web servers. Services ensure essential functions are always available, making your system efficient and user-friendly.

Earlier we installed a package httpd: Let's check that -

So we had earlier installed a package name httpd which can be managed by the systemctl command -

systemctl is a command in Linux used to control and manage systemd services, which are background processes that handle various system tasks. It allows users to start, stop, enable, disable, and check the status of services, making system administration more efficient. For more understanding checkout the below

systemctl status httpd - Shows the status of the the service

As you can see the status is inactive. Now if you want to start the service we can use systemctl start httpd.

systemctl restart httpd - This command will restart the httpd service.

systemctl reload httpd - Unlike the restart command, the reload command doesn't stop and start the service. Instead, it causes the web server to reload its configuration files and apply any changes without interrupting active connections.

NOTE: While booting up, this service will not come up.

To get the service at the boot time:

systemctl enable httpd - After booting up service will come up. Use this command before booting up and then start the service.

Few Other Commands:

systemctl is-active httpd : To check if the service is active.

sytemctl is-enabled httpd: To check if the service is enabled for the boot time or not.

The way systemct works is based on its configuration file.

In Linux, the systemctl command is used for controlling and managing systemd units, which can be services, sockets, devices, etc. Systemd units are defined using configuration files that are typically stored in the /etc/systemd/system/ directory.

[root@bazinga ~] cat /etc/systemd/system/multi-user.target.wants/httpd.service 
# See httpd.service(8) for more information on using the httpd service.

# Modifying this file in-place is not recommended, because changes
# will be overwritten during package upgrades.  To customize the
# behaviour, run "systemctl edit httpd" to create an override unit.

# For example, to pass additional options (such as -D definitions) to
# the httpd binary at startup, create an override unit (as is done by
# systemctl edit) and enter the following:

#    [Service]
#    Environment=OPTIONS=-DMY_DEFINE

[Unit]
Description=The Apache HTTP Server
Wants=httpd-init.service
After=network.target remote-fs.target nss-lookup.target httpd-init.service
Documentation=man:httpd.service(8)

[Service]
Type=notify
Environment=LANG=C

ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND # This the binary which runs with some options when we start the service
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
# Send SIGWINCH for graceful stop
KillSignal=SIGWINCH
KillMode=mixed
PrivateTmp=true
OOMPolicy=continue

[Install]
WantedBy=multi-user.target
[root@bazinga ~]#

Linux Processes:

In Linux, processes are like tasks that your computer runs to accomplish various things. Just like how you might have different apps open on your phone, each doing its own job, your computer runs processes to handle tasks such as running programs, managing files, or handling network connections. Every process has its own space to work in and interacts with the computer's resources, like memory and CPU. Linux is really good at managing these processes, making sure they run smoothly and efficiently, just like a conductor in an orchestra making sure all the instruments play in harmony.

top - It provides a real-time overview of the system's resource utilization and running processes.

  • System Information:

    • Uptime: Displays how long the system has been running.

    • Load Average: This shows the system's average workload over different time periods.

  • Tasks Information:

    • Total Tasks: Number of running processes.

    • Running Tasks: Processes currently executing.

    • Sleeping Tasks: Processes in a waiting state.

    • Stopped Tasks: Processes paused or stopped.

    • Zombie Tasks: Processes that have finished but not been cleaned up.

  • CPU Usage:

    • CPU Usage: Percentage of CPU being used.

    • CPU States: Breakdown of CPU activity (user, system, idle, etc.).

  • Memory Usage:

    • Total Memory: The system's total available RAM.

    • Used Memory: How much RAM is currently in use?

    • Free Memory: Available, unused RAM.

    • Buffers and Cache: Memory used for temporary data storage.

  • Process List:

    • Process ID (PID): Unique identification for each process.

    • User: Owner of the process.

    • CPU %: Percentage of CPU used by the process.

    • Memory %: Percentage of memory used by the process.

    • Command: Name of the command or program being executed.

ps aux - It just displays the information and quits.

ps -ef - It shows the parent process id and some extra information. In the below image, you can see PID 1 has PPID 0 which is not present because it's dead or it has completed its execution.

ps -ef | grep httpd - Show the processes which have httpd word in it.

ps -ef | grep httpd | grep -v 'grep' - Show the processes which have httpd in it excluding the word grep from it.

kill <process id> - It will kill the process with that id and all the processes derived from it. E.g. kill 764 It will kill all the process.

kill -9 <process id> - It will force kill that process, but it may or may not kill its child processes depending upon the system. The child processes become orphan and it gets adopted by the systems processes.

ps -ef | grep httpd | grep -v 'grep' | awk '{print $2}' - Prints column 2 of the table.

ps -ef | grep httpd | grep -v 'grep' | awk '{print $2}' | xargs kill -9 - It takes column 2 as an argument and deletes the processes.

NOTE - You can identify the zombie process by seeing status Z. Best way to clear the zombie process is to reboot your machine.

Conclusion:

๐Ÿ”ง๐Ÿ”„ In the world of Linux and DevOps, understanding services and processes is like unraveling the heartbeat of your system. From systemctl commands to managing processes, you've gained insights into the core of system management. Now you're ready to orchestrate with confidence! ๐Ÿ’ป๐Ÿš€ #DevOps #Linux #SystemManagement.

"Managing services and processes in Linux is a piece of cake, said - no one ever! ๐Ÿฐ๐Ÿ”ฅ #LinuxChallenges"

Did you find this article valuable?

Support Chronicles of Tech ๐Ÿ“š๐Ÿ’ป by becoming a sponsor. Any amount is appreciated!

ย