Day 7 - Understanding Package Manager and systemctl

Day 7 - Understanding Package Manager and systemctl

What is a package manager in Linux?

In simpler words, a package manager is a tool that allows users to install, remove, upgrade, configure and manage software packages on an operating system. The package manager can be a graphical application like a software center or a command line tool like apt-get or Pacman.

You’ll often find me using the term ‘package’ in tutorials and articles, To understand package manager, you must understand what a package is.

What is a package?

A package is usually referred to as an application but it could be a GUI application, command line tool or a software library (required by other software programs). A package is essentially an archive file containing the binary executable, configuration file and sometimes information about the dependencies.

Different kinds of package managers

Package Managers differ based on the packaging system but the same packaging system may have more than one package manager.

For example, RPM has Yum and DNF package managers. For DEB, you have apt-get, aptitude command line-based package managers.

Tasks

  1. You have to install docker and Jenkins in your system from your terminal using package managers

  2. Write a small blog or article to install these tools using package managers on Ubuntu and CentOS

Solution:-

1.) You have to install docker and Jenkins in your system from your terminal using package managers

Install Docker

  1. Open your terminal and update the package list.
sudo apt update
  1. Install the Docker package.
sudo apt install docker.io
  1. Verify that Docker is installed and running.
sudo systemctl status docker

Install Jenkins

  1. Open your terminal and update the package list.
sudo apt update
  1. Install the Jenkins package.
sudo apt install jenkins
  1. Start the Jenkins service.
sudo systemctl start jenkins
  1. Open a web browser and navigate to http://localhost:8080.

  2. You will be prompted to create a new administrator user.

  3. Once you have created a new administrator user, you can start using Jenkins.

Install Jenkins in Docker

You can also install Jenkins in Docker. This is a good option if you want to run Jenkins in a containerized environment.

To install Jenkins in Docker, you will need to have Docker installed on your system. Once you have Docker installed, you can follow these steps:

  1. Create a Dockerfile.
FROM jenkins/jenkins:lts-jdk11
  1. Build the Docker image.
docker build -t jenkins .
  1. Run the Docker image.
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins

The -p 8080:8080 and -p 50000:50000 options map the ports 8080 and 50000 in the container to the same ports on the host machine. This allows you to access the Jenkins web interface on port 8080 of your host machine.

The -v jenkins_home:/var/jenkins_home option mounts a volume named jenkins_home in the container to the /var/jenkins_home directory on the host machine. This allows Jenkins to persist its data even after the container is stopped or restarted.

Once the Docker image is running, you can access the Jenkins web interface on port 8080 of your host machine.

systemctl and systemd

systemctl is used to examine and control the state of “systemd” system and service manager. systemd is a system and service manager for Unix-like operating systems(most of the distributions, not all).

Tasks

  1. Check the status of the docker service in your system (make sure you completed the above tasks, else docker won't be installed)

  2. Stop the service Jenkins and post before and after screenshots

  3. Read about the commands systemctl vs service

Solution:-

1.) Check the status of the docker service in your system (make sure you completed the above tasks, else docker won't be installed)

These are commands to check the status of the Docker service on different operating systems:

  • Linux:
sudo systemctl status docker
  • Windows:
sc query docker
  • macOS:
systemctl status docker

Once you have the command for your operating system, run it in your terminal. The output of the command will tell you the status of the Docker service.

2.) Stop the service Jenkins and post before and after screenshots

To stop the Jenkins service in Linux, you can use the following command:

sudo systemctl stop jenkins

This will stop the Jenkins service immediately. If you want to wait for any running jobs to finish before stopping Jenkins, you can use the following command:

sudo systemctl stop jenkins --wait

Once the Jenkins service is stopped, you can verify that it is stopped by running the following command:

sudo systemctl status jenkins

The output of the command should show that the Jenkins service is "inactive".

3.) Read about the commands systemctl vs service

eg. systemctl status docker vs service docker status

systemctl and service are both commands used to manage services in Linux. However, they are different in a few ways.

  • systemctl is the newer command and is part of the systemd init system. systemd is the default init system on most Linux distributions.

  • service is the older command and is part of the SysV init system. SysV init was the default init system on older Linux distributions, but it is slowly being replaced by systemd.

systemctl has a wider range of features than service. For example, systemctl can be used to manage units other than services, such as sockets and devices. systemctl can also be used to query the status of services and units.

service is a simpler command than systemctl. It can only be used to manage services. However, service is often easier to use than systemctl, especially for basic tasks such as starting, stopping, and restarting services.

In general, it is recommended to use systemctl if you are using a systemd-based distribution. However, you can still use service if you are comfortable with it.

Let me know if you have any other queries.

Thank You

If you liked this blog then click on ❤

and do follow for more interesting and helpful blogs.

Did you find this article valuable?

Support Anurag Dutt by becoming a sponsor. Any amount is appreciated!