[关闭]
@cyysu 2017-10-17T08:26:27.000000Z 字数 1529 阅读 788

centos自动升级依赖

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

脚本编写


脚本内容

  1. YUM=/var/run/yum.pid
  2. #yum pid error
  3. yumError(){
  4. if [ -e ${YUM} ];then
  5. rm -rf ${YUM}
  6. fi
  7. }
  8. ## install dependence
  9. dependence(){
  10. echo -e "\033[41m `date`: Begin to install software!!!\033[0m"
  11. yumError
  12. yum install -y vim epel-release net-tools traceroute python gcc python-devel Cython 2&>/dev/null
  13. }
  14. ## update system
  15. update(){
  16. echo -e "\033[41m `date`: Begin to update system!!!\033[0m"
  17. if [ $? -eq 0 ];then
  18. yumError
  19. yum -y update 2&>/dev/null
  20. if [ $? -eq 0 ];then
  21. yumError
  22. yum install -y python-pip 2&>/dev/null
  23. fi
  24. else
  25. yumError
  26. yum -y update 2&>/dev/null
  27. yum install -y python-pip 2&>/dev/null
  28. fi
  29. }
  30. ## install python dependence software
  31. pythonSoftware(){
  32. echo -e "\033[41m `date`: Begin to install python dependence software!!!\033[0m"
  33. if [ $? -eq 0 ];then
  34. pip install paho-mqtt 2&>/dev/null
  35. fi
  36. if [ $? -eq 0 ];then
  37. pip install modbus-tk 2&>/dev/null
  38. fi
  39. }
  40. # main function
  41. case "$1" in
  42. start)
  43. dependence
  44. update
  45. pythonSoftware
  46. ;;
  47. stop)
  48. ;;
  49. status)
  50. echo $?
  51. ;;
  52. *)
  53. echo "Usage autostart.sh [start|stop]" >&2
  54. exit 3
  55. esac

系统服务

将下面的内容增加到/lib/systemd/system/中,然后就可以使用systemctl控制这个服务了

autostart.service

  1. # This file is part of systemd.
  2. #
  3. # systemd is free software; you can redistribute it and/or modify it
  4. # under the terms of the GNU Lesser General Public License as published by
  5. # the Free Software Foundation; either version 2.1 of the License, or
  6. # (at your option) any later version.
  7. [Unit]
  8. Description=autostart python service
  9. After=network.target
  10. [Service]
  11. ExecStart=/opt/autostart.sh start
  12. Type=forking
  13. PIDFile=/opt/start.pid
  14. PrivateTmp=true
  15. [Install]
  16. WantedBy=multi-user.target

打赏

                    支付宝                                                         微信

微信与支付宝支付

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