Linux program boot self-Starting method detailed ~ program automatically start ~myself__linux

Source: Internet
Author: User


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. (Configure commands in/etc/crontab) can also


5. Scheduled automatic running of the program once
The timed execution command at is similar to Crond (but it only executes once): The command executes at a given time, 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 commands directly from the keyboard:


6. Create a boot from boot script

-----------------------------------------------------------

1 Copy your startup script to the/ETC/INIT.D directory

The following assumes that your script file name is test.

2 Set permissions on script files

$ sudo chmod 755/etc/init.d/test

3 Execute the following command to place the script in the startup script:

$ cd/etc/init.d

$ sudo update-rc.d test defaults 95

Note: The number 95 is the sequence number of the script to start, according to their own needs to modify accordingly. You know how this number works when you have multiple startup scripts, and there are dependent dependencies that start between them. The output information for this command is referenced as follows:

Update-rc.d:warning:/etc/init.d/test missing LSB Informationupdate-rc.d:see

To uninstall the startup script:

$ cd/etc/init.d

$ sudo update-rc.d-f test remove

The information for the output of the command is referenced as follows:

Removing any system startup links for/etc/init.d/test .../etc/rc0.d/k95test/etc/rc1.d/k95test/etc/rc2.d/s95test /etc/rc3.d/s95test/etc/rc4.d/s95test/etc/rc5.d/s95test/etc/rc6.d/k95test

----------------------------------------------------

Under the CentOS system, there are two main ways to set up your own installed programs to boot.
1, the start of the program to add the command to the/etc/rc.d/rc.local file, such as the following is the setting up boot httpd. #!/bin/sh # This script would be executed *after* all the other init scripts.   # You can put your own initialization stuff in-if you don ' t # want to do the full Sys V style init stuff. Touch/var/lock/subsys/local/usr/local/apache/bin/apachectl start

2, add the written startup script to the directory/etc/rc.d/init.d/, and then use the command chkconfig to set the boot up.
For example: We put the httpd script into the/etc/rc.d/init.d/directory and add my service---> to system services by placing the service you write in the system service location Chkconfig--add httpd "Chkconfig httpd on" Setting up this system service is turned on "

The command is set to boot.


Ps:mysql Boot from:

#cp Support-files/mysql.server/etc/init.d/mysql.server

--------------------------------------------------------------------------------------------------------------- -------------------


How to implement MySQL's self-boot in Linux under Linux automatically boot MySQL
1) #> Cp/usr/local/mysql/support-files/mysql.server/etc/init.d/mysql
2) #> chmod +x/etc/init.d/mysql
3) #> chkconfig--add MySQL
Some Linux (not RHAS3) also requires this command: #> chkconfig--level 345 MySQL on
4 Append the following command line to the file/etc/rc.local (/etc/rc.d/rc.local)
/bin/sh-c ' Cd/usr/local/mysql;/bin/mysqld_safe--user=mysql & '

In fact, I only do the 4th step, after boot MySQL can also start



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.