码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-03-10 16:22:08      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:ini   ide   app   shell脚本   朋友   test   exe   main   jar   

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

/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 脚本内容:

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.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" "$@"

 

/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.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 "$@"

 

主要脚本如上。

 

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

标签:ini   ide   app   shell脚本   朋友   test   exe   main   jar   

原文地址:http://www.cnblogs.com/haochuang/p/6531113.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!