Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to start and shut down system service under Linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to start and shut down system services under Linux". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to start and shut down system services under Linux.

Early service management used the mechanism of systemV to manage the startup / shutdown / default startup of services through / etc/init.d/*, service, chkconfig, setup, etc.

Starting from CentOS 7.x, the systemd mechanism is adopted, the maximum function of this mechanism is parallel processing, and a single instruction management (systemctl) is adopted to speed up the boot!

Example 1: what is the current status of the atd service? [root@study] # systemctl status atd.serviceatd.service-Job spooling toolsLoaded: loaded (/ usr/lib/systemd/system/atd.service; enabled) Active: active (running) since Mon 2015-08-10 19:17:09 CST 5h 42min agoMain PID: 1350 (atd) CGroup: / system.slice/atd.service └─ 1350 / usr/sbin/atd-fAug 10 19:17:09 study.centos.vbird systemd [1]: Started Job spooling tools.# focuses on the second and third lines oh # Loaded: this line explains whether the unit will start when you boot, and enabled will start when you boot. Disabled boot will not start # Active: now the unit is executing (running) or not (dead) # the next few lines indicate the PID status of the unit program and the last line shows the login file information for the service! # the login file information format is: "time", "message sending host", "which service message", "actual message content" # so the above display message is: this atd starts by default and is running now! Example 2: shut down the atd service normally [root@study ~] # systemctl stop atd.service [root@study ~] # systemctl status atd.serviceatd.service-Job spooling toolsLoaded: loaded (/ usr/lib/systemd/system/atd.service; enabled) Active: inactive (dead) since Tue 2015-08-11 01:04:55 CST 4s agoProcess: 1350 ExecStart=/usr/sbin/atd-f $OPTS (code=exited, status=0/SUCCESS) Main PID: 1350 (code=exited, status=0/SUCCESS) Aug 10 19:17:09 study.centos.vbird systemd [1]: Started Job spooling tools.Aug 11 01:04:55 study.centos.vbird systemd [1]: Stopping Job spooling tools...Aug 11 01:04:55 study.centos.vbird systemd [1]: Stopped Job spooling tools.# this unit will still start next time, but it is not running now.

Systemd defines each service as unit, while unit is classified into different categories, such as service, socket, target, path, timer, etc., which is convenient for management and maintenance.

Start / shut down / restart: systemctl [start | stop | restart] unit.service

Set the default startup / default no startup mode: systemctl [enable | disable] unit.service

Query all started services of the system using systemctl list-units-type=service and query all services (including non-startup) using systemctl list-unit-files-- type=service

Systemd removes the previous concept of runlevel (although there is still a compatible target) and uses a different target operating environment instead. Common operating environments are multi-user.targer and graphical.target. Switch to a different operating environment without rebooting to use systemctl isolate unit.target, while setting the default environment uses systemctl set-default unit.target

The default configuration file of the systemctl system is mainly placed in / usr/lib/systemd/system. If the administrator wants to modify or design by himself, it is recommended to put it in the / etc/systemd/system/ directory.

Administrators should use man systemd.unit, man systemd.service, man systemd.timer to query / etc/systemd/system/ the following configuration file syntax, and use systemctl daemon-reload to load before they can write their own services and management services!

In addition to atd and crond, the time management function of systemd can be used through the function of systemd.timer, that is, timers.target.

At this point, I believe you have a deeper understanding of "how to start and shut down system services under Linux". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report