@cyysu
2017-10-17T08:26:27.000000Z
字数 1529
阅读 912
- 时间:2017年10月17日
- 作者:Kali
- 邮箱:cyysu.github.io@gmail.com/2869905223@qq.com/微信lwyx1413
- 版本:4.0
- 描述:centos下自动解决依赖脚本,和centos自启动脚本配套,用来启动Python程序
脚本编写
YUM=/var/run/yum.pid#yum pid erroryumError(){if [ -e ${YUM} ];thenrm -rf ${YUM}fi}## install dependencedependence(){echo -e "\033[41m `date`: Begin to install software!!!\033[0m"yumErroryum install -y vim epel-release net-tools traceroute python gcc python-devel Cython 2&>/dev/null}## update systemupdate(){echo -e "\033[41m `date`: Begin to update system!!!\033[0m"if [ $? -eq 0 ];thenyumErroryum -y update 2&>/dev/nullif [ $? -eq 0 ];thenyumErroryum install -y python-pip 2&>/dev/nullfielseyumErroryum -y update 2&>/dev/nullyum install -y python-pip 2&>/dev/nullfi}## install python dependence softwarepythonSoftware(){echo -e "\033[41m `date`: Begin to install python dependence software!!!\033[0m"if [ $? -eq 0 ];thenpip install paho-mqtt 2&>/dev/nullfiif [ $? -eq 0 ];thenpip install modbus-tk 2&>/dev/nullfi}# main functioncase "$1" instart)dependenceupdatepythonSoftware;;stop);;status)echo $?;;*)echo "Usage autostart.sh [start|stop]" >&2exit 3esac
将下面的内容增加到/lib/systemd/system/中,然后就可以使用systemctl控制这个服务了
autostart.service
# This file is part of systemd.## systemd is free software; you can redistribute it and/or modify it# under the terms of the GNU Lesser General Public License as published by# the Free Software Foundation; either version 2.1 of the License, or# (at your option) any later version.[Unit]Description=autostart python serviceAfter=network.target[Service]ExecStart=/opt/autostart.sh startType=forkingPIDFile=/opt/start.pidPrivateTmp=true[Install]WantedBy=multi-user.target
支付宝 微信