#!/usr/bin/python3
import os
import sys
#检查root用户
if os.getuid() !=0:
print('请以root用户身份运行')
sys.exit()
#导入yum源
print("="*20,'导入yum源',"="*20)
cmd = 'rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm'
if os.system(cmd) !=0:
print('yum 源导入失败')
sys.exit()
#安装nginx
print("="*20,'安装nginx',"="*20)
cmd = 'yum install -y nginx'
if os.system(cmd) !=0:
print('nginx 安装失败')
sys.exit()
#启动nginx
print("="*20,'启动nginx',"="*20)
cmd = 'systemctl start nginx'
if os.system(cmd) !=0:
print('nginx 启动失败')
sys.exit()
print("="*20,'welcome 安装启动成功 welcome',"="*20)