[关闭]
@cyysu 2017-10-17T08:22:30.000000Z 字数 1531 阅读 645

centos自启动脚本

  • 时间:2017年10月17日
  • 作者:Kali
  • 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
  • 版本:4.0
  • 描述:centos下自启动脚本,用来启动Python程序

脚本编写


脚本内容

  1. #! /bin/bash
  2. #chkconfig: 2345 80 90
  3. #description: autostart centos scripts. This scripts add a install environment scripts to solve different system.
  4. #processname: autostartPython
  5. DIRECTORY=/opt/build
  6. FILE=demo.py
  7. # Copy config file to the build directory
  8. findFile(){
  9. # add copy config file to build directory
  10. cd $DIRECTORY
  11. for file in `ls`
  12. do
  13. if [ -d $file ];then
  14. cd $file && \cp ./*.json ../ && cd ..
  15. fi
  16. done
  17. }
  18. # Main function
  19. main(){
  20. python demo.py
  21. }
  22. # Start function
  23. do_start(){
  24. #Compile build directory
  25. if [ -d $DIRECTORY ];then
  26. echo "`date`: Enter this directory!!!"
  27. findFile
  28. else
  29. echo -e "\033[41m`date`: ${DIRECTORY} may not exit!!! Ready to compile file to produce!!!\033[0m "
  30. cd /opt
  31. for dir in `ls`
  32. do
  33. if [ -d $dir ];then
  34. cd $dir
  35. # find which dir contains python files and go to compile python files to so files
  36. if [ `ls -lR | grep "py" | wc -l` -gt 2 ];then
  37. cd ..
  38. python setup.py $dir && cd ${DIRECTORY}
  39. fi
  40. fi
  41. done
  42. findFile
  43. #exit
  44. fi
  45. #make sure current directory is /opt/build
  46. cd ${DIRECTORY}
  47. # Add start File to build
  48. if [ -e $FILE ];then
  49. echo "File exist success! Ready to run program!!!"
  50. main
  51. else
  52. echo -e "\033[41m`date`: Scripts start failed!!! ${FILE} may not exit!!! Ready to produce bootfile!!!\033[0m "
  53. cd /opt && cp demo.py ${DIRECTORY} && cd ${DIRECTORY}
  54. main
  55. #exit
  56. fi
  57. }
  58. case "$1" in
  59. start)
  60. #echo -e "\033[41m `date`: Begin to solve dependence problem!!!\033[0m"
  61. #chmod 777 -R /opt
  62. #/bin/bash /opt/autoinstall.sh start
  63. #setenforce 0
  64. #echo -e "\033[41m `date`: Dependence solve end!!!\033[0m"
  65. #do_start
  66. cd /opt/build
  67. python mqttTest.py
  68. ;;
  69. stop)
  70. ;;
  71. status)
  72. echo $?
  73. ;;
  74. *)
  75. echo "Usage autostart.sh [start|stop]" >&2
  76. exit 3
  77. esac

打赏

                    支付宝                                                         微信

微信与支付宝支付

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注