【树莓派】在树莓派上制作开机自启动程序及服务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
复制代码

 

/etc/init.d/scptolocal:

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 "$@"
复制代码

 

本文转自 念槐聚 博客园博客,原文链接:http://www.cnblogs.com/haochuang/p/6531113.html,如需转载请自行联系原作者

相关文章
|
3月前
|
Ubuntu
在树莓派4B上安装ubuntu系统
在树莓派4B上安装ubuntu系统
|
数据安全/隐私保护 Windows
Windows使用远程桌面连接树莓派
Windows使用远程桌面连接树莓派
1065 0
Windows使用远程桌面连接树莓派
|
监控 Python
树莓派远程音乐播放器
主要功能: udp助手发送指令到云服务器 云服务器中转到树莓派 树莓派处理指令 - 放歌 - 向指定端口发送udp客户端请求的数据 - 停止放歌 - 停止程序
258 0
树莓派远程音乐播放器
树莓派3b+安装Raspbian系统
树莓派烧录系统需要先下载树莓派系统镜像或镜像压缩包,再将SD卡插入电脑,用SDFormatter这个软件对SD卡的第一个盘(boot盘)进行格式化,再用Win32DiskImager这个软件选择img镜像文件进行系统的烧录。
221 0
树莓派3b+安装Raspbian系统
|
安全
树莓派系列-1-初识树莓派,把它装起来
树莓派系列-1-初识树莓派,把它装起来
156 0
树莓派系列-1-初识树莓派,把它装起来