我只是对Linux有所了解,而且由于目录问题,我似乎无法让start-stop-daemon运行python脚本。在linux文件结构中,我有以下文件:
~/test.txt
THIS LINE IS A TEST
~/test.py
#!/usr/bin/python
import time
with open("test.txt") as f:
while True:
try:
print("Hello World")
print(f.readline())
t
这是我正在使用的守护进程类。
它充当一个基类,我想从另一个控制器文件中派生2个独立的守护进程。
class Daemon:
"""A generic daemon class.
Usage: subclass the daemon class and override the run() method."""
def __init__(self, pidfile,outfile='/tmp/daemon_out',errfile='/tmp/daemon_log'):
最后,我在守护进程中成功地转换了脚本的进程,经过几个小时的测试,我发现在守护进程中转换的脚本不执行以下操作:
out_file = open("test.txt","w")
out_file.write("")
out_file.close()
我的剧本是这样写的:
class daemon: # taken here https://web.archive.org/web/20160305151936/http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_pyth
我为bitcoind提供了一个upstart脚本,它基于本主题中的脚本:
我强烈需要重生未来的工作:如果发生了什么事,比特币应该自动重新启动。我试着模仿这种情况,但暴发户并没有重新启动这个过程。
问题:如果发生了一些不好的事情,我如何使新启动(或其他什么)观看和重新启动它?
实际脚本:
description "bitcoind"
start on filesystem
stop on runlevel [!2345]
oom never
expect daemon
respawn
respawn limit 10 60 # 10 times in 60 seconds
s
我使用下面的代码在我的服务器上运行脚本的一个实例。我有一个cronjob来每分钟运行一次。
#!/bin/bash
if [[ $# < 1 ]]; then
echo "Name of pid file not given."
exit
fi
# Get the pid file's name.
PIDFILE=$1
shift
if [[ $# < 1 ]]; then
echo "No command given."
exit
fi
echo "Checking pid in file
我不能通过init脚本关闭我的redis服务器。这有的巨大副作用,当我做sudo reboot时挂起我的机器。
我使用新安装了redis,将其配置为接受unix套接字上的连接,现在正在尝试stop服务器,以便恢复以前保存的.rdb转储。
但我不断得到以下信息:
Could not connect to Redis at 127.0.0.1:0: Connection refused
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiting for Redis to shutdown ...
Waiti
我有一个启动Python进程的daemon脚本。我能够通过使用在:上找到的代码来做到这一点。
代码完全按照预期启动daemon进程。但是,当daemon进程停止时,运行中的作业有时甚至只是有时会停止运行。
代码的stop函数是:
def stop(self):
"""
Stop the daemon
"""
# Get the pid from the pidfile
try:
pf = file(self.pidfile, &
我有一个java程序,它作为服务在linux盒中运行。我有shell脚本文件,它有下面的行来启动程序。
$EXEC -home "$JAVA_HOME" -cp "$CLASS_PATH" -outfile "$LOG_OUT" -errfile "$LOG_ERR" -pidfile "$PID" $1 $CLASS
$CLASS_PATH has class path
$CLASS has the name of main class
EXEC="/usr/bin/jsvc"
我可以使用以下
我正在做一个很棒的小功能:
def startProcess(name, path):
"""
Starts a process in the background and writes a PID file
returns integer: pid
"""
# Check if the process is already running
status, pid = processStatus(name)
if status == RUNNING:
raise Alr
我在运行Apache,并试图通过Monit监控它。监视似乎运行良好,但是当Apache关闭时,Monit无法启动它。
Monit确实检测到它已关闭,但是start命令失败了。
下面是monit配置
check process httpd with pidfile /var/run/httpd.pid
start program = "/usr/bin/apachestart start"
stop program = "/etc/init.d/httpd stop"
if failed host 127.0.0.1 port 80
protocol http t