1#!/bin/Bash2#/etc/init.d/service_name3 4 # # # BEGIN INIT INFO5 # Provides:provider6# required-Start: $remote _fs $syslog7# required-Stop: $remote _fs $syslog8# Default-start:2 3 4 59# Default-stop:0 1 6Ten# short-description:example Initscript One # Description:this Service is a test A # # # END INIT INFO - - the Case " $" inch - start) - Echo "starting service_name" -cd/home/Pi + suPi-c"python/home/pi/pythoncode/test.py" - ;; + stop) A Echo "stopping service_name" at Killallservice_name - ;; -*) - Echo "Usage:/etc/init.d/service_name start|stop" -Exit1 - ;; in Esac -Exit0
View Code
First, in console input: sudo nano/etc/init.d/service_name, copy the above code into the file. In the above code, "Service_Name" is your own name for this service, and BEGIN INIT INFO changes as needed without affecting the program.
Save the file, and then enter
1 sudo chmod +x/etc/init.d/service_name
Where Service_Name is your own name.
Input
1 sudo update-rc.d/etc/init.d/service_name defaults
Can.
Reference: http://raspberrywebserver.com/serveradmin/run-a-script-on-start-up.html
Raspberry PI writes the Python script to the service and sets the boot up