0

我的 AWS OpsWorks 自定义食谱中有两个食谱

第一个是myserver/recipes/supervisor.rb

 #myserver::supervisor

 supervisor_service "mylistener" do
      command "/usr/bin/php /var/www/listener.php"
      autostart true
      autorestart true
      numprocs 1
      process_name "%(program_name)s-%(process_num)s"
 end

第二个是myserver/recipes/update_code.rb

 #myserver::update_code
 include_recipe "myserver::supervisor"
 execute "update_code" do
     command %Q {
         /usr/local/bin/downloadfile.sh
         /usr/local/bin/changelink.sh
     }
     notifies :restart, "supervisor_service[mylistener]"
 end

supervisor_service是从这里提供的。

起初我尝试在运行实例中执行第一个配方。执行成功,supervisor运行顺利。

第二个秘诀基本上是更新主管运行的代码。所以我需要重新启动主管。但是每次执行服务时我都会收到此错误。

================================================================================
Error executing action `restart` on resource 'supervisor_service[mylistener]'
================================================================================


RuntimeError
------------
Supervisor service mylistener cannot be restarted because it does not exist


Resource Declaration:
---------------------
# In /opt/aws/opsworks/releases/20140116091718_218/site-cookbooks/myserver/recipes/supervisor.rb

9: supervisor_service "mylistener" do
10:     command "/usr/bin/php /var/www/listener.php"
11:     autostart true
12:     autorestart true
13:     numprocs 1
14:     process_name "%(program_name)s-%(process_num)s"
15: end

我究竟做错了什么?

更新

我把include_recipe 'supervisor'文件放进去myserver/recipes/supervisor.rb

#myserver::supervisor
include_recipe 'supervisor'

supervisor_service "mylistener" do
    command "/usr/bin/php /var/www/listener.php"
    autostart true
    autorestart true
    numprocs 1
    process_name "%(program_name)s-%(process_num)s"
end

但是当我myserver::update_code在我的 AWS OpsWorks 中执行时,它仍然在下面返回错误,但带有一个新部分Compiled Resource

================================================================================
Error executing action `restart` on resource 'supervisor_service[mylistener]'
================================================================================


RuntimeError
------------
Supervisor service mylistener cannot be restarted because it does not exist


Resource Declaration:
---------------------
# In /opt/aws/opsworks/releases/20140116091718_218/site-cookbooks/myrecipe/recipes/supervisor.rb

11: supervisor_service "mylistener" do
12:     command "/usr/bin/php /var/www/listener.php"
13:     autostart true
14:     autorestart true
15:     numprocs 1
16:     process_name "%(program_name)s-%(process_num)s"
17: end

Compiled Resource:
------------------
# Declared in /opt/aws/opsworks/releases/20140116091718_218/site-cookbooks/myserver/recipes/supervisor.rb:11:in `from_file'

supervisor_service("mylistener") do
priority 999
numprocs_start 0
autorestart true
retries 0
updated true
stderr_capture_maxbytes "0"
exitcodes [0, 2]
stderr_logfile "/var/log/mylistener.err.log"
cookbook_name :myserver
stdout_capture_maxbytes "0"
autostart true
recipe_name "supervisor"
serverurl "AUTO"
action :enable
stderr_logfile_backups 10
startretries 3
process_name "%(program_name)s-%(process_num)s"
stdout_logfile_backups 10
stopwaitsecs 10
stderr_logfile_maxbytes "50MB"
startsecs 1
numprocs 1
retry_delay 2
stdout_logfile_maxbytes "50MB"
command "/usr/bin/php /var/www/listener.php"
stopsignal :TERM
service_name "mylistener"
stdout_logfile "/var/log/mylistener.out.log"
end

更新

我终于用这个手动执行

execute "supervisor-restart-mylistener" do
    command "supervisorctl restart mylistener:*"
end

但仍然试图找出为什么notifies不起作用。

4

2 回答 2

1

我遇到了同样的错误,但这是由于主管食谱中的一个错误。 https://github.com/poise/supervisor/issues/43

我恢复到Supervisor cookbook 0.4.2,它又可以正常工作了。

于 2014-07-22T06:16:11.423 回答
0

除非您将这两个配方都包含在 run_list 或 using 中include_recipe,否则此错误是正确的。如果update_code.rbnotify supervisor_service,则supervisor.rb配方是该配方的“依赖项”。您应该将以下内容添加到您的顶部update_code.rb

include_recipe 'myserver::supervisor'
于 2014-02-03T17:09:13.803 回答