首页 > 代码库 > 【树莓派】在树莓派上制作开机自启动程序及服务2

【树莓派】在树莓派上制作开机自启动程序及服务2

有朋友说根据这个文章实践时候有问题,可能之前中间有过个更新,但是忘了更新博文,在这里我把目前最新的贴一下。

/etc/init.d/sendtooss:

sendtooss服务:

#!/bin/sh### BEGIN INIT INFO# Provides:          sendtooss# Default-Start:     2 3 4 5# Default-Stop:      0 1 6# Required-Start: $local_fs# Required-Stop:# chkconfig: 12345 99 05# Short-Description: Start or stop the sendtooss App.### END INIT INFOstart(){    echo -e "\033[32m start sendtooss \033[0m"    cd /home/lifeccp/webapp/sendtooss    su lifeccp -c "sh /home/lifeccp/webapp/sendtooss/startup --spring.profiles.active=test &"}stop(){    echo -e "\033[32m stop sendtooss \033[0m"    pkill -f sendtooss    app_pid=$(pgrep -f sendtooss)    if [ "${app_pid}" = "" ]; then        echo -e  "\033[32m -=stop sendtooss finished=- \033[0m"    else        echo -e  "\033[31m -=stop sendtooss failed=- \033[0m"        kill -9 "${app_pid}"        echo -e  "\033[32m -=kill -9 sendtooss=- \033[0m"    fi}case $1 instart)    start    ;;stop)    stop    ;;*)    echo -e "\033[32m Usage: $0 (start|stop) \033[0m"    ;;esac

 

scptolocal服务:

#!/bin/sh### BEGIN INIT INFO# Provides:          scptolocal# Default-Start:     2 3 4 5# Default-Stop:      0 1 6# Required-Start: $local_fs# Required-Stop:# chkconfig: 12345 99 05# Short-Description: Start or stop the scptolocal App.### END INIT INFOstart(){    echo -e "\033[32m start scptolocal \033[0m"    cd /home/lifeccp/webapp/scptolocal    su lifeccp -c "sh /home/lifeccp/webapp/scptolocal/scptolocal -b LIFECCP:5090 --directory /home/lifeccp/dicom &"}stop(){    echo -e "\033[32m stop scptolocal \033[0m"    pkill -f scptolocal    app_pid=$(pgrep -f scptolocal)    if [ "${app_pid}" = "" ]; then        echo -e  "\033[32m -=stop scptolocal finished=- \033[0m"    else        echo -e  "\033[31m -=stop scptolocal failed=- \033[0m"        kill -9 "${app_pid}"        echo -e  "\033[32m -=kill -9 scptolocal=- \033[0m"    fi}case $1 instart)    start    ;;stop)    stop    ;;*)    echo -e "\033[32m Usage: $0 (start|stop) \033[0m"    ;;esac

 

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

在/home/lifeccp/webapp/目录下,需要有相应的shell脚本,被调用。如下:

/home/lifeccp/webapp/sendtooss/startup 脚本内容:

lifeccp@raspberrypi:~ $ cat webapp/sendtooss/startup #!/bin/bash# -------------------------------------------------------------------------# Osprey  Launcher# args:#     --spring.profiles.active = <profile>    e.g.:‘dev[test|prod]‘# -------------------------------------------------------------------------MAIN_JAR=osprey-1.0.14.release.jarDIRNAME="$(dirname "$0")"# OS specific support (must be ‘true‘ or ‘false‘).cygwin=false;case "$(uname)" in    CYGWIN*)        cygwin=true        ;;esac# For Cygwin, ensure paths are in UNIX format before anything is touchedif $cygwin ; then    [ -n "$WORK_HOME" ] &&        WORK_HOME=$(cygpath --unix "$WORK_HOME")    [ -n "$JAVA_HOME" ] &&        JAVA_HOME=$(cygpath --unix "$JAVA_HOME")fi# Setup WORK_HOMEif [ "x$WORK_HOME" = "x" ]; then    WORK_HOME=$(cd "$DIRNAME"; pwd)fi# Setup the JVMJAVA="java"# if [ "x$JAVA_HOME" != "x" ]; then#     JAVA=$JAVA_HOME/bin/java# else#     JAVA="java"# fi# Execute the JVMcd "$WORK_HOME" && exec "$JAVA" -jar "$MAIN_JAR" "$@"

 

/home/lifeccp/webapp/scptolocal/scptolocal 中有对应的 scptolocal 服务:

lifeccp@raspberrypi:~ $ cat webapp/scptolocal/scptolocal#!/bin/sh# -------------------------------------------------------------------------# Pandion  Launcher# args:#     -b,--bind <[aet[@ip]:]port> e.g.:‘LIFECCP:107‘#     --directory <path>          e.g.:‘./dicom‘# -------------------------------------------------------------------------MAIN_CLASS=com.lifeccp.box.store.DicomReceiverMAIN_JAR=pandion-1.0.5.release.jarDIRNAME="$(dirname "$0")"# OS specific support (must be ‘true‘ or ‘false‘).cygwin=false;case "$(uname)" in    CYGWIN*)        cygwin=true        ;;esac# For Cygwin, ensure paths are in UNIX format before anything is touchedif $cygwin ; then    [ -n "$WORK_HOME" ] &&        WORK_HOME=$(cygpath --unix "$WORK_HOME")    [ -n "$JAVA_HOME" ] &&        JAVA_HOME=$(cygpath --unix "$JAVA_HOME")fi# Setup WORK_HOMEif [ "x$WORK_HOME" = "x" ]; then    WORK_HOME=$(cd "$DIRNAME"; pwd)fi# Setup the JVMJAVA="java"# if [ "x$JAVA_HOME" != "x" ]; then#     JAVA=$JAVA_HOME/bin/java# else#     JAVA="java"# fi# Setup the classpathCP="$WORK_HOME/$MAIN_JAR"# Execute the JVMexec "$JAVA" -cp "$CP" $MAIN_CLASS "$@"

 

主要脚本如上。

 

【树莓派】在树莓派上制作开机自启动程序及服务2