我正在systemd为 OSSEC HIDS编写单元文件。问题是,当systemd启动服务时,它会立即停止它们。
当我使用以下ExecStart指令时,一切正常。
ExecStart=/var/ossec/bin/ossec-control start
Run Code Online (Sandbox Code Playgroud)
但是当我进行以下小的改进时,我在 OSSEC 日志中发现它SIG 15在启动后收到。
ExecStart=/bin/sh -c '${DIRECTORY}/bin/ossec-control start'
Run Code Online (Sandbox Code Playgroud)
如果我再做一个小的更改,服务将SIG 15在 20 秒后收到。
ExecStart=/bin/sh -c '${DIRECTORY}/bin/ossec-control start && sleep 20'
Run Code Online (Sandbox Code Playgroud)
所以,我想,这会在服务启动后systemd杀死/bin/sh进程,/bin/sh然后杀死OSSEC.
我怎么解决这个问题?
我想用我的Django项目使用uwsgi
我测试usgi --ini uwsgi.ini 效果很好
而我想写进去systemd控制它
面对错误
这是我的文件
/etc/systemd/system/mysite.service
[Unit]
Description=uWSGI for proj
After=syslog.target
[Service]
Restart=always
ExecStart=/usr/bin/uwsgi --ini /usr/share/nginx/ENV/proj/proj/uwsgi.ini
StandardError=syslog
KillSignal=SIGQUIT
Type=forking
NotifyAccess=main
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
我第一次使用systemctl restart mysite.service
它效果很好,然后我使用systemctl stop mysite.service
然后重新启动systemctl restart mysite.service
但是停止后它无法重新启动
我收到错误:
proj.service - uWSGI for proj
Loaded: loaded (/usr/lib/systemd/system/proj.service; disabled)
Active: failed (Result: start-limit) since Fri 2015-11-13 13:40:35 CST; 887ms ago
Process: 4297 ExecStart=/usr/bin/uwsgi --ini /usr/share/nginx/ENV/proj/proj/uwsgi.ini (code=exited, status=0/SUCCESS)
Main PID: 4298 (code=exited, status=0/SUCCESS)
Nov 13 13:40:35 localhost.localdomain systemd[1]: proj.service …Run Code Online (Sandbox Code Playgroud) 我正在开发一个主要启动系统是 runit 的系统。
不幸的是,runit 要求它运行的任何应用程序都像这样在前台运行:
#!/bin/bash
exec sshd -D
Run Code Online (Sandbox Code Playgroud)
看到 nginx 没有提供在前台运行它的方法,我如何让 runit 仍然管理 nginx 并能够使用 runit 的sv命令停止、启动和重新启动它?
我不完全确定我正在尝试做的事情是否可行。我想将 vbox 虚拟机作为服务运行并在启动时启用它。这是我的 .service 脚本:
[Unit]
Description=Virtualbox Headless VM
Wants=network-online.target
After=network-online.target
[Service]
Type=forking
ExecStart=/usr/bin/VBoxHeadless -s vbox_uuid
ExecStop=/usr/bin/VBoxManage controlvm vbox_uuid poweroff
User=myuser
[Install]
WantedBy=muti-user.target
Run Code Online (Sandbox Code Playgroud)
当我尝试正常启动时,我的 cli 挂起并且不会分叉该过程。有人有任何想法/想法/建议吗?
systemctl status 给了我这个:
Jun 20 07:17:07 localhost.localdomain systemd[1]: Starting Virtualbox Headless VM...
Jun 20 07:17:09 localhost.localdomain pulseaudio[4143]: [pulseaudio] socket-server.c: bind(): Address already in use
Jun 20 07:17:09 localhost.localdomain pulseaudio[4143]: [pulseaudio] module.c: Failed to load module "module-esound-protocol-unix" (argument: ""): initialization failed.
Jun 20 07:17:09 localhost.localdomain pulseaudio[4143]: [pulseaudio] main.c: Module load failed.
Jun 20 07:17:09 localhost.localdomain …Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个 systemd 守护进程。我面临的问题是守护进程在蜜蜂启动后 1 分 30 秒被杀死,因为没有检测到分叉。
我正在使用该int daemon(int nochdir, int noclose)函数来守护进程。
int main()
{
openlog("shutdownd", LOG_PID, LOG_DAEMON);
if(daemon(0, 0) != 0)
{
syslog(LOG_ERR, "Error daemonizing process : %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
syslog(LOG_NOTICE, "Daemon started !\n");
pthread_create(&threads[0], NULL, &alimThread, NULL);
pthread_create(&threads[1], NULL, &extinctThread, NULL);
pthread_create(&threads[2], NULL, &blinkThread, NULL);
while(1)
{
}
syslog(LOG_NOTICE, "Daemon stopped !\n");
exit(EXIT_SUCCESS);
}
Run Code Online (Sandbox Code Playgroud)
这是服务文件 /etc/systemd/system/shutdownd.service
[Unit]
Description=Shutdown Daemon
After=syslog.target
[Service]
Type=forking
PIDFile=/var/run/shutdownd.pid
ExecStartPre=/bin/rm -f /var/run/shutdownd.pid
ExecStartPre=/usr/bin/shutdownd-exportGpio.sh
ExecStart=/usr/bin/shutdownd
Restart=on-abort
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)
守护程序函数应该派生进程并将其与终端分离,我还关闭文件描述符并将工作目录更改为 /。
然而,systemd 似乎没有检测到分叉,因为它在 …