Understanding package manager and systemctl
Shubham Deshpande
Associate Cloud Engineer @SELA | AWS Solutions Architect Associate| GCP Associate Cloud Engineer | Aspiring DevOps
What is a package manager in Linux?
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.
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.
What are the 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.
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.
Here is the output of the same on the ec2 instance which I created for testing purposes:
For installing docker on CentOS, please follow this documentation
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:
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
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
If everything has been set up correctly, you should see an output like this:
Browsing to https://<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:
using the following command;
sudo service docker status
the status would look this this:
2. stop the service Jenkins and post before and after screenshots:
Before:
After stopping the service:
Using the command "sudo service jenkins stop", the status of the Jenkins service would look like 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.