The recent VPS often unstable, vps easy to die and no swap swap space, card after the death of automatic restart, the installation of CentOS when the MySQL did not boot up, resulting in each reboot can not access the Web site, must manually connect SSH open MySQL can visit, this situation has several times, A few times ago, no heart, it's been two times lately. I put MySQL into the boot to boot, in fact, this is not very good, because if your MySQL set the cache is relatively large, a boot may lead to insufficient memory card death, so it is more trouble, I have the MySQL cache set to relatively small, after the operation of the VPS has more than 100 memory, so not afraid of.
CentOS Set the boot boot method as follows:
Vi/etc/rc.d/rc.local on the last line, add the program path that you want to boot:
| The code is as follows |
Copy Code |
/usr/sbin/apachectl Start #apache Server /etc/rc.d/init.d/mysqld Start #mysql Server /ETC/RC.D/INIT.D/SMB Start #samba Server /usr/local/subversion/bin/svnserve-d #svn Server |
The path is set by itself as you install it.
automatically run programs in red Hat Linux
1. Run the program automatically at power-on startup
After Linux is loaded, it initializes hardware and device drivers, and then runs the first process init. Init continues the boot process based on the configuration file to start another process. Typically, modifications are placed in/ETC/RC or/etc/rc.d or/ETC/RC? The script file in the D directory allows Init to start other programs automatically. For example: Edit/etc/rc.d/rc.local file, at the bottom of the file with a line "Xinit" or "startx", you can start directly after the boot into the X-window.
2. Automatically run programs at logon
When a user logs on, bash first automates the global logon script created by the system administrator:/etc/profile. Bash then finds one of the three special files sequentially in the user's home directory:/.bash_profile,/.bash_login,/.profile, but only the one found first.
Therefore, simply adding a command to the above file in the light of the actual need enables the user to automatically run certain programs (similar to the DOS Autoexec.bat) when they log in.
3. Automatically run programs when you exit logins
When you exit login, Bash automatically executes the personal exit logon script/.bash_logout. For example, by adding the command "Tar-cvzf c.source.tgz *.c" in/.bash_logout, the "tar" command is automatically backed up *.c files each time you exit the login.
4. Automatically run programs on a regular basis
Linux has a daemon called crond, which periodically checks the contents of a set of command files in the/var/spool/cron directory and executes the commands in those files at set times. Users can create, modify, and delete these command files through the crontab command.
For example, the establishment of a document Crondfile, content of "9 hours * happybirthday", running the "crontab cronfile" command, every 23rd 9:00 system automatically executes the "HappyBirthday" program ("*" It means no matter what day of the week it is.
5. Timed Autorun program once
executes a command at a time similar to Crond (but it executes only once): the command executes at given times, but does not automatically repeat. The AT command is in the general format: at [-F file] time, executing all the commands given in the file at the specified times. You can also enter the command directly from the keyboard:
| The code is as follows |
Copy Code |
$ at 12:00 At>mailto Roger-s″have a lunch″< plan.txt At>ctr-d Job 1 at 2000-11-09 12:00 2000-11-09 12:00 automatically issued a title "Have a Lunch", content for Plan.txt file content of the mail to Roger. #!/bin/bash Restart= "..." #里面写相应服务代码 Start= "..." Stop= "....." Case "$" in Restart) $RESTART echo "..." ;; Start $START echo "..." ;; STOP) $STOP echo "..." ;; *) echo "Usage: $ {restart¦start¦stop}" Exit 1 Esac Exit 1 |
After the script is finished, you need to modify the permissions chmod u+x test.sh
First, Linux randomly started service programs are in the/etc/ Init.d in this folder, the files inside are all script files (the script is simply to write the program to run to a file to allow the system to execute sequentially, similar to the Autorun.dat file under Windows), and the other Etc This folder also has such as RC1.D, rc2.d to Rc6.d folder, these are different Linux runlevel, we generally enter the X Windows multi-user run level is the 5th level, That is rc5.d, the script file under this folder is the service program to start randomly when running level 5th. Note that the files under each RC (1-6). D folder are actually a soft connection to the files under the/etc/init.d folder (similar to shortcuts in Windows), that is, the entire service program under the/etc/init.d folder, and each RC ( 1-6). D link only the corresponding service program that it needs to launch itself!
To start SCIM (a program), we first need to know where the SCIM program, with the Locate command can be found, SCIM in/usr/bin/scim here, where the USR is the user's, bin in Linux to express the program can be executed. In this way, I can write a script, put it in the/ETC/INIT.D, and then make a corresponding soft link in the RC5.D.
This script is actually very simple, just two lines:
| The code is as follows |
Copy Code |
#!/bin/bash /usr/bin/scim |
The first line is the declaration of what terminal to run the script, the second line is the command to run.
It's also important to note that in RC5.D, each link's name begins with S or K, and s begins with a system startup that starts randomly, and K begins with a random start. In this way, you can know, if I want which service to start randomly, it is the first letter of its name changed to S on it, of course, the s changed to K, this service can not be started randomly. So I'm going to name this link as sxxx so the system can get it started randomly.
add a self-starter script
First put your own script in the/ETC/INIT.D, and then execute the following instructions:
UPDATE-RC.D a start 90 2 3 4 5. Stop 90 0 1 6.
Where A is your script, notice that there are two points.
A script example.
| code is as follows |
copy code |
| #!/bin/sh # Source function library. if [-f/etc/init.d/functions]; N ./etc/init.d/functions Else ./lib/lsb/init-functions Fi Mod=/a.ko Start () { Echo-n $ "Insert a kernel module:" /sbin/insmod $MOD Echo } Stop () { Echo-n $ "remove a kernel Module: /sbin/rmmod a-f Echo } [f $MOD] | | Exit 0 # were called. case ' in Start ' start ;; Stop) Stop ;; Restart|reload) Stop start ;; *) Echo $ "Usage: $ {start|stop|restart|reload}" |
The UPDATE-RC.D command, which is used to automatically upgrade the System V type initialization script, simply means what you want the system to run when booting the initialization, which is expected to stop on shutdown or reboot, and can be used to help you set it up. The scripts are connected in/etc/rcn.d/lnname, and the corresponding scripts are located in/etc/init.d/script-name.
1, set the specified boot sequence, specify the run level of the Startup items:
UPDATE-RC.D start
2, set at the specified run level, in the specified order to stop:
UPDATE-RC.D Stop
3. Remove the specified startup entry from all run levels:
Update-rc.d-f Remove
For example:
| The code is as follows |
Copy Code |
UPDATE-RC.D script-name Start 90 1 2 3 4 5. Stop 52 0 6.
|
Start 90 1 2 3 4 5. : Indicates that in 1, 2, 3, 4, 5 of these five run levels, in order, from small to large, the 90th runs this script.
Stop 52 0 6. : in 0, 6 of these two levels of operation, in order, from small to large, the 52nd to stop the operation of the script.
If you add a script to the/ETC/INIT.D, you need to create a link
In the/ETC/RC*.D. K begins with Kill, and S begins with start, and the numeric order represents the order of initiation. (SYSV)
UPDATE-RC.D can do you a favor.
Cases:
Create a script called Zope in the/ETC/INIT.D, and then
| The code is as follows |
Copy Code |
UPDATE-RC.D Zope Defaults |
will produce the following chain?::
| The code is as follows |
Copy Code |
Adding system startup For/etc/init.d/zope ... /etc/rc0.d/k20zope->. /init.d/zope /etc/rc1.d/k20zope->. /init.d/zope /etc/rc6.d/k20zope->. /init.d/zope /etc/rc2.d/s20zope->. /init.d/zope /etc/rc3.d/s20zope->. /init.d/zope /etc/rc4.d/s20zope->. /init.d/zope /etc/rc5.d/s20zope->. /init.d/zope |
Other advanced use method please man UPDATE-RC.D