树莓派配置开机自启动程序大致有三种,目前最主流的是将程序作为服务启动,本文介绍下树莓派开机启动 jar(SpringBoot打成的jar包)
#!/bin/sh
echo "zlink101 service begin start"
export JAVA_HOME=/home/soft/jdk1.8.0_241
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=/home/soft/go/bin:$PATH
cd /mnt/service
sleep 10s
nohup ./xjar java -jar gateway-1.0.0.jar &
echo "zlink101 service start success"
stop.sh 代码如下:
#!/bin/sh
echo "zlink101 stop begin"
ID=`ps -ef | grep "gateway-1.0.0.jar" | grep -v "grep" | awk '{print $2}'`
echo $ID
for id in $ID
do
kill -9 $id
echo "killed $id"
done
sleep 5s
echo "zlink101 stop success"
写完之后可以运行测试下
#! /bin/bash
### BEGIN INIT INFO
# Provides: Juson
# Required-Start: $network $remote_fs $syslog $time
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: zlink101 initscript
### END INIT INFO
case "$1" in
start)
sh /mnt/service/start.sh
;;
stop)
sh /mnt/service/stop.sh
;;
*)
exit 1
;;
esac
exit 0
最后注意文件权限!