


How to make programs start automatically when booting in Linux system
How to make the program automatically start when the computer is turned on in the Linux system Core tip: System services can generally start automatically when the computer is turned on. So what should you do if you want the program to start automatically when the computer is turned on under the Linux system? We know that in the Windows system "Start"-->"All Programs"-->"Start" just put a shortcut in it, but what about Linux systems? ...System services can generally start automatically when the computer is turned on. So what should you do if you want the program to start automatically when the computer is turned on under the Linux system? We know that in the Windows system, "Start" --> "All Programs" -- > Just put a shortcut in "Startup", but what about Linux system?
This is also a relatively simple problem. There are many ways to solve it. Here are three methods. Because it is a brief introduction, the specific details are not very detailed. You can read the relevant manuals through man.
1./etc/rc.local
This is the simplest method. Edit "/etc/rc.local" and enter the shell command to start the program (you need to enter the command full path), similar to "Startup" under Windows.
Use the command vi /etc/rc.local
Then add the full path of the program to be executed in the last line of the file.
For example, if a haha.sh is to be executed every time the computer is turned on, and this script is placed under /opt, then you can add a line "/opt/./haha.sh" to "/etc/rc.local", Or two lines of "cd /opt" and "./haha.sh".
2. Crontab (similar to Windows task scheduling service)
You can set the execution schedule of the program through crontab, for example, let the program be executed at 8 o'clock every day, or at 10 o'clock every Monday once.
crontab -l lists the schedule;
crontab -e edits the schedule;
crontab -d deletes the schedule;
"-l" has nothing to say, it is just a view. ;
"-e" is for editing, which is no different from vi (in fact, it is to use vi to edit a specific file);
"-d" is basically not used because it deletes all the timetables of the user. Generally, Use "-e" to edit and delete the unnecessary timetable line by line;
So how to edit it?
The format of the crontab file is: M H D m d CMD.
A 6-field field, the last CMD is the program to be executed, such as haha.sh.
M: Minutes (0-59)
H: Hours (0-23)
D: Date (1-31)
m: Month (1-12)
d: A Day of the week (0-6, 0 represents Sunday)
These five time fields are separated by spaces, and their value can be a number or multiple numbers separated by commas (or Others), if no setting is required, the default is "*".
For example, executing haha.sh at 8:05 every day is "5 8 * * * /opt/./haha.sh".
It seems that I have strayed away from the "automatic startup of the boot program", now I am back to the topic. In fact, the crontab function introduced above already has the ability to start automatically at boot. You can write a monitoring script and execute it every 5 minutes (*/5 * * * * ./haha.sh). If the program is no longer available, restart it. . (*/5) means every 5 minutes
3. Register system services
The services that come with the operating system, such as ssh, ftp, etc., are automatically started when the computer is powered on. We can also use this method This is a way to increase the "value" of the programs you develop.
For example, if I want to add an installed service as a system service, I can execute the following command:
chkconfig --add service name (First, add it as a system service. Note that there are two words in front of add. Horizontal bar)
chkconfig -leve startup level service name on
(Explanation, level 3 means starting in the command line mode, level 5 means starting in the graphical interface, on means opening)
chkconfig -leve startup level service name off
(Explanation, off means to turn off automatic startup)
For example: chkconfig -level 3 mysql on
You can also use chkconfig --add service name to delete system services
******************************** *************************************************** ********If you want to check which services have been added as system services, you can use the command:
ntsysv or chkconfig --list
If you want to check which programs have been added as self-starting, you can use Command:
cat /etc/rc.local (check which program paths have been added to this file)
************************ *************************************************** *******************
The following is an example of how to add a shell script as a system service and follow the system startup:
You can see " There are many files under /etc/rc.d/init.d", and the contents of each file can be seen. They are actually some shell scripts.
The system service is started through the script file in "/etc/rc.d/init.d". We can also write our own script and place it here.
The content of the script file is also very simple, similar to this (for example, name it "hahad"):
. /etc/init.d/functions
start() { echo "Starting my process "
cd /opt
./haha.sh}
stop() { killall haha.sh
echo "Stoped"}
After writing the script file, things are not over yet. Continue to complete the following steps: chmod +x hahad
chkconfig hahad on #Set the hahad switch (on/off)
chkconfig --list hahad #You can see the services that have been registered with hahad
At this time, all the work is completed.
How to install the Redis database under Linux and share the automatic startup script
nginx automatically starts the service after booting
Linux automatically starts MySQL
The above is the detailed content of How to make programs start automatically when booting in Linux system. For more information, please follow other related articles on the PHP Chinese website!

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools