nginx启动脚本(class练习)
说明:使用类的方式编写程序启动脚本(练习) 1 #!/usr/bin/env python import sys
import os
from subprocess import Popen,PIPE class Process(object): def __init__(self,name,pfile,workdir):
self.name = name
self.pfile = pfile
self.workdir = workdir
self._init() def _init(self):
if os.path.exists(self.workdir):
os.chdir(self.workdir)
else:
os.makedirs(self.workdir)
os.chdir(self.workdir) def _pidfile(self):
return os.path.join(self.workdir,self.pfile) def _writepid(self):
if self.pid:
with open(self.pfile,'w') as fd:
fd.write('%s' % self.pid) def _getpid(self):
p = Popen(['pidof','nginx'],stdout=PIPE)
return p.stdout.read() def start(self):
cmd = self.name
if self._getpid():
sys.exit('The %s are started!!' % self.name)
else:
p = Popen(cmd,stdout=PIPE,shell=True)
self.pid = (p.pid + 1)
self._writepid()
print('The %s is start ' % self.name) def stop(self):
if self._getpid():
for pid in self._getpid().strip().split():
os.kill(int(pid),15)
if os.path.exists(self._pidfile()):
os.remove(self._pidfile())
print('The %s is stopped... ' % self.name)
else:
print('The %s is not running...' % self.name) def restart(self):
self.stop()
self.start() def status(self):
if self._getpid():
print('The %s status is running...' % self.name)
else:
print('The %s status is stopped ...' % self.name) def reload(self):
os.system('%s -s reload' % self.name)
print('The %s is reload Successful !' % self.name ) def help(self):
print('Usage: %s {start|stop|restart|reload}' % __file__) def main():
name = '/usr/sbin/nginx'
workdir = '/var/run/nginx'
pfile = 'nginx.pid'
nginx = Process(name,pfile,workdir)
try:
para = sys.argv[1]
except IndexError as e:
sys.exit(e)
if para == 'start':
nginx.start()
elif para == 'stop':
nginx.stop()
elif para == 'restart':
nginx.restart()
elif para == 'status':
nginx.status()
elif para == 'reload':
nginx.reload()
else:
nginx.help() if __name__ == '__main__':
main()
nginx启动脚本(class练习)的更多相关文章
- linux nginx 启动脚本
linux nginx 启动脚本 [root@webtest76 ~]# vi /etc/init.d/nginx #!/bin/bash # nginx Startup script for the ...
- Nginx 启动脚本/重启脚本
第一步先运行命令关闭nginx sudo kill `cat /usr/local/nginx/logs/nginx.pid` 第二步 vi /etc/init.d/nginx 输入以下内容 #!/b ...
- nginx启动脚本,手动编辑
nginx启动脚本,手动编辑 #! /bin/bash # chkconfig: - # description: nginx service XDIR=/www/server/nginx DESC= ...
- centos LNMP第一部分环境搭建 LAMP LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/php/{p.conf.default,p.conf} php运行方式SAPI介绍 第二十三节课
centos LNMP第一部分环境搭建 LAMP安装先后顺序 LNMP安装先后顺序 php安装 安装nginx 编写nginx启动脚本 懒汉模式 mv /usr/local/php/{ ...
- Nginx 启动脚本
Nginx 启动脚本 1.vim /etc/init.d/nginx #!/bin/bash # chkconfig: - 30 21 # description: http service. # S ...
- LNMP 1.4 nginx启动脚本和配置文件
编写Nginx启动脚本,写入下面这段,授权755 vim /etc/init.d/nginx #!/bin/bash # chkconfig: - # description: http servic ...
- shell脚本之nginx启动脚本、统计日志字段、for循环实战、跳板机
1.NGINX启动脚本 #!/bin/bash # chkconfig: 235 32 62 # description: nginx [ -f /etc/init.d/functions ] &am ...
- nginx启动脚本和配置文件
1.编写Nginx启动脚本,并加入系统服务 vim /etc/init.d/nginx并在其中写入如下内容:#!/bin/bash# chkconfig: - 30 21# description: ...
- 开发nginx启动脚本及开机自启管理(case)
往往我们在工作中需要自行写一些脚本来管理服务,一旦服务异常或宕机等问题,脚本无法自行管理,当然我们可以写定时任务或将需要管理的脚本加入自启等方法来避免这种尴尬的事情,case适用与写启动脚本,下面给大 ...
随机推荐
- 【紫书】(UVa12563)Jin Ge Jin Qu hao
继续战dp.不提. 题意分析 这题说白了就是一条01背包问题,因为对于给定的秒数你只要-1s(emmmmm)然后就能当01背包做了——那1s送给劲歌金曲(?).比较好玩的是这里面dp状态的保存——因为 ...
- Assetbundle2
Assetbundle可以将Prefab封装起来,这是多么方便啊! 而且我也强烈建议大家将Prefab封装成Assetbundle,因为Prefab可以将游戏对象身上带的游戏游戏组件.游戏脚本.材质都 ...
- 对SE的认识
对SE的认识 简述 “架构师”,也就是SE,总是给外人一种比较牛逼的感觉,其实踏实做开发的真的很少关注这个title. 抛开这个名词,这个角色的存在的确有一定的意义,因为项目中需要一个能“带领大家前进 ...
- Python之tornado框架实现翻页功能
1.结果如图所示,这里将html页面与网站的请求处理放在不同地方了 start.py代码 import tornado.ioloop import tornado.web from controlle ...
- HDU 4569 Special equations(枚举+数论)(2013 ACM-ICPC长沙赛区全国邀请赛)
Problem Description Let f(x) = anxn +...+ a1x +a0, in which ai (0 <= i <= n) are all known int ...
- 父窗体和子窗体的显示,show&showdialog方法
showdialog(): 子窗体弹出后,不能对父窗体进行操作.show()可以. 具体原理: 1.在调用Form.Show方法后,Show方法后面的代码会立即执行 2.在调用Form.ShowDi ...
- 【翻译】ASP.NET Core 入门
ASP.NET Core 入门 原文地址:Introduction to ASP.NET Core 译文地址:asp.net core 简介 翻译:ganqiyin ...
- ssh问题_1
昨天配置了虚拟机的ssh,可以相互连接,但是今天早上就不行了,遇到如下错误 [slave1@hadoop ~]$ scp .ssh/id_rsa.pub master@hadoop.master:~/ ...
- LoadRunner系统架构简介与运行原理
1.LoadRunner系统架构简介 LoadRunner是通过创建虚拟用户来代替真实实际用户来操作客户端软件比如Internet Explorer,来向IIS.Apache等Web服务器发送HTTP ...
- LeetCode难度和面试频率(转)
转自:http://www.cnblogs.com/ywl925/p/3507945.html ID Question Diff Freq Data Structure Algorit ...