First, using Init
1, the system has a corresponding Python interpreter, and in the script header declaration, for example:#!/usr/bin/python
+x somescript.py
Start this command format to launch the program
4. Place the script under the/etc/rc.d/init.d/path
--add somescript.py Add Service
3 somescript.py on Boot the service on Init 3 or 5 level
When running Chkconfig, the program will error and need to include in the file:
1 # chkconfig:- 2 # Description:xxxx is a service
It is recommended that you set the init level to 3, because setting it to 5 o'clock runs two scripts.
Later found, Level 3 also has the same problem.
Second, the use of SYSTEMD
Writing Device.service Scripts
1 [Unit]2description=xxxx3After=Network.service4 ?5 [Service]6Type= Simple7User=Root8group=Root9Workingdiretory=/var/www/html/appTenexecstart=/usr/bin/python app.py One ? A [Install] -Wantedby=multi-user.target
Copy the script to/etc/systemd/system/and give the app.py script Execute permissions:
1 chmod +x app.py
Start the service:
1 systemctl start App.service
View service Status:
1 systemctl status App.service
Stop service:
1 systemctl stop App.service
Done!!!
Most Linux platforms now offer SYSTEMD, and individuals recommend using SYSTEMD. SYSTEMD Tutorial Please go to Nanyi tutorial.
Linux Boot Execution python script