Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用systemd管理一组重新招聘的员工?_Ruby On Rails_Systemd_Resque_Upstart_Ubuntu 18.04 - Fatal编程技术网

Ruby on rails 如何使用systemd管理一组重新招聘的员工?

Ruby on rails 如何使用systemd管理一组重新招聘的员工?,ruby-on-rails,systemd,resque,upstart,ubuntu-18.04,Ruby On Rails,Systemd,Resque,Upstart,Ubuntu 18.04,我正在尝试将对一组resque工作人员的控制权从upstart迁移到systemd。在upstart下,我们能够有两个控制脚本,一个脚本定义一个工作程序,另一个脚本多次调用第一个脚本,用一个upstart命令启动或停止多个工作程序。我们正在尝试使用systemd实现相同的功能 我曾经尝试过每个工作人员使用一个systemd单元,所以如果我们试图管理6个工作人员,我们会使用6个单独的systemd单元脚本,每个工作人员一个。然后,我们使用bash脚本来触发: systemctl start|sto

我正在尝试将对一组resque工作人员的控制权从upstart迁移到systemd。在upstart下,我们能够有两个控制脚本,一个脚本定义一个工作程序,另一个脚本多次调用第一个脚本,用一个upstart命令启动或停止多个工作程序。我们正在尝试使用systemd实现相同的功能

我曾经尝试过每个工作人员使用一个systemd单元,所以如果我们试图管理6个工作人员,我们会使用6个单独的systemd单元脚本,每个工作人员一个。然后,我们使用bash脚本来触发:

systemctl start|stop|restart worker-1.service &
systemctl start|stop|restart worker-2.service &
...
问题在于,当我们通过systemctl发送kill信号时,它会立即终止父级resque进程,导致任何分叉的童工立即死亡,而不是在死亡前完成他们的工作。我们能够使用upstart实现这个确切的行为,其中父进程不接受新作业(将停止分叉),子工作进程在作业中工作时被允许保持活动状态,在作业完成后,子工作进程将自行死亡

在系统D下,所有工人都会立即死亡,工作在完成之前中途终止

我们的systemd单元脚本如下所示:

[Unit]
Description=Controls a single Resque worker process: worker-1
After=redis.service

[Service]
Restart=on-failure
RestartSec=10
StartLimitInterval=400
StartLimitBurst=5
KillSignal=SIGQUIT

User=www-data
WorkingDirectory=/app/working/dir
Type=single
ExecStart=/usr/bin/bundle exec rake production resque:work QUEUE=a,b,c,d,e,f
ExecStop=/bin/kill -QUIT $MAINPID

[Install]
WantedBy=multi-user.target
systemctl $COMMAND resque-worker-1.service &
我尝试过将Type=single更改为Type=forking,但该流程不会持续运行,它会尝试启动,然后在没有作业可用时启动,因为父流程只有在有作业时才会分叉,因此该流程会终止并无法继续运行。使用Type=simple时,流程按预期工作,但如上所述,我们无法像使用upstart那样优雅地控制它们

我们的bash脚本如下所示:

[Unit]
Description=Controls a single Resque worker process: worker-1
After=redis.service

[Service]
Restart=on-failure
RestartSec=10
StartLimitInterval=400
StartLimitBurst=5
KillSignal=SIGQUIT

User=www-data
WorkingDirectory=/app/working/dir
Type=single
ExecStart=/usr/bin/bundle exec rake production resque:work QUEUE=a,b,c,d,e,f
ExecStop=/bin/kill -QUIT $MAINPID

[Install]
WantedBy=multi-user.target
systemctl $COMMAND resque-worker-1.service &
其中每个辅助服务都有一个命令$命令只是传递给脚本的一个参数(start | stop | restart)

以前使用的upstart脚本:

从运行级别开始[2345] 在运行级别停止[06]


杀死信号退出

我想我自己解决了这个问题。通过删除此指令:

ExecStop=/bin/kill -QUIT $MAINPID
KillMode=process
SendSIGKILL=no
当我发出systemctl stop resque-worker-n.service now时,它会优雅地等待作业完成,然后杀死该工人

注意到某些工作仍会立即退出,因此添加了此指令:

ExecStop=/bin/kill -QUIT $MAINPID
KillMode=process
SendSIGKILL=no
但随后注意到,当稍后重新启动workers时,“已完成”的作业被resque视为可排队,因此会再次错误地排队。因此,增加了本指令:

ExecStop=/bin/kill -QUIT $MAINPID
KillMode=process
SendSIGKILL=no
现在的行为似乎和以前使用upstart时的行为相同