Service management of source package installation under Linux

Service management of source package installation under Linux

1. Startup management of source package service

# Find the startup script of the service through the installation path of the source package.
# That is, get the absolute path of the startup script of the service,
# Finally add the startup options.
[root@localhost ~]# /usr/local/apache2/bin/apachectl start|stoplrestart|...

Notice:

When installing services using source packages, the startup scripts for each service are different.

How do we know the name of a service's startup script?

In the official installation document, you will be clearly told the name of the startup script for the service.

Example of starting the service:

illustrate:

The error message says that the host name localhost.localdomain is not recognized, but there is no problem starting the Apache service.

Check whether the apache service is enabled by running the command ps aux | grep httpd .

As shown in the following figure:

2. Self-start management of source package service

By configuring the /etc/rc.d/rc.local configuration file, you can implement self-start management of services installed through source packages.

This method is universal and can be used regardless of whether the service is installed with a source package or an RPM package. The key is whether you write the service startup command for the source package or the service startup command for the RPM package in the /etc/rc.d/rc.local configuration file.

Therefore, it is recommended to use configuration files to manage services in a universal and unified way in Linux systems.

Example:

# Configure the /etc/rc.d/rc.local configuration file [root@localhost ~]# vim /etc/rc.d/rc.local

# Modify the content of the startup file #!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/local/apache2/bin/apachectl start

3. Make the source package service recognized by the service management command

Next, we will do an experiment to make the apche service installed through the source package the same as the apache service installed through the RPM package, which can be recognized by service , chkconfig , and ntsysv commands.

The problem we want to solve is as follows:

(1) Allow services installed through source packages to be managed and started by the service command

service command actually just searches the /etc/rc.d/init.d/ directory for a startup script for the service, so we only need to make a soft link and link the startup script of the source package to the /etc/rc.d/init.d/ directory, and it can be managed by service command.

# Make a soft link to the startup script of the service installed through the source package in the /etc/rc.d/init.d/directory [root@localhost ~]# ln -s /usr/local/apache2/bin/apachectl /etc/rc.d/init.d/apachectl

Check the contents of /etc/rc.d/init.d/ , as shown in the following figure:

Run service apachectl restart command to start the apche service.

It can be seen that apche service can be started through the service command, and no unrecognized service error is reported.

(2) Allow services installed through source packages to be managed and started automatically by the chkconfig command

Following the previous step, you then need to configure the startup scripts of the services installed through the source package that are soft-linked to the /etc/rc.d/init.d/ directory.

# Edit the source package startup script in the /etc/rc.d/init.d/ directory# (Note that this file is a soft link, so the source package startup script is still modified)
[root@localhost ~]# vim /etc/rc.d/init.d/apachectl

# Add the following content at the beginning #!/bin/sh
# Add content-1
# Specify that the httpd script can be managed by the chkconfig command # The format is: chkconfig: run level startup order shutdown order # Here we set apache to be managed by the chkconfig command at levels 3 and 5, the startup order is S86, and the shutdown order is K76
# Note: (Set your own order, do not conflict with the order of existing startup programs in the system)
# chkconfig:35 86 76
#
# Add content-2
# Description, any content# description: aaabbbccc

#The above two sentences must be added to be recognized by the chkconfig command.

Then enable chkconfig command to manage the services installed by the source package.

[root@localhost ~]# chkconfig --add apachectl

No error indicates success.

Use the chkconfig command to view the self-starting services in Linux.

As shown in the following figure:

Then you can use the chkconfig command to enable the automatic startup state of the service.

(3) Allow the ntsysv command to manage services installed through source packages

The ntsysv command actually uses the same management mechanism as the chkconfig command. That is to say, the chkconfig command above can manage services installed by the source package, and the ntsysv command can also manage services installed by the source package.

Execute the [root@localhost ~]# ntsysv command and you can find the apache service we just configured above in the graphical interface.

(4) Summary

If you want the source package service to be recognized and managed by service command, just make a soft link to link the startup script to the /etc/rc.d/init.d/ directory.

In order to make the source package service recognized by the chkconfig command, in addition to linking the service startup script to the /etc/rc.d/init.d/ directory, you also need to modify the startup script and add the following to the beginning of the startup script:

# chkconfig : run level, startup order, shutdown order.

# description : Description information. Then you need to use chkconfig --add 服務名method to add the service to chkconfig command management.

The command format is as follows:

[root@localhost ~]# chkconfig [options] [service name]

Options:
  --add: Add the service to the management of the chkconfig command.
  --del: Delete the service from the management of the chkconfig command.

# Example:
# Delete the apache service from the chkconfig command management [root@localhost ~]# chkconfig -del httpd

After the chkconfig command configuration is completed, the ntsysv command can also manage the service.

hint:

Just know that services installed with source packages can be handled this way, but it is not recommended. For services installed through source code packages, just start the services using the source code packages. For services installed through RPM packages, just start the services using the RPM packages. This is great.

This is the end of this article about service management of source code package installation under Linux. For more relevant Linux source code package installation management content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  Toolkit: A more powerful front-end framework than Bootstrap

>>:  Introduction to the usage of exists and except in SQL Server

Recommend

Detailed explanation of the usage of DECIMAL in MySQL data type

Detailed explanation of the usage of DECIMAL in M...

MySQL table addition, deletion, modification and query basic tutorial

1. Create insert into [table name] (field1, field...

Graphic tutorial on installing Ubuntu 18.04 on VMware 15 virtual machine

In the past few years, I have been moving back an...

Master the commonly used HTML tags for quoting content in web pages

Use blockquote for long citations, q for short ci...

Web Design Experience: Self-righteous Web Designers

1. Trash or Classic? Web technology updates very ...

Solution to CSS anchor positioning being blocked by the top fixed navigation bar

Many websites have a navigation bar fixed at the ...

Summary of Linux file basic attributes knowledge points

The Linux system is a typical multi-user system. ...

Detailed explanation of MySQL index principles and optimization

Preface This article was written by a big shot fr...

Installation and use tutorial of Elasticsearch tool cerebro

Cerebro is an evolution of the Elasticsearch Kopf...

Summary of various common join table query examples in MySQL

This article uses examples to describe various co...

MySQL tutorial thoroughly understands stored procedures

Table of contents 1. Concepts related to stored p...

How to control the proportion of Flex child elements on the main axis

background Flex layout achieves alignment and spa...

Perfect solution for vertical centering of form elements

Copy code The code is as follows: <!DOCTYPE ht...

Detailed explanation of MySQL deadlock and database and table sharding issues

Record the problem points of MySQL production. Bu...