daemon

Python logging daemon destroys file handle

时光毁灭记忆、已成空白 提交于 2019-12-06 15:23:23
问题 My script logs to a file just fine until I try to fork it into the background at which point the file handle is closed, even if I use filesPreserve. How can I improve this in a lightweight fashion so that my logger runs in the background? #!/usr/bin/env python from socket import * import sys, time, logging import daemon context = daemon.DaemonContext() logger = logging.getLogger('audit') hdlr = logging.FileHandler('/mnt/audit.log') formatter = logging.Formatter('%(asctime)s %(message)s') hdlr

Java service on Linux - How to ensure constant uptime. Deamon, Shell script or Wrapper?

心已入冬 提交于 2019-12-06 15:18:57
I have a Java worker that are polling a external queue system for jobs, through web service calls. What is the most solid way to ensure that the worker is operating at any given time? JVM execution is not different from any other program. So what you want to do is to put together a shell script and place it in /etc/init.d and link it appropriatelly to to /etc/rc.d. On RedHat flavors it will ensure service startup with the system. Wring the script may be tricky, but I would copy one of existing ones and change it to call java executable with right parameters. In this script you would have to

Supervisorctl does not auto-restart daemon queue worker when hanging

谁都会走 提交于 2019-12-06 15:02:40
I have supervisorctl managing some daemon queue workers with this configuration : [program:jobdownloader] process_name=%(program_name)s_%(process_num)03d command=php /var/www/microservices/ppsatoms/artisan queue:work ppsjobdownloader --daemon --sleep=0 autostart=true autorestart=true user=root numprocs=50 redirect_stderr=true stdout_logfile=/mnt/@@sync/jobdownloader.log Sometimes some workers are like hanging (running but stop getting queue messages) and supervisorctl does not automatically restart them, so I have to monitor and manually restart them. Is there something wrong with the

File Monitoring Daemon on Unix

耗尽温柔 提交于 2019-12-06 14:48:37
问题 I am looking to write a file monitoring daemon that runs on Fedora 8 that monitors a file and reports back when the file was last modified in minutes. What would be the best way to do this, Im a bit of a newbie in terms of writing daemons like this? I guess I write a script? and then run this using a daemon. If anyone has any links to point me in the right direction it would be helpful :) 回答1: My choice would be to use the cron job manager. So you write a program in the language of your

如何写一个daemon程序

扶醉桌前 提交于 2019-12-06 13:56:17
在实际的服务器后台程序开发时,有时需要将某个服务 daemon 化来完成一些定时任务,比如往 KV 系统中刷新数据。 有两个问题需要提前弄清楚: daemon 程序中的 pid file 有什么作用? 为什么要二次fork,只fork一次可以吗? Daemon class 这是一个 Daemon class,继承此 class 的类需要 override 里面的 run 方法。 #!/usr/bin/env python import sys, os, time, atexit from signal import SIGTERM class Daemon: def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): self.stdin = stdin self.stdout = stdout self.stderr = stderr self.pidfile = pidfile def daemonize(self): try: pid = os.fork() if pid > 0: # exit first parent sys.exit(0) except OSError, e: sys.stderr.write("fork #1 failed: %d (%s

Automatically restarting HHVM when it stops responding but process not dead

情到浓时终转凉″ 提交于 2019-12-06 11:15:18
I'm having a problem where every 12-24 hours, HHVM crashes but it seems to leave the process running. It seems most providers just use php5-fpm as a failover within nginx for stability. However, this won't restart the non-responsive hhvm instance. Since the process is left running, most server monitoring solutions will see it as a live daemon, and not restart it. HTTP monitoring can be slow to react. Is it possible to trigger the hhvm restart on failover? If not, what would be the best solution to ensure a listening daemon that's non responsive is restarted. kristapsk posted a solution on

Launching command using NSTask returns error

[亡魂溺海] 提交于 2019-12-06 11:00:16
问题 I'd like to launch the following command from my application using NSTask: sudo -u myusername launchctl load /Library/LaunchAgents/com.google.keystone.agent.plist Here is a code I do: NSPipe *pipe = [NSPipe pipe]; NSTask *task = [[NSTask alloc] init]; [task setLaunchPath: @"/bin/sh"]; [task setCurrentDirectoryPath:@"/"]; [task setStandardError:pipe]; NSArray *arguments = nil; arguments = @[@"sudo", @"-u", @"myusername", @"launchctl", @"load", @"/Library/LaunchAgents/com.google.keystone.agent

Docker daemon does not start or restart

[亡魂溺海] 提交于 2019-12-06 10:17:18
I am on ubuntu 14.04 and I also upgrade docker to recent version. Whenever I do a sudo /etc/init.d/docker start I get a successful pid as follows, docker start/running, process 16267 When I view the PID details, I see nothing - ps -p 16267 PID TTY TIME CMD And when I try to do a sudo docker version I see the below - Client API version: 1.16 Go version (client): go1.2.1 OS/Arch (client): linux/amd64 2015/01/10 10:30:49 Cannot connect to the Docker daemon. Is 'docker -d' running on this host? The output of sudo docker -d is as follows, [2015-01-12T21:05:59.889680188+08:00] [info] docker daemon:

PHP 实现守护进程(Daemon)

試著忘記壹切 提交于 2019-12-06 09:55:24
守护进程(Daemon)是运行在后台的一种特殊进程。它独立于控制终端并且周期性地执行某种任务或等待处理某些发生的事件。守护进程是一种很有用的进程。php也可以实现守护进程的功能。 最近要开发一个 Agent,因为和 webserver 一起开发,所以 Agent也用PHP 开发。 功能需求: (1)需监听端口,接收控制器发来的任务消息; (2)根据任务消息,启动执行任务,并监控任务状态; (3)将任务运行结果反馈给控制器; 开始使用 workerman 框架,但是发现框架虽好,但也有很多限制。 1、基本概念 进程:每个进程都有一个父进程,子进程退出,父进程能得到子进程退出的状态。 进程组:每个进程都属于一个进程组,每个进程组都有一个进程组号,该号等于该进程组组长的PID 2、守护进程编程要点 1. 在后台运行。 为避免挂起控制终端将Daemon放入后台执行。方法是在进程中调用fork使父进程终止,让Daemon在子进程中后台执行。 if($pid=pcntl_fork()) exit(0);//是父进程,结束父进程,子进程继续 2. 脱离控制终端,登录会话和进程组 有必要先介绍一下Linux中的进程与控制终端,登录会话和进程组之间的关系:进程属于一个进程组,进程组号(GID)就是进程组长的进程号(PID)。登录会话可以包含多个进程组。这些进程组共享一个控制终端

Catch RuntimeExceptions in Java application and send them via email

假装没事ソ 提交于 2019-12-06 09:23:27
问题 I'm starting my app on Linux server with a command like this /usr/local/bin/jsvc \ -home /usr/local/jdk1.8.0_111 \ -cp /opt/myapp/myapp.jar:/opt/myapp/lib/* \ -user myappuser \ -outfile /opt/myapp/out.log \ -errfile /opt/myapp/error.log \ -pidfile /opt/myapp/myapp.pid \ com.example.MyApp I'm using log4j for logging in my app and it has own configuration described in log4j.properties which is located inside myapp.jar . I want to be able to catch any exception which happens in the app and to