How to Set startup in linux

Source: Internet
Author: User
The following describes how to set the Automatic startup program in linux. The script is usrlocalapache2bin ;. the apachectlstart file is located in etcrc. dinit. d. The name is apached, which must be executable. # chmod + xetcrc. dinit. the attributes of the dapached setting file are executable # ln-set

How to set the Automatic startup program on linux
The following uses self-starting apache as an example;
Self-starting script:
/Usr/local/apache2/bin;
./ApachectlStart
The file is located under/etc/rc. d/init. d and is named apach.EdAnd be executable.
#Chmod+ X/etc/rc. d/init. d/apached // set the object attributes to executable.
#Ln-S/etc/rc. d/init. d/apached/etc/rc3.d/S90apache // create a soft connection and a shortcut
# Ln-s/etc/rc. d/init. d/apached/etc/rc0.d/K20apache
 

Automatically run the program in Red Hat Linux
1. automatically run the program at startup
After Linux is loaded, it initializes the hardware and device drivers, and then runs the first process init. Init starts other processes based on the configuration file. Normally, the modification is placed in/etc/rc or/etc/rc. d or/etc/rc ?. The script file in the d directory can enable init to automatically start other programs. For example, to edit the/etc/rc. d/rc. local file, add a line of xinit or startx at the end of the file. After the file is started, you can directly enter X-Window.

2. automatically run the program upon Logon
When a user logs on, bash automatically runs the global logon script:/etc/pro created by the system administrator.File. Bash then searches for one of the three special files in sequence in the user's starting Directory:/. bash_profile,/. bash_login, And/. profile, but only executes the first one found.
Therefore, you only need to addCommandYou can automatically run certain programs (similar to the AutoExEc. bat ).

3. automatically run the program upon logon.
When you log out, bash automatically runs the personal logout script/. bash_logout. For example, if you add the tar-cvzf c. source. tgz *. c command to/. bash_logout, the tar command is automatically executed to back up the *. c file every time you log out.

4. Periodically run the program automatically
Linux has a daemon called crond. Its main function is to periodically check the content of a group of command files in the/var/spool/cron directory, and execute the commands in these files at the specified time. You can useCrontabCommand to create, modify, and delete these command files.
For example, create a crondFile with the content 00 9 23 Jan * HappyBirthday. After running the crontab cronFile command, every time the system automatically executes the HappyBirthday program at a.m. on June 23, lunar January (* indicates that no matter the day of the day is the day of the week ).

5. automatically run the program once at a scheduled time
Scheduled command execution at is similar to crond (but it is only executed once): The command is executed at a given time, but is not automatically repeated. The general format of the at command is: at [-f file]TimeTo execute all the commands in the file at the specified time. You can also enter the command directly from the keyboard:

$ At 12: 00
At> mailto Roger-s "Have a luNcH "<plan.txt
At> CTr-D
Job 1

At, February 9, an email entitled Have a lunchcontaining the plan.txt file was automatically sent to Roger.

 

#! /Bin/bash
RESTART =... # Write the corresponding service code
START = .......
STOP = ..........
Case $1 in
Restart)
$ RESTART
Echo ......
;;
Start)
$ START
Echo ......
;;
STOP)
$ STOP
Echo ......
;;
*)
Echo Usage: $0 {restart transaction start transaction stop}
Exit 1
Esac

Exit 1

After writing the script, you need to modify the chmod u + x test. sh permission.

 

First, all the services started randomly in linux are in/etc/init. d. All the files in this folder are script files (in simple words, the script program writes the program to be run to a file so that the system can execute it in order, similar to windows autorun. in addition, there are folders such as rc1.d, rc2.d to rc6.d In the/etc folder, which are different runlevels in linux, generally, the running level of multiple users in X windows is 5th, that is, rc5.d. The script file in this folder is the service program to be started randomly when the script file is 5th. Note that in each rc (1-6 ). the files in the d folder are all/etc/init. A soft connection to the files in the d folder (similar to the shortcut in windows), that is, in/etc/init. the d folder contains all the service programs, and each rc (1-6 ). d. Only link it to start the desired service program!

To start scim (a program), we first need to know where the scim program is, use loCatE command can be found, scim in/usr/bin/scim here, where usr table shows that it belongs to the user, bin in linux indicates that the program can be executed. In this way, I can write a script program, put it in/etc/init. d, and then make a corresponding soft link in rc5.d.
This script is actually very simple, just two lines:

#! /Bin/bash
/Usr/bin/scim

The first line is to declare the terminal used to run the script, and the second line is the command to run.

Note that in rc5.d, the name of each link starts with S or K, K starts with a random start. In this case, you can know which service I want to start at random, and change the first letter K to S. Of course, after changing S to K, this service cannot be started randomly. Therefore, we need to name this link SXXX so that the system can start it at random.

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.