@cyysu
2017-10-17T08:22:30.000000Z
字数 1531
阅读 645
- 时间:2017年10月17日
- 作者:Kali
- 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
- 版本:4.0
- 描述:centos下自启动脚本,用来启动Python程序
脚本编写
#! /bin/bash
#chkconfig: 2345 80 90
#description: autostart centos scripts. This scripts add a install environment scripts to solve different system.
#processname: autostartPython
DIRECTORY=/opt/build
FILE=demo.py
# Copy config file to the build directory
findFile(){
# add copy config file to build directory
cd $DIRECTORY
for file in `ls`
do
if [ -d $file ];then
cd $file && \cp ./*.json ../ && cd ..
fi
done
}
# Main function
main(){
python demo.py
}
# Start function
do_start(){
#Compile build directory
if [ -d $DIRECTORY ];then
echo "`date`: Enter this directory!!!"
findFile
else
echo -e "\033[41m`date`: ${DIRECTORY} may not exit!!! Ready to compile file to produce!!!\033[0m "
cd /opt
for dir in `ls`
do
if [ -d $dir ];then
cd $dir
# find which dir contains python files and go to compile python files to so files
if [ `ls -lR | grep "py" | wc -l` -gt 2 ];then
cd ..
python setup.py $dir && cd ${DIRECTORY}
fi
fi
done
findFile
#exit
fi
#make sure current directory is /opt/build
cd ${DIRECTORY}
# Add start File to build
if [ -e $FILE ];then
echo "File exist success! Ready to run program!!!"
main
else
echo -e "\033[41m`date`: Scripts start failed!!! ${FILE} may not exit!!! Ready to produce bootfile!!!\033[0m "
cd /opt && cp demo.py ${DIRECTORY} && cd ${DIRECTORY}
main
#exit
fi
}
case "$1" in
start)
#echo -e "\033[41m `date`: Begin to solve dependence problem!!!\033[0m"
#chmod 777 -R /opt
#/bin/bash /opt/autoinstall.sh start
#setenforce 0
#echo -e "\033[41m `date`: Dependence solve end!!!\033[0m"
#do_start
cd /opt/build
python mqttTest.py
;;
stop)
;;
status)
echo $?
;;
*)
echo "Usage autostart.sh [start|stop]" >&2
exit 3
esac
支付宝 微信