Set Raspberry Pi boot

Raspberry Pi program startup settings.

About boot, I find the Internet a tutorial, and then did so again.

Need start-up procedure is to write my program is a data transmission, the name for trans.py

 

Startup scripts, stored in /etc/init.d following directory:

#!/bin/bash

# /etc/init.d/trans

### BEGIN INIT INFO

# Provides: xiaofeng

# Required-Start: $remote_fs $syslog

# Required-Stop: $remote_fs $syslog

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Short-Description: trans initscript

# Description: transform data

### END INIT INFO

 

case "$1" in

    start)

        echo "Starting trans"

        /scream/trans.py &

        ;;

    stop)

        echo "Stopping trans"

        #kill all trans.py

        kill $ (ps aux | grep -m 1 'python /scream/trans.py' | awk '{print $ 2}')

        ;;

    *)

        echo "Usage: service ledblink start|stop"

        exit 1

        ;;

esac

exit 0

 

This is the original script. I put a red mark where the information into my program, and then OK. Save the name of my script is trans  

Modify the permissions: sudo chmod + x /etc/init.d/trans

You can test the service command

 

sudo service trans start # start

sudo service trans stop # Stop

 

I tested at the start of service order wrong, that can not find the file, should be the authority, then I did a while back, somehow the well.

 

Finally, set the boot: sudo update-rc.d trans defaults

Delete boot: update-rc.d -f trans remove

Referring to the article Source:

https://www.embbnux.com/2015/04/12/raspberry_pi_setting_python_script_start_on_boot/

Usage Update-rc.d command http://www.52pi.net/?p=255

About scripting languages case of usage:

string in case

Mode 1) command ;;

Mode 2) command ;;

......

Esac

Case statement is a multi-branch statement, according to which ")" left pattern matching string values ​​to execute the corresponding command, the match is performed from top to bottom, is always matched to the first execution command table corresponding to the mode. If each one of pattern matching can not, nothing is executed, while the back and then put a *) represents any string that does not match the above. ";;" represents a part of the program commands corresponding to the pattern.

 

$ #: Indicates the number of command line arguments to save the program.

$ ?: represents the return value of a command before saving.

$ 0: Lists the current program name

$ *: That saves all the input command line parameters in the form of "$ 1 $ 2 ..." in

$ @: That saves all the input command line parameters in the form of "$ 1" "$ 2" ... a.

$ N: $ 1 is the first parameter of the command, the command line $ 2 for the second save the book, and so one.

 

Permission settings:

chmod u + x name indicates that only he can perform

chmod ug + x name and said he was with a group can be performed.

chmod + x represents everyone can perform

Guess you like

Origin www.cnblogs.com/SkystarX/p/12286032.html