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适用与写启动脚本,下面给大 ...
随机推荐
- Spring.Net在ASP.NET Mvc里使用的一个小例子
就贴个小例子,就不注意格式了. 1.下载dll NuGet的下载地址:http://docs.nuget.org/docs/start-here/installing-nuget 在vs的NuGet里 ...
- nodejs的交叉(跨平台)编译(to android)
nodejs的二进制包有两种安装方式node-gyp以及node-pre-gyp 这两条命令会写入该包的安装脚本. node-gyp是使用gyp工具编译源码,因此必须指定交叉编译器(参见http:// ...
- Python网络编程(socketserver、TFTP云盘、HTTPServer服务器模型)
HTTP协议? HTTP是一个应用层协议,由请求和响应构成,是一个标准的客户端服务器模型.HTTP是一个无状态的协议. 通常承载于TCP协议之上,有时也承载于TLS或SSL协议层之上,这个时候,就成了 ...
- Docker安装Zabbix全记录
零.Zabbix架构设计 一.docker安装mysql 查找Docker Hub上的mysql镜像: [root@10e131e69e15 ~]# docker search mysql INDEX ...
- %matplotlib inline
整理摘自 https://zhidao.baidu.com/question/1387744870700677180.html %matplotlib inline是jupyter notebook里 ...
- Leetcode 678.有效的括号字符串
有效的括号字符串 给定一个只包含三种字符的字符串:( ,) 和 *,写一个函数来检验这个字符串是否为有效字符串.有效字符串具有如下规则: 任何左括号 ( 必须有相应的右括号 ). 任何右括号 ) 必须 ...
- 【转】Virtual DOM
前言 React 好像已经火了很久很久,以致于我们对于 Virtual DOM 这个词都已经很熟悉了,网上也有非常多的介绍 React.Virtual DOM 的文章.但是直到前不久我专门花时间去学习 ...
- 山科SDUST OJ Problem J :连分数
Problem J: 连分数 Time Limit: 1 Sec Memory Limit: 64 MBSubmit: 2723 Solved: 801[Submit][Status][Web B ...
- POI 导入 一直报400问题
排查过程:1.400一般都是参数或者请求不对,但是我这个情况是本地好用,只是服务器有问题,所以排除了传值的格式等问题. 2.服务器和本地网络隔离,所以没办法比较代码,分两次全量覆盖了html和js部分 ...
- 使用锚点在HTML页面中快速移动
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...