我需要从 Debian 中的应用程序创建一个守护进程。在 Debian 中是否有任何标准工具,例如 Ubuntu 中的“新贵”?我只需要启动-停止命令,就可以使用一些选项和 pid 文件将程序作为守护进程启动,并用 pid 文件杀死它。
我查看了 init.d,但似乎这些用于启动时启动。我想手动启动我的守护进程。
我在 Debian 有很长的运行过程。在某些时候抛出错误:
打开的文件太多。
跑步:
ulimit -a
显示:
打开文件 (-n) 1024
我希望将打开文件的数量增加 2 倍。执行后
ulimit -n 2048
该限制在我的会话结束前一直有效,这不适用于该任务。
如何永久增加打开文件的数量?
我正在寻找一种标准方法或最佳实践来保持由init.dshell 脚本启动的守护进程。
或者更好的是,有没有办法让它直接从/etc/init.d?
具体来说,我有一个名为 dtnd 的守护进程,它具有无限循环,用于查找意外结束的进程,如果有的话,守护进程会再次唤醒它们。此外,我使用 start-stop-daemon 工具来让进程从给定的系统用户运行。
我想从启动时运行这个 dtnd 守护进程。为了实现这种行为,我创建了一个 init.d 脚本,它使用 start、stop 和 status 命令“包装”dtnd 文件。
我有两个问题要解决:
有没有办法从 init.d shell 脚本中实现使某些进程保持活动状态。是标准/最佳实践吗?
建议使用无限循环保持进程存活?我想最好使用一些命令respawn来实现这一点。这是正确的?
我知道respawn命令的存在。我认为这就是我需要的,但我不明白之间的工作流程/etc/init.d/和/etc/init。谁能帮我?
请注意,我没有inittab文件既没有暴发户(我只被允许使用/etc/init,/etc/init.d,cron和系统工具start-stop-daemon。我的意思是,只有默认工具)
非常感谢您的参与!
我用 PHP 开发了一个爬虫,它解析一个带有特定标头的 URL,并将所有内容的 URL 放入队列中。它工作正常。
我在 ubuntu 14.04 中开发了这段代码,并在 /etc/init 文件夹中放置了一个 .conf 文件,其中包含以下内容:
# Info
description "Warm the varnish to get the list of products"
author "Juanjo Aguilella"
# Events
start on startup
stop on shutdown
# Automatically respawn
respawn
respawn limit 100 5
# Run the script
# Note, in this example, if your PHP script return
# the string "ERROR", the daemon will stop itself.
script
[ $(exec /usr/bin/php -f /var/www/crawler.php) = 'ERROR' ] && ( stop; …Run Code Online (Sandbox Code Playgroud) 如果我使用 NTP 守护进程或 ntpdate 命令,我是否需要担心更改时区?
我是否应该使用 cron 作业重新配置时区以保证服务器时间的准确性?
我正在使用 ubuntu 服务器。
在 Ubuntu 服务器上运行 Monit 5.4。当我使用 时monit reload,它似乎会重新启动受监控的服务(在这种情况下为 Tomcat 7)。这是预期的行为吗?文档说:
reload - 重新初始化正在运行的 Monit 守护进程,守护进程将重新读取其配置,关闭并重新打开日志文件。
我希望它不会重新启动任何服务,而只会重新加载它的配置,这样我就可以更改电子邮件警报和其他内容。
这是输出 monit status
The Monit daemon 5.4 uptime: 15h 0m
Process 'tomcat7'
status Running
monitoring status Monitored
pid 38842
parent pid 1
uptime 14h 30m
children 0
memory kilobytes 3445964
memory kilobytes total 3445964
memory percent 10.4%
memory percent total 10.4%
cpu percent 14.8%
cpu percent total 14.8%
port response time 0.018s to localhost:80 [HTTP via TCP]
data collected Tue, 17 …Run Code Online (Sandbox Code Playgroud) 我有一个通常使用以下命令运行的 python 脚本:
(environment) python run.py
Run Code Online (Sandbox Code Playgroud)
我想在开始时运行这个脚本。(我正在使用 ubuntu)这是我的服务:
[Unit]
Description=My Script Service
After=multi-user.target
[Service]
Type=idle
ExecStart=/home/user/anaconda3/bin/python /home/user/space/run.py
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我无法运行这个脚本,但我可以运行任何不在环境内部的脚本。如何在启动时运行 python 脚本(virtualenv)?
sudo systemctl status user_sent
? user_sent.service - Mail Service
Loaded: loaded (/lib/systemd/system/user_sent.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since xxxxx 16:30:20 MSK; 3s ago
Process: 3713 ExecStart=/usr/bin/python run.py (code=exited, status=200/CHDIR)
Main PID: 3713 (code=exited, status=200/CHDIR)
Run Code Online (Sandbox Code Playgroud) 我需要守护在 Wine 中运行的 Windows 应用程序,并在/var/run. 由于它需要 X11 会话才能运行,因此我需要确保在运行用户的环境中设置了 $DISPLAY 变量。
假设我已经有一个 X11 会话在运行,并带有给定的显示,下面是我的/etc/init.d脚本中的 start-stop-daemon 行:
start-stop-daemon --start --pidfile /var/run/wine-app.pid -m -c myuser -g mygroup -k 002 --exec /home/myuser/.wine/drive_c/Program\ Files/wine-app.exe
Run Code Online (Sandbox Code Playgroud)
不幸的是,我在 Ubuntu 8.04 上的 start-stop-daemon 版本没有-e设置环境变量的选项。我认为您可以在命令之前简单地设置 $DISPLAY,如下所示:
VAR1="Value" start-stop-daemon ...
Run Code Online (Sandbox Code Playgroud)
但它不起作用。由于我使用该-c {user}选项以特定用户身份运行,因此我猜测有一个环境切换并且 VAR1 丢失了。我试过从正在运行的用户.profile和/或导出 DISPLAY,.bashrc但它也不起作用。
有没有另一种方法可以做到这一点?这甚至可能吗?我是否忽略了什么?
守护进程和服务之间有区别吗?
或者它们基本上都是驻留在内存中的应用程序,并绑定到特定端口并侦听/响应请求?
我有一个想要守护进程的 Perl 脚本。基本上这个 perl 脚本将每 30 秒读取一个目录,读取它找到的文件,然后处理数据。为了简单起见,请考虑以下 Perl 脚本(称为 synpipe_server,在 中有此脚本的符号链接/usr/sbin/):
#!/usr/bin/perl
use strict;
use warnings;
my $continue = 1;
$SIG{'TERM'} = sub { $continue = 0; print "Caught TERM signal\n"; };
$SIG{'INT'} = sub { $continue = 0; print "Caught INT signal\n"; };
my $i = 0;
while ($continue) {
#do stuff
print "Hello, I am running " . ++$i . "\n";
sleep 3;
}
Run Code Online (Sandbox Code Playgroud)
所以这个脚本基本上每 3 秒打印一次。
然后,因为我想守护这个脚本,我也把这个 bash 脚本(也称为 synpipe_server)放在/etc/init.d/:
#!/bin/bash
# synpipe_server …Run Code Online (Sandbox Code Playgroud) daemon ×10
linux ×5
debian ×4
ubuntu ×3
init.d ×2
debian-lenny ×1
filesystems ×1
init ×1
monit ×1
ntp ×1
ntpd ×1
pid ×1
python ×1
service ×1
startup ×1
systemd ×1
ubuntu-16.04 ×1
unix ×1
upstart ×1
virtualenv ×1