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适用与写启动脚本,下面给大 ...
随机推荐
- abo dto属性验证的坑
问题回现: public class ShipmentRequestDto { public string FromPhoneNumber { get; set; } /// <summary& ...
- virsh查看迁移信息的两个命令
virsh qemu-monitor-command uuid --hmp info migrate, 能看到迁移所设置的相关参数,和进度相关信息: virsh domjobinfo uuid命令, ...
- 常见 SQL语句使用 增删改查
一.常见的增删改查(一).查:1.SELECT 列名称 FROM 表名称,其中列名可以是多个,中间用豆号分开,如SELECT LastName,FirstName FROM Persons: 2.SE ...
- spring-data-jpa 简单使用心得
对于总是使用mybatis的我,突发奇想的想使用spring-data-jpa搭一个小环境,这几天处处碰壁,现总结如下: 环境采用springboot maven需要导入: <dependenc ...
- springmvc项目搭建四-基于前端框架完善页面的数据显示
上一篇把前端框架先放上去了,现在开始前后端进行交互,对数据进行显示. 效果如图所示...中间经历了数据显示不上去的问题,是对于spring的注解了解不够,问题及其解决可以参照上一篇问题处理... 目前 ...
- 延迟加载(Lazyload)三种实现方式
定义:延迟加载也称为惰性加载,即在长网页中延迟加载图像.用户滚动到它们之前,视口外的图像不会加载.这与图像预加载相反,在长网页上使用延迟加载将使网页加载更快.在某些情况下,它还可以帮助减少服务器负载. ...
- 玩ktap
1.ktap是否有过滤的功能,之前bpf程序可以阻止某些trace的log的输出,ktap是否有这样的功能呢? 2.ftrace 和 perf 的ring buffer好像不是一个,有什么区别? 需求 ...
- IIS注册asp.net4.0
1. 运行->cmd 2. cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319 3. aspnet_regiis.exe -i
- 【BZOJ 3316】JC loves Mkk 01分数规划+单调队列
单调栈不断吞入数据维护最值,数据具有单调性但不保证位置为其排名,同时可以按照进入顺序找出临近较值单调队列队列两端均可删除数据但只有队末可以加入数据,仍然不断吞入数据但同时可以额外刨除一些不符合条件的数 ...
- 自定义CheckBox
自定义android的CheckBox按钮图形有两个步骤三种方式: 第一步: 新建Android XML文件,类型选Drawable,根结点选selector,放置在drawable文件夹内,指定各种 ...