I have two recipe in my AWS OpsWorks custom cookbook
First one is 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
and the second one is 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
The supervisor_service
is provided from here .
At first I tried executing the first recipe in running instances. The execution succeeded and the supervisor was running smoothly.
The second recipe is basically updating the code run by the supervisor. So I need to restart the supervisor. But the then I got this error everytime I executed the service.
================================================================================
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
What am I doing wrong?
I put include_recipe 'supervisor'
in the file 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
But when I execute myserver::update_code
in my AWS OpsWorks, it still returns error below, but with a new section 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
UPDATE
I finally use this manual execution
execute "supervisor-restart-mylistener" do
command "supervisorctl restart mylistener:*"
end
But still trying to figure out why the notifies
doesn't work.
I was getting the same error but it was due to a bug in the supervisor cookbook. https://github.com/poise/supervisor/issues/43
I reverted back to the Supervisor cookbook 0.4.2 and it works fine again.
Unless you're including both of those recipes in the run_list or using include_recipe
, this error is correct. If update_code.rb
notifies supervisor_service
, then the supervisor.rb
recipe is a "dependency" of that recipe. You should add the following to the top of your update_code.rb
:
include_recipe 'myserver::supervisor'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.