树莓派在树莓派上制作开机自启动程序及服务2
Posted 念槐聚:产品规划设计 项目管理 测试质量 过程改进 从0到1
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了树莓派在树莓派上制作开机自启动程序及服务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 INFO start(){ 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 in start) 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 INFO start(){ 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 in start) start ;; stop) stop ;; *) echo -e "\033[32m Usage: $0 (start|stop) \033[0m" ;; esac
--------------------
在/home/lifeccp/webapp/目录下,需要有相应的shell脚本,被调用。如下:
/home/lifeccp/webapp/sendtooss/startup 脚本内容:
[email protected]:~ $ 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.jar DIRNAME="$(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 touched if $cygwin ; then [ -n "$WORK_HOME" ] && WORK_HOME=$(cygpath --unix "$WORK_HOME") [ -n "$JAVA_HOME" ] && JAVA_HOME=$(cygpath --unix "$JAVA_HOME") fi # Setup WORK_HOME if [ "x$WORK_HOME" = "x" ]; then WORK_HOME=$(cd "$DIRNAME"; pwd) fi # Setup the JVM JAVA="java" # if [ "x$JAVA_HOME" != "x" ]; then # JAVA=$JAVA_HOME/bin/java # else # JAVA="java" # fi # Execute the JVM cd "$WORK_HOME" && exec "$JAVA" -jar "$MAIN_JAR" "[email protected]"
在/home/lifeccp/webapp/scptolocal/scptolocal 中有对应的 scptolocal 服务:
[email protected]:~ $ 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.DicomReceiver MAIN_JAR=pandion-1.0.5.release.jar DIRNAME="$(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 touched if $cygwin ; then [ -n "$WORK_HOME" ] && WORK_HOME=$(cygpath --unix "$WORK_HOME") [ -n "$JAVA_HOME" ] && JAVA_HOME=$(cygpath --unix "$JAVA_HOME") fi # Setup WORK_HOME if [ "x$WORK_HOME" = "x" ]; then WORK_HOME=$(cd "$DIRNAME"; pwd) fi # Setup the JVM JAVA="java" # if [ "x$JAVA_HOME" != "x" ]; then # JAVA=$JAVA_HOME/bin/java # else # JAVA="java" # fi # Setup the classpath CP="$WORK_HOME/$MAIN_JAR" # Execute the JVM exec "$JAVA" -cp "$CP" $MAIN_CLASS "[email protected]"
主要脚本如上。
以上是关于树莓派在树莓派上制作开机自启动程序及服务2的主要内容,如果未能解决你的问题,请参考以下文章