Detailed explanation of two ways of Linux service management: service and systemctl

Detailed explanation of two ways of Linux service management: service and systemctl

1.service command

The service command actually goes to the /etc/init.d directory to execute related programs

# The service command starts the redis script service redis start
# Start the redis script directly /etc/init.d/redis start
# Startup update-rc.d redis defaults

We need to write the script ourselves

2.systemctl command

systemd is the latest initialization system (init) of the Linux system. Its function is to increase the system startup speed, start as few processes as possible, and start as many processes concurrently as possible.

The process management command corresponding to systemd is systemctl

1) The systemctl command is compatible with service

That is, systemctl will also go to the /etc/init.d directory to view and execute related programs

systemctl redis start
systemctl redis stop
# Systemctl enable redis

2) The systemctl command manages systemd's resource units

The systemd unit is placed in the directory / usr/lib/systemd/system(Centos)或/etc/systemd/system(Ubuntu)


There are four main types of files: mount, service, target, and want.

.mount File


The .mount file defines a mount point. The configuration of the What, Where, and Type data items in the [Mount] node is equivalent to the following command:

mount -t hugetlbfs /dev/hugepages hugetlbfs

.service file


The .service file defines a service, which is divided into three sections: [Unit], [Service], and [Install]

[Unit]

Description:

After: Start after network.target, auditd.service is started

ConditionPathExists: Execution conditions

[Service]

EnvironmentFile: The file where the variable is located

ExecStart: Execute the startup script

Restart: Restart when fail

[Install]
Alias: Service alias
WangtedBy: Required in multi-user mode

.target file


.target defines some basic components for .service files to call

.wants File


The .wants file defines the set of files to be executed. Each time it is executed, the files in the .wants folder will be executed.

Summarize

The above is the two Linux service management methods service and systemctl introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Linux &, use of nohup and Systemctl
  • Detailed explanation of systemctl command in Linux system
  • SystemC environment configuration method under Linux system

<<:  Realize super cool water light effect based on canvas

>>:  Mybatis mysql delete in operation can only delete the first data method

Recommend

Detailed tutorial on installing mysql 8.0.13 (rpm) on Centos7

yum or rpm? The yum installation method is very c...

SVG+CSS3 to achieve a dynamic wave effect

A vector wave <svg viewBox="0 0 560 20&qu...

The visual design path of the website should conform to user habits

Cooper talked about the user's visual path, w...

Summary of 9 excellent code comparison tools recommended under Linux

When we write code, we often need to know the dif...

How to clean up data in MySQL online database

Table of contents 01 Scenario Analysis 02 Operati...

Example of how to generate random numbers and concatenate strings in MySQL

This article uses an example to describe how MySQ...

Commands to find domain IP address in Linux terminal (five methods)

This tutorial explains how to verify the IP addre...

How to use html2canvas to convert HTML code into images

Convert code to image using html2canvas is a very...

Summary of commonly used time, date and conversion functions in Mysql

This article mainly summarizes some commonly used...

Design theory: people-oriented green design

Reflections on the two viewpoints of “people-orie...

JavaScript article will show you how to play with web forms

1. Introduction Earlier we introduced the rapid d...

How to implement Hover drop-down menu with CSS

As usual, today I will talk about a very practica...