How to set the Service Startup command in Linux

Source: Internet
Author: User

This article describes in detail the commands and methods for Setting Automatic startup of the startup service in linux, including ntsysv, chkconfig, # setup, and commands added to rc. for more information about the local method, see.

Method 1: ntsysv

Similar to the msconfig tool in windows, it is used to set whether the service is started randomly. You can use ntsysv to start or close services managed by xinetd, or use ntsysv to configure the running level. Services managed by xinetd will be immediately affected by ntsysv, and other services will not take effect immediately. You must use the service xxxxx stop/start/restart command to stop/run/restart a service. (Replace xxxxxx with the name of the service you want to stop .)

The Code is as follows: Copy code
# Ntsysv
# Service network retart
"Service Usage: service name (start/restart/stop/status )"

Problems I have encountered:
Once I tried to use the command # serverce iptables start to start the firewall, but I couldn't start it. Finally, I used the ntsysv command. After iptables is selected, I can run service iptables start to start the firewall normally.

Method 2: chkconfig

Chkconfig is used to manage the services started during system initialization. The Chkconfig command can be used to activate or stop a service, or set to enable a service to start at random. However, the chkconfig command does not automatically disable or activate a service immediately. It simply changes the symbolic connection.
The usage instructions are as follows:
Function Description: Check and set various services of the system.
Syntax: chkconfig
[-- Add] [-- del] [-- list] [System Service] Or chkconfig [-- level <level code>] [System Service] [on/off/reset]
Parameters:
-Add adds the specified system service, enables the chkconfig command to manage it, and adds relevant data in the system startup description file.
-Del: deletes the specified system service. It is no longer managed by the chkconfig command, and relevant data is also deleted in the description file started by the system.
-Level <level code> specifies the execution level of the read System Service
1: The chkconfig command can also be used to activate and remove services. The chkconfig-list command displays the list of system services, and whether these services have been started (on) or stopped (off) in the running level from 0 to 6 ).

The Code is as follows: Copy code
Chkconfig-add smb # add smb service
Chkconfig-list | grep smb
Chkconfig-list smb
Smb 0: off 1: off 2: on 3: on 4: on 5: on 6: off

2: chkconfig can also be used to set whether a service is started or stopped at a specified running level. For example, to stop the samba service at runtime Level 3 and 5, run the following command:
Chkconfig-level 35 smb off
3: services managed by xinetd are immediately affected by chkconfig. For example, if xinetd is running and finger is disabled, after the chkconfig finger on command is executed, finger does not have to manually restart xinetd to be enabled immediately. Changes to other services do not take effect immediately after chkconfig is used. You must use the service servicename start/stop/restart command to restart the service.

Method 3:Configure the Automatic startup of SAMBA through service configuration. This method is omitted in the graphic interface.
Conclusion: Both ntsysv and chkconfig can make the services managed by xinetd take effect immediately, while other services need to run
# Service xxxx restart to take effect.

Method 4:

Enter the # setup command to enter the system service menu, select the service you want to start, such as httpd, and restart the machine or/etc/rc. d./init. d/httpd
Start

Method 5:

(2)
Put the startup command in/etc/rc. d/rc. in the local file, the service can be automatically started every time it is started. For example, for apache, after compiling apache, The apachectl file will be generated under the bin in the installation directory. This is a STARTUP script, we only need to add this command to rc. local.
(Suse does not have rc. local. SUSE can define its own script in this way. If you want to run your script before and after switching the running level, you can create the following:

The Code is as follows: Copy code

/Etc/init. d/before. local
/Etc/init. d/after. local)
Echo/usr/local/apache/bin/apachectl>/etc/rc. d/rc. local,
You can add the following scripts in rc. local to set automatic service startup:
# Sshd
/Usr/local/sbin/sshd

# Proftpd
/Usr/local/sbin/proftpd

# Apache
/Home/apache/bin/apachectl start

# Mysql
/Home/mysql/bin/safe_mysqld -- port = 3306 &

# Start oracle8i listener first
Su-oracle-c 'lsnrctl start'

# Start oracle8i
Su-oracle-c 'dbstart'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.