基于shell脚本编写的服务自启程序:
1.主程序代码(autoboot-2.0.sh):
#! /bin/sh
echo "in autoboot-2.0.sh"
cd /autoboot
while read line
do
basepath=$line
cd $basepath
jarStartSh=$(ls $basepath|grep start.sh)
jarFullName=$(ls $basepath|grep ".jar$")
if [ ${jarStartSh} ]
then
printf "\n *************************正在启动${jarStartSh}*******************\n"
sh start.sh
else
printf "\n *******************没有找到start.sh,正在生成中*********************\n"
cp -a /autoboot/config/*.sh ./
sh start.sh
fi
echo ${jarFullName}" starting ... ... "
sleep 2
done < autoboot.txt
2.配置文件示例(autoboot.txt文件)
/project1-path1/project1Name
/project2-path1/project2-path2/project2Name
需要依赖:
1.config文件下的脚本;
2.自启配置文件:autoboot.txt文件;
程序源码地址:
github地址:https://github.com/Guofucheng0822/project_shell