Linux - Introduction to the service command

The service command is used to manage system services, such as start (start), stop (stop), restart (restart), view status (status), etc. Related commands also include chkconfig, ntsysv, etc. chkconfig is used to view and set the running level of the service, and ntsysv is used to intuitively and conveniently set whether each service is automatically started. The service command itself is a shell script that looks for the specified service script in the /etc/init.d/ directory, and then invokes the service script to complete the task.

The inside story of the service: When the service runs the specified service (called the System V initial script), most of the environment variables are removed, only the two environment variables of LANG and TERM are retained, and the current path is set to /, that is to say, in the Run service scripts in a predictably very clean environment.

When running the service mysql start command, linux actually executes the /etc/init.d/mysql script. For the script called by the service, it must support at least two parameters, start and stop.


common way

Format: service <service>

 

Print command-line usage help for the specified service <service>.

 

Format: service <service> start

 

Start the specified system service <service>

 

Format: service <service> stop

 

Stop the specified system service <service>

 

Format: service <service> restart

 

Restart the specified system service <service>, that is, stop (stop) and then start (start).

 

Format: chkconfig --list

 

View a list of system services, and the runlevel of each service.

 

Format: chkconfig <service> on

 

Set the specified service <service> to start automatically when it is powered on.

 

Format: chkconfig <service> off

 

Set the specified service <service> not to start automatically when it is powered on.

 

Format: ntsysv

 

Set whether to automatically start the service when it is powered on in a full-screen text interface.


Using the example
example one network restart

When the host name, ip address and other information are modified, it is often necessary to restart the network to make it take effect.

[root@node34 root]# service network restart
Shutting down interface eth0: [OK]
Shutting down loopback interface: [OK]
Setting network parameters: [OK]
Popup loopback interface: [OK]
Popping up interface eth0: [OK]
[root @node34 root]#


Example 2 Restart MySQL

[root@node34 root]# service mysqld status
mysqld (pid 1638) is running...
[root@node34 root]# service mysqld restart
Stop MySQL: [OK]
Start MySQL: [OK]
[root@node34 root]#

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326644868&siteId=291194637