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

The marquee element implements effects such as scrolling fonts and pictures

The marquee element can achieve simple font (image...

React antd realizes dynamic increase and decrease of form

I encountered a pitfall when writing dynamic form...

Detailed explanation of the use of nohup /dev/null 2>&1

nohup command: If you are running a process and y...

How to quickly install tensorflow environment in Docker

Quickly install the tensorflow environment in Doc...

Example code for implementing beautiful clock animation effects with CSS

I'm looking for a job!!! Advance preparation:...

Free tool to verify that HTML, CSS and RSS feeds are correct

One trick for dealing with this type of error is t...

Example code for CSS to achieve horizontal lines on both sides of the text

This article introduces the sample code of CSS to...

The front-end page pop-up mask prohibits page scrolling

A problem that front-end developers often encount...

How to implement the strategy pattern in Javascript

Table of contents Overview Code Implementation Su...

Implementation and usage scenarios of JS anti-shake throttling function

Table of contents 1. What is Function Anti-shake?...

CSS3 uses the transition property to achieve transition effects

Detailed description of properties The purpose of...

Installing the ping tool in a container built by Docker

Because the Base images pulled by Docker, such as...

VMware Workstation 12 Pro Linux installation tutorial

This article records the VMware Workstation 12 Pr...

Detailed tutorial on installing and using Kong API Gateway with Docker

1 Introduction Kong is not a simple product. The ...