Day 7 Task: Understanding package manager and systemctl

TABLE OF CONTENTS
1. What is Package Manager in Linux?
2. What is a Package?
3. Different Kinds of Package Managers
4. Installation of Docker on Ubuntu
5. Installation of Jenkins on Ubuntu
6. Installation of Docker in CentOS
7. systemctl & systemd
8. systemctl Commands
9. service Commands
10. Difference between systemctl & service

What is a package manager in Linux?

A package manager in Linux is a software tool that automates the process of installing, updating, configuring, and removing software packages on a Linux distribution. It simplifies software management by providing a centralized and organized way to handle software installations and dependencies.

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).

📦 Software Packages: Bundles of files that include everything needed to run a program on your computer! 🖥️

  • 📁 Binary Files: Executable files with the actual code of the program. They make the software work. 💻

  • 📚 Libraries: Shared files that help the main program perform various tasks. 📙

  • 🛠️ Configuration Files: Custom settings to personalize how the program behaves. 🔧

What are the different kinds of package managers?

  1. 📦 APT (Advanced Package Tool): Used in Debian-based Linux distributions like Ubuntu, Linux Mint, and Debian itself.

  2. 🍶 dnf (Dandified YUM) and YUM (Yellowdog Updater Modified): Used in Fedora, CentOS, and Red Hat Enterprise Linux (RHEL).

  3. 🍭 Pacman: Used in Arch Linux and its derivatives.

  4. 🦌 zypper: Used in openSUSE Linux.

  5. 🌳 Portage: Used in Gentoo Linux.

  6. 🍺 Homebrew: Used on macOS to manage packages and software.

Task: Install docker and Jenkins in your system from your terminal using package managers:

Installing Docker:

Docker is an open platform for developing, shipping and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

To install docker, I will use the AWS EC2 Ubuntu machine. With the help of official docker documentation, we can easily follow the installation procedure here:

Steps:

Update the apt package index and install packages to allow apt to use a repository over HTTPS:

sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg

Add Docker’s official GPG key:

sudo install -m 0755 -d /etc/apt/keyring
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpgs

Use the following command to set up the repository:

echo 
 "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
 "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
 sudo tee /etc/apt/sources.list.d/docker.list > /dev/null\

Update the apt package index:

sudo apt-get update

To install the latest version, run:

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Verify that the Docker Engine installation is successful by running the hello-world image:

sudo docker run hello-world

This command downloads a test image and runs it in a container. When the container runs, it prints a confirmation message and exits.

Installing Jenkins:

Jenkins is an open-source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat.

To install Jenkins, I will use the AWS EC2 Ubuntu machine. With the help of official Jenkins documentation, we can easily follow the installation procedure here:

Steps:

Add the repository key to your system:

Before installing Jenkins, firstly install Java.

o apt install openjdk-17-jre java -version
 openjdk version "17.0.7" 2023-04-18 OpenJDK Runtime Environment
 (build 17.0.7+7-Debian-1deb11u1) OpenJDK 64-Bit Server
 VM (build 17.0.7+7-Debian-1deb11u1, mixed mode, sharing)

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt update sudo apt install openjdk-17-jre java -version
 openjdk version "17.0.7" 2023-04-18 OpenJDK Runtime Environment
 (build 17.0.7+7-Debian-1deb11u1) OpenJDK 64-Bit Server
 VM (build 17.0.7+7-Debian-1deb11u1, mixed mode, sharing)

Updating the repository:

sudo apt-get update

Installing Jenkins:

sudo apt-get install jenkins

Enabling the Jenkins service to start at boot with the command:

sudo systemctl enable jenkins

Starting the Jenkins service with the command:

sudo systemctl start jenkins

Checking the status of the Jenkins service using the command:

sudo systemctl status jenkins

You should see an output like this:-

Browsing to http://<server_ip>:8080 (or whichever port you configured for Jenkins when installing it) and wait until the Unlock Jenkins page appears.

From the Jenkins console log output, copy the automatically-generated alphanumeric password (between the 2 sets of asterisks). The command will print the password at the console:

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

On the Unlock Jenkins page, paste the password into the Administrator password field and click Continue. Once this is done, post-installation tasks can be done.

systemctl and systemd:

systemd is a system and service manager for modern Linux systems that provides a standard process for controlling system startup and managing system services. systemd is designed to replace the traditional SysV init system, which manages the boot process and runs system services in a sequential manner.

systemctl is a command-line utility that is used to control and manage systemd. It allows you to start, stop, restart, enable, disable, and check the status of system services. systemctl also provides logging and debugging tools to help troubleshoot issues with system services.

Systemd and systemctl work together to provide more efficient and flexible system management for Linux. systemd is designed to improve system boot and shutdown times, provide better resource management, and offer more detailed logging and debugging capabilities. systemctl makes it easy to control and manage system services, simplifying the process of system administration.

Tasks:

  1. Check the status of docker service in your system:

using the following command;

sudo service docker status

the status would look this this:

Difference between "systemctl status docker" & "service docker status"

Both systemctl status docker and service docker status commands are used to check the status of the Docker daemon on a Linux system. However, they differ in the way they interact with the system's init system.

systemctl is the default init system manager in most modern Linux distributions that use systemd. It is a command-line utility that provides a system and service manager for Linux systems. The systemctl status command is used to display the status of a particular service in the systemd unit hierarchy.

On the other hand, service is an older init system manager that is still used on some Linux distributions. The service command is used to control the system services and their status. It is used to manage the services in the /etc/init.d directory.

In summary, the main difference between systemctl status docker and service docker status is the underlying init system manager they use. If your Linux distribution uses systemd, then you should use systemctl to interact with the system services. If your distribution uses the older init system manager, you should use service to interact with the system services.

0
Subscribe to my newsletter

Read articles from Ankit Kumar Jaiswal directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ankit Kumar Jaiswal
Ankit Kumar Jaiswal