daemon

How do you use python-daemon the way that it's documentation dictates?

自作多情 提交于 2020-01-12 18:44:41
问题 I'm trying to make a daemon in python and I've come across the python-daemon package. The interesting thing about it is that the most common way I've seen it used isn't even what the documentation, which is very sparse, tells you to do import os import grp import signal import daemon import lockfile from spam import ( initial_program_setup, do_main_program, program_cleanup, reload_program_config, ) context = daemon.DaemonContext( working_directory='/var/lib/foo', umask=0o002, pidfile=lockfile

Constantly monitor a program/process using Python

与世无争的帅哥 提交于 2020-01-12 07:37:06
问题 I am trying to constantly monitor a process which is basically a Python program. If the program stops, then I have to start the program again. I am using another Python program to do so. For example, say I have to constantly run a process called run_constantly.py . I initially run this program manually, which writes its process ID to the file "PID" (in the location out/PROCESSID/PID). Now I run another program which has the following code to monitor the program run_constantly.py from a Linux

Docker容器端口映射无法访问的问题排查

痞子三分冷 提交于 2020-01-10 20:20:58
一、背景 一般需要对外提供服务的Docker容器,我们在启动时后使用-p命令将对外访问端口暴露给外部,例如启动Docker Registry,我们将5000端口映射出来供外部访问: docker run -d -p 5000:5000 registry 但最近碰到一个非常奇怪的情况:研发组里一个CentOS 7测试环境里部署有Docker Registry,并对外暴露了端口。启动容器后一段时间内都是可以正常工作的,但在不定时间间隔后,外部主机就会出现无法从仓库中拉取镜像的情况,提示TimeOut: 然而在Docker宿主机上访问仓库则可以正常访问: 至于这个问题,只有手动重启出问题的Docker daemon服务后,外部才可以重新访问,但只要再过一段时间又会出现这样的问题。 二、问题排查 碰到这个问题我第一反应就是问组里的人,是不是有人重启过CentOS 7 自己的firewallD了。 因为这台服务器是我配置的,防火墙虽然开着但我已经开启端口访问了,所以肯定不是因为防火墙阻断连接的缘故。但由于这篇文章是篇踩坑排查文档,所以还是把这种情况写出来了 情况一:开着防火墙但没有开放端口 CentOS 7自带并启用了防火墙FirewallD,我们可以通过下面的命令检查FirewallD的状态: firewall-cmd --state 如果输出的是“not running

rsync 服务快速部署手册

馋奶兔 提交于 2020-01-10 17:52:56
来源: https://www.cnblogs.com/miclesvic/p/6189540.html 一、rsync服务端安装 1、查看rsync安装包 # rpm -qa rsync rsync-3.0.6-12.el6.x86_64 2、安装rsync 系统默认都会安装rsync软件包的,如果查看发现没有安装,执行yum安装即可 # yum install rsync -y 3、添加rsync服务的用户,管理本地目录的 # useradd -s /sbin/nologin -M rsync # id rsync 4、生成rsyncd.conf配置文件 # cat /etc/rsyncd.conf #rsync_config______________________start #created by oldboy 15:00 2016-11-15 ##rsyncd.conf start## uid = rsync # 用户 远端的命令使用rsync访问共享目录 gid = rsync # 用户组 use chroot = no # 安全相关 max connections = 200 # 最大连接数 timeout = 300 # 超时时间 pid file = /var/run/rsyncd.pid # 进程对应的进程号文件 lock file = /var/run

centos系统组件优化

佐手、 提交于 2020-01-09 23:42:59
CentOS Linux在公司服务器上广泛被使用,本文总结了一些常见的加固方法。 基本原则: 最小的权限+最小的服务=最大的安全 操作之前先备份; 为避免配置错误无法登录主机,请始终保持有一个终端已用root登录并不退出,在另一个终端中做配置修改。这样即使改错,也不至于因系统无法登录导致永远无法登录或恢复配置。 操作项: 一、注释掉系统不需要的用户和用户组 注意:不建议直接删除,当你需要某个用户时,自己重新添加会很麻烦。 cp /etc/passwd /etc/passwdbak #修改之前先备份 vi /etc/passwd #编辑用户,在前面加上#注释掉此行 #adm:x:3:4: adm:/var/adm:/sbin/nologin #lp:x:4:7: lp:/var/spool/lpd:/sbin/nologin #sync:x:5:0: sync:/sbin:/bin/sync #shutdown:x:6:0: shutdown:/sbin:/sbin/shutdown #halt:x:7:0: halt:/sbin:/sbin/halt #uucp:x:10:14: uucp:/var/spool/uucp:/sbin/nologin #operator:x:11: 0perator:/root:/sbin/nologin #games:x:12:100: games

[Linux系统] 编写一个守护进程

懵懂的女人 提交于 2020-01-07 20:53:57
daemon.c文件: // daemon.c #include<stdio.h> #include<signal.h> #include<sys/param.h> #include<sys/types.h> #include<sys/stat.h> #include<stdlib.h> int init_daemon(void) { pid_t pid; int i; pid = fork(); if(pid > 0){ //第一步,结束父进程,使得子进程成为后台 exit(0); }else if(pid < 0){ return -1; } /*第二步建立一个新的进程组,在这个新的进程组中,子进程成为这个进程组的首进程,以使该进程脱离所用终端*/ setsid(); /*再次新建一个子进程,退出父进程,保证该进程不是进程组长,同时让该进程无法再打开一个新的终端*/ pid = fork(); if(pid > 0){ exit(0); }else if(pid < 0){ return -1; } //第三步:关闭所用从父进程继承的不再需要的文件描述符 for(i = 0;i < NOFILE;close(i++)); //第四步:改变工作目录,使得进程不与任何文件系统联系 chdir("/"); //第五步:将文件屏蔽字设置为0 umask(0); //第六步

\"Another MySQL daemon already running with the same unix socket.\"报错处理

 ̄綄美尐妖づ 提交于 2020-01-07 14:08:10
【问题发现】 1、访问zabbix页面显示数据库连接异常。 2、登录设备发现mysql异常,报错"Another MySQL daemon already running with the same unix socket." 【问题修复】 根据报错应是socket文件存在占用,删除mysql.sock文件 【出现原因】 虚拟机直接下电导致mysql进程未正常关闭。 来源: https://www.cnblogs.com/pzzning/p/12149917.html

Flask deployed with twistd: Failed to load application: 'NoneType' object has no attribute 'startswith'

亡梦爱人 提交于 2020-01-07 00:52:53
问题 I am trying to deploy my Twisted application using .tac files and twistd I tried to deploy it with the command line: twistd -y service.tac I have the error: ... application = getApplication(self.config, passphrase) --- <exception caught here> --- File "/usr/local/lib/python2.7/dist-packages/twisted/application/app.py", line 450, in getApplication application = service.loadApplication(filename, style, passphrase) File "/usr/local/lib/python2.7/dist-packages/twisted/application/service.py",

python多进程编程中常常能用到的几种方法

人走茶凉 提交于 2020-01-07 00:51:07
python中的多线程其实并不是真正的多线程,如果想要充分地使用多核CPU资源,在python中大部分情况需要使用多进程。python提供了非常好用的多进程包Multiprocessing,只需要定义一个函数,python会完成其它所有事情。借助这个包,可以轻松完成从单进程到并发执行的转换。multiprocessing支持子进程、通信和共享数据、执行不同形式的同步,提供了Process、Queue、Pipe、LocK等组件 一、Process 语法:Process([group[,target[,name[,args[,kwargs]]]]]) 参数含义:target表示调用对象;args表示调用对象的位置参数元祖;kwargs表示调用对象的字典。name为别名,groups实际上不会调用。 方法:is_alive():    join(timeout):    run():    start():    terminate(): 属性:authkey、daemon(要通过start()设置)、exitcode(进程在运行时为None、如果为-N,表示被信号N结束)、name、pid。其中daemon是父进程终止后自动终止,且自己不能产生新的进程,必须在start()之前设置。 1.创建函数,并将其作为单个进程 from multiprocessing import

Ansible-基础配置及常用模块

泪湿孤枕 提交于 2020-01-06 15:28:49
一、Ansible介绍 1.1、什么是ansible? Ansible是一个配置管理系统configuration management system, python 语言是运维人员必须会的语言, ansible 是一个基于python 开发的自动化运维工具, 其功能实现 基于ssh远程连接服务 , ansible 可以实现 批量系统配置,批量软件部署,批量文件拷贝,批量运行命令 等功能, 除了ansible之外,还有saltstack 等批量管理软件. 1.2、软件特点 1)ansible不需要单独安装客户端,SSH相当于ansible客户端。 2)ansible不需要启动任何服务,仅需安装对应工具即可。 3)ansible依赖大量的python模块来实现批量管理。 4)ansible配置文件 /etc/ansible/ansible.cfg 。 5)Ansible是一种agentless(基于ssh),可实现批量配置、命令执行和控制,基于Python实现的自动化运维工具。Ansible的两个特性: 模块化 :通过调用相关模块,完成指定任务,且支持任何语言编写的自定义模块; playbook :剧本,可根据需要一次执行完剧本中的所有任务或某些任务; 1.3、架构特点 1)连接插件(connectior plugins) :用于连接主机 用来连接被管理端。 2)核心模块(core