@cyysu
2017-10-17T08:22:30.000000Z
字数 1531
阅读 762
- 时间: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: autostartPythonDIRECTORY=/opt/buildFILE=demo.py# Copy config file to the build directoryfindFile(){# add copy config file to build directorycd $DIRECTORYfor file in `ls`doif [ -d $file ];thencd $file && \cp ./*.json ../ && cd ..fidone}# Main functionmain(){python demo.py}# Start functiondo_start(){#Compile build directoryif [ -d $DIRECTORY ];thenecho "`date`: Enter this directory!!!"findFileelseecho -e "\033[41m`date`: ${DIRECTORY} may not exit!!! Ready to compile file to produce!!!\033[0m "cd /optfor dir in `ls`doif [ -d $dir ];thencd $dir# find which dir contains python files and go to compile python files to so filesif [ `ls -lR | grep "py" | wc -l` -gt 2 ];thencd ..python setup.py $dir && cd ${DIRECTORY}fifidonefindFile#exitfi#make sure current directory is /opt/buildcd ${DIRECTORY}# Add start File to buildif [ -e $FILE ];thenecho "File exist success! Ready to run program!!!"mainelseecho -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#exitfi}case "$1" instart)#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_startcd /opt/buildpython mqttTest.py;;stop);;status)echo $?;;*)echo "Usage autostart.sh [start|stop]" >&2exit 3esac
支付宝 微信