Linux (debian)

Source: Internet
Author: User

Linux (debian)

Check on the Internet that linux has a variety of methods to set auto-start upon startup. There are two methods here, but the second method has never been tested successfully. I hope you can give some suggestions. Thank you very much!

Method 1:

Add it directly before exit 0 in/ect/rc. local and restart it. The easiest way is

Method 2:

Create a STARTUP script under/etc/init. d/and use a soft link under/etc/rc2.d/to link the script.

1. rc under/etc ?. D directory Introduction

/Etc has rc0.d -- rc6.d

Different levels:

0:Disable computer
1:
Single User Mode
2:
Multi-User Network Mode
3:
Multi-User Network Mode
4:
Reserved as custom; otherwise3
5:
Same operation level4Is generally used for graphic interfaces.(GUI)Login(For exampleXOfXdmOrKDEOfKdm)
6:
Restart the computer

In/etc/rc ?. D. Each directory contains many symbolic links, some of which start with a K letter and others start with a S letter. These link names are followed by two numbers after the first letter. This K means to stop a service, and S means to start a service. The number determines the Starting sequence of these scripts, from 00 to 99 (the smaller the number, the earlier the execution ). When init is converted to another running level, some corresponding services will stop while others will start.

Real scripts are in the/etc/init. d directory. they complete the actual work, and symbolic links all point to them. Both the stop script link and the start script link point to the same script in the/etc/init. d directory. This is because different parameters can be used to call these scripts, such as start, stop, restart, reload, and status. When the K link is called, the corresponding script runs with the stop parameter; when the S link is called, the corresponding script runs with the start parameter.

There is an exception in the above description. The link starting with S in the rc0.d and rc6.d directories does not start anything, but is called with the stop parameter to stop some services. The logic behind this is that when a user wants to restart or shut down the system, the user does not need to start any service, but only needs to stop the system.

The following describes the script parameters:

StartStart the service. Stop Stop the service. RestartClose the service and start it again. ReloadThe service configuration has been updated. If you modify the configuration file of a service and do not need to restart the service, you can use this parameter. StatusDisplays the service status. if the service is running, the PID of the service process is displayed.

You can freely modify how the process starts. The files we provide here are just an example of how they work.

2. Write a simple Startup Script

# Vi/etc/init. d/bin. sh

  1. #! /Bin/sh
  2. # Chkconfig: 2345 80 05 -- specify the execution level. 0 usually refers to shutdown, 6 to restart, and others to start normally. 80 indicates the startup priority, and 05 indicates the disabled priority.
  3. # Description: simple example service
  4. RETVAL = 0
  5. Start () {# start the entry function of the service
  6. Echo "simple example service is started ..."
  7. }
  8. Stop () {# disable the entry function of the service
  9. Echo "simple example service is stoped ..."
  10. }
  11. # Use case to select
  12. Case $1 in
  13. Start)
  14. Start # Call the preceding start Function
  15. ;;
  16. Stop)
  17. Stop # Call the above stop Function
  18. ;;
  19. *)
  20. Echo "error choice! Please input start or stop ";;
  21. Esac
  22. Exit $ RETVA # chmod + x/etc/init. d/bin. sh // Add executable permissions

    #/Etc/init. d/bin. sh start // Test

    3. link the startup script to/etc/rc2.d.

    # Ln-s/etc/init. d/bin. sh/etc/rc2.d/S20bin // function: Run/etc/init. d/bin. sh start at startup.

    # Ln-s/etc/init. d/bin. sh/etc/rc0.d/K20bin // when the computer is disabled, run/etc/init. d/bin. sh stop

    4. Restart (this method has never been passed. I hope you can make some suggestions. Thank you very much !)



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.