我正在尝试控制基于 python 的程序(它不会与控制台分离)
#!/bin/bash
user=nobody
pid=/var/run/xx.pid
name=xx
prog=/xx.py
case $1 in
start)
/sbin/start-stop-daemon --start -b --oknodo --user "$user" --name "$name" --pidfile "$pid" --startas "$prog" --chuid nobody -- --daemon
;;
stop)
/sbin/start-stop-daemon --stop --oknodo --user "$user" --name "$name" --pidfile "$pid" --retry=TERM/5/KILL/1
;;
restart)
;;
*)
;;
esac
Run Code Online (Sandbox Code Playgroud)
开始部分工作正常。我可以看到脚本正在运行,但停止部分没有。它简单地说No xx found running; none killed.
所以我猜开始部分有问题?
当我输入sudo service networking restart时,出现如下所示的错误:
edward@computer:~$ sudo service networking restart
stop: Job failed while stopping
start: Job is already running: networking
Run Code Online (Sandbox Code Playgroud)
当我想networking在更改 mac 地址后以及在/etc/network/interfaces文件中设置静态 IP 后重新启动时出现此错误。
即使在恢复这些更改并且我的计算机工作正常后,我也会遇到同样的错误。
在查看时,/var/log/syslog我发现了这一点:
kernel: [ 6448.036144] init: networking post-stop process (28701)
terminated with status 100
Run Code Online (Sandbox Code Playgroud)
这与失败的停止/启动有关吗?
我在 Ubuntu 14.04
我有一个新贵脚本来在 RedHat 6 中创建一个服务:
env PLAY_BINARY=/usr/bin/play
env HOME=/opt/warda
env USER=root
env GROUP=root
[...]
script
exec start-stop-daemon --start --exec $PLAY_BINARY --chuid $USER:$GROUP --chdir $HOME --start $HOME
end script
Run Code Online (Sandbox Code Playgroud)
在 Ubuntu 中一切正常。
但是在 RedHat 中,当我启动时sudo initctl start play,我得到了成功的反馈play start/running,但play没有运行。
我认为这个问题start-stop-daemon在 RedHat 中不存在。
如何替换exec start-stop-daemon...命令?
我尝试使用以下方法启动 monit:
/etc/init.d/monit start
Run Code Online (Sandbox Code Playgroud)
然后我得到错误:
[....] Starting daemon monitor: monit/etc/init.d/monit: 124: /etc/init.d/monit: start-stop-daemon: not found
failed!
Run Code Online (Sandbox Code Playgroud)
打字
which start-stop-daemon
Run Code Online (Sandbox Code Playgroud)
显示
/sbin/start-stop-daemon
Run Code Online (Sandbox Code Playgroud)
/sbin 中的 ls -al 显示
-rwxr-xr-x 1 root root 26740 Jan 21 12:18 start-stop-daemon
Run Code Online (Sandbox Code Playgroud)
编辑:添加脚本
#!/bin/sh
### BEGIN INIT INFO
# Provides: monit
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Should-Start: $all
# Should-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: service and resource monitoring daemon
# Description: monit is a utility …Run Code Online (Sandbox Code Playgroud) 我正在学习如何使用 systemd 创建服务。我收到此错误:
.service: Start request repeated too quickly.
Run Code Online (Sandbox Code Playgroud)
我无法再启动服务;它昨天正在工作。我究竟做错了什么?
(root@Kundrum)-(11:03:19)-(~)
$nano /lib/systemd/system/swatchWATCH.service
1 [Unit]
2 Description=Monitor Logfiles and send Mail reports
3 After=syslog.target network.target
4
5 [Service]
6 Type=simple
7 ExecStart=/usr/bin/swatch --config-file=/home/kristjan/.swatchrc --input-record-separator="\n \n " --tail-file=/var/log/snort/alert --daemon
8 Restart=on-failure
9 StartLimitInterval=3
10 StartLimitBurst=100
11
12 [Install]
13 WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
StartLimitInterval而StartLimitBurst我试图修复它之后添加。
我的系统是 Debian 9.8 Stretch 所有更新。
我试图在我的 Debian 机器上运行 Google AppEngine,我创建了一个文件init.d/gae:
. /lib/lsb/init-functions
#
# Initialize variables
#
name=gae
user=$name
pid=/var/run/$name.pid
prog="python /opt/google_appengine/dev_appserver.py --host=0.0.0.0 --admin_host=0.0.0.0 --php_executable_path=/usr/bin/php-cgi /var/www"
case "${1}" in
start)
echo "Starting...Google App Engine"
start-stop-daemon --start --make-pidfile --background --oknodo --user "$user" --name "$name" --pidfile "$pid" --startas "$prog"
;;
stop)
echo "Stopping...Google App Engine"
;;
restart)
${0} stop
sleep 1
${0} start
;;
*)
echo "Usage: ${0} {start|stop|restart}"
exit 1
;;
esac
exit 0
# End scriptname
Run Code Online (Sandbox Code Playgroud)
我正在通过手动调用来测试脚本,并且脚本运行但不是作为守护程序运行,或者至少它不会与终端分离。我期待/寻找与 Apache 类似的功能。
我缺少什么开关?
编辑
我应该注意到,尽管开关指示应该创建它,但没有写入或创建 PID …
我最近编写了一个 Python 程序,旨在通过 SMPP SMS 服务器进行通信。
我面临的问题是我不知道如何使用 Conda 虚拟环境在 Cent OS 服务器上将 Python 脚本作为服务运行。我使用了很多依赖项,在 Conda 上选择虚拟环境不是一种选择。
有什么办法可以将此脚本作为服务运行吗?还有一种方法可以使用以下方法编写控制台方法来启动此脚本吗?
service fooService start
Run Code Online (Sandbox Code Playgroud) python services start-stop-daemon virtualenv datascience-anaconda
我正在编写一个守护进程来使用 jsvc 和这个(可能是 pre-systemd)教程在无头Ubuntu 16.04 机器上管理我的 Java 应用程序,并且尽可能运行,收到错误update-rc.d mydaemon enable
update-rc.d: error: mydaemon Default-Start contains no runlevels, aborting
已经用Google搜索了一下周围,这似乎有一些做的(相当?)最近将systemd,我已经证实与运行pidof systemd。
我如何实现与启动时相同的行为update-rc.d(更重要的是通过停止服务/etc/init.d/mydaemon stop而不是仅仅终止进程,因为 Java 应用程序需要清理)。而且是systemd和update-rc.d不同的系统,还是systemd只是改变后者如何工作的?
我正在尝试从错误的安装中恢复,并且想要删除一些软件包。但我不能。
# apt autoremove offending-package
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
Run Code Online (Sandbox Code Playgroud)
(我的路径没问题。)
根据packages.debian.org,start-stop-daemon 应该位于/sbin/.
它不在那里!我应该怎么办?