From 7b2927deac7cd69aba41748d9943da505ba68c45 Mon Sep 17 00:00:00 2001 From: Sebastian Baum Date: Mon, 18 Sep 2017 07:34:55 +0200 Subject: [PATCH 1/6] - Added support for php artisan migrate:status --- CHANGELOG.md | 3 +++ README.md | 24 +++++++++++++----------- metadata.rb | 2 +- recipes/migrate_status.rb | 15 +++++++++++++++ 4 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 recipes/migrate_status.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e0019c..8f76db7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Laravel-Artisan Cookbook Changelog +## 0.5.0 +* Added support of `php artisan migrate:status` + ## 0.4.0 * Added support of `php artisan schedule:run` * Added a possibility to disable running of `php artisan schedule:run` diff --git a/README.md b/README.md index 50a9628..a792e77 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ Commands that are particular useful for development are not supported. * cache:clear * config:cache * config:clear +* migrate:status * package:discover * schedule:run * view:clear @@ -76,14 +77,15 @@ Using AWS Opsworks you can pass in the path via custom json: ``` ### Recipes -* `laravel-artisan::clear-compiled` Remove the compiled class file -* `laravel-artisan::down` Put the application into maintenance mode. -* `laravel-artisan::env` Display the current framework environment. -* `laravel-aritsan::up` Bring the application out of maintenance mode. -* `laravel-artisan::cache_clear` Flush the application cache. -* `laravel-artisan::config_cache` Create a cache file for faster configuration loading. -* `laravel-artisan::config_clear` Remove the configuaration cache file. -* `laravel-artisan::package_discover` Rebuild the cached package manifest. -* `laravel-artisan::schedule_run` Run the scheduled commands. -* `laravel-artisan::schedule_remove` Remove the cronjob that runs `php artisan schedule:run` -* `laravel-artisan::view_clear` Clear all compiled view files. \ No newline at end of file +* `laravel-artisan::clear-compiled` - Remove the compiled class file +* `laravel-artisan::down` - Put the application into maintenance mode. +* `laravel-artisan::env` - Display the current framework environment. +* `laravel-aritsan::up` - Bring the application out of maintenance mode. +* `laravel-artisan::cache_clear` - Flush the application cache. +* `laravel-artisan::config_cache` - Create a cache file for faster configuration loading. +* `laravel-artisan::config_clear` - Remove the configuaration cache file. +* `laravel-artisan::migrate_status` - Show the status of each migration. +* `laravel-artisan::package_discover` - Rebuild the cached package manifest. +* `laravel-artisan::schedule_run` - Run the scheduled commands. +* `laravel-artisan::schedule_remove` - Remove the cronjob that runs `php artisan schedule:run` +* `laravel-artisan::view_clear` - Clear all compiled view files. \ No newline at end of file diff --git a/metadata.rb b/metadata.rb index ad25e90..86f362c 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache-2.0' description "Run laravel's artisan commands" long_description "Run laravel's artisan commands on remote nodes" -version '0.4.0' +version '0.5.0' chef_version '>= 12.1' if respond_to?(:chef_version) supports 'ubuntu', '= 16.04' diff --git a/recipes/migrate_status.rb b/recipes/migrate_status.rb new file mode 100644 index 0000000..b11b386 --- /dev/null +++ b/recipes/migrate_status.rb @@ -0,0 +1,15 @@ +# +# Cookbook:: laravel-artisan +# Recipe:: migrate_status +# +# Copyright:: 2017, The Authors, All Rights Reserved. + +include_recipe 'laravel-artisan::default' + +COMMAND = 'migrate:status' + +execute "php artisan #{COMMAND}" do + cwd node['laravel-artisan']['path'] + command "#{node['laravel-artisan']['call']} #{COMMAND} #{node['laravel-artisan']['verbosity']}" + action :run +end \ No newline at end of file From 89c6b0b280ce5e0ef92017e8afaee710aba45fd2 Mon Sep 17 00:00:00 2001 From: Sebastian Baum Date: Mon, 18 Sep 2017 15:50:09 +0200 Subject: [PATCH 2/6] - preparations for php artisan queue:work (wip) --- recipes/queue_work.rb | 40 +++++++++ templates/supervisor.conf.erb | 148 ++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 recipes/queue_work.rb create mode 100644 templates/supervisor.conf.erb diff --git a/recipes/queue_work.rb b/recipes/queue_work.rb new file mode 100644 index 0000000..dcb768d --- /dev/null +++ b/recipes/queue_work.rb @@ -0,0 +1,40 @@ +# +# Cookbook:: laravel-artisan +# Recipe:: queue:work +# +# Copyright:: 2017, The Authors, All Rights Reserved. + +include_recipe 'laravel-artisan::default' + +## install pip first +package 'python-pip' do + action :install +end + +#bash 'install something' do +# user 'root' +# cwd '/tmp' +# code <<-EOH +# +# EOH +#end + +execute 'install supervisor' do + command 'pip install supervisor' + action :run +end + +COMMAND = 'queue:work' + +#supervisord_program "php artisan #{COMMAND} as a supervisor service" do +# name 'laravel-queue' +# command "#{node['laravel-artisan']['path']} #{node['laravel-artisan']['call']} #{COMMAND} #{node['laravel-artisan']['verbosity']}" +# action [:supervise, :start] +#end + + +#execute "php artisan #{COMMAND}" do +# cwd node['laravel-artisan']['path'] +# command "#{node['laravel-artisan']['call']} #{COMMAND} #{node['laravel-artisan']['verbosity']}" +# action :run +#end \ No newline at end of file diff --git a/templates/supervisor.conf.erb b/templates/supervisor.conf.erb new file mode 100644 index 0000000..6906427 --- /dev/null +++ b/templates/supervisor.conf.erb @@ -0,0 +1,148 @@ +; Sample supervisor config file. +; +; For more information on the config file, please see: +; http://supervisord.org/configuration.html +; +; Notes: +; - Shell expansion ("~" or "$HOME") is not supported. Environment +; variables can be expanded using this syntax: "%(ENV_HOME)s". +; - Quotes around values are not supported, except in the case of +; the environment= options as shown below. +; - Comments must have a leading space: "a=b ;comment" not "a=b;comment". +; - Command will be truncated if it looks like a config file comment, e.g. +; "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ". + +[unix_http_server] +file=/tmp/supervisor.sock ; the path to the socket file +;chmod=0700 ; socket file mode (default 0700) +;chown=nobody:nogroup ; socket file uid:gid owner +;username=user ; default is no username (open server) +;password=123 ; default is no password (open server) + +;[inet_http_server] ; inet (TCP) server disabled by default +;port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface +;username=user ; default is no username (open server) +;password=123 ; default is no password (open server) + +[supervisord] +logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log +logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB +logfile_backups=10 ; # of main logfile backups; 0 means none, default 10 +loglevel=info ; log level; default info; others: debug,warn,trace +pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid +nodaemon=false ; start in foreground if true; default false +minfds=1024 ; min. avail startup file descriptors; default 1024 +minprocs=200 ; min. avail process descriptors;default 200 +;umask=022 ; process file creation umask; default 022 +;user=chrism ; default is current user, required if root +;identifier=supervisor ; supervisord identifier, default is 'supervisor' +;directory=/tmp ; default is not to cd during start +;nocleanup=true ; don't clean up tempfiles at start; default false +;childlogdir=/tmp ; 'AUTO' child log dir, default $TEMP +;environment=KEY="value" ; key value pairs to add to environment +;strip_ansi=false ; strip ansi escape codes in logs; def. false + +; The rpcinterface:supervisor section must remain in the config file for +; RPC (supervisorctl/web interface) to work. Additional interfaces may be +; added by defining them in separate [rpcinterface:x] sections. + +[rpcinterface:supervisor] +supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface + +; The supervisorctl section configures how supervisorctl will connect to +; supervisord. configure it match the settings in either the unix_http_server +; or inet_http_server section. + +[supervisorctl] +serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket +;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket +;username=chris ; should be same as in [*_http_server] if set +;password=123 ; should be same as in [*_http_server] if set +;prompt=mysupervisor ; cmd line prompt (default "supervisor") +;history_file=~/.sc_history ; use readline history if available + +; The sample program section below shows all possible program subsection values. +; Create one or more 'real' program: sections to be able to control them under +; supervisor. + +;[program:theprogramname] +;command=/bin/cat ; the program (relative uses PATH, can take args) +;process_name=%(program_name)s ; process_name expr (default %(program_name)s) +;numprocs=1 ; number of processes copies to start (def 1) +;directory=/tmp ; directory to cwd to before exec (def no cwd) +;umask=022 ; umask for process (default None) +;priority=999 ; the relative start priority (default 999) +;autostart=true ; start at supervisord start (default: true) +;startsecs=1 ; # of secs prog must stay up to be running (def. 1) +;startretries=3 ; max # of serial start failures when starting (default 3) +;autorestart=unexpected ; when to restart if exited after running (def: unexpected) +;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) +;stopsignal=QUIT ; signal used to kill process (default TERM) +;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) +;stopasgroup=false ; send stop signal to the UNIX process group (default false) +;killasgroup=false ; SIGKILL the UNIX process group (def false) +;user=chrism ; setuid to this UNIX account to run the program +;redirect_stderr=true ; redirect proc stderr to stdout (default false) +;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO +;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) +;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) +;stdout_events_enabled=false ; emit events on stdout writes (default false) +;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO +;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) +;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) +;stderr_events_enabled=false ; emit events on stderr writes (default false) +;environment=A="1",B="2" ; process environment additions (def no adds) +;serverurl=AUTO ; override serverurl computation (childutils) + +; The sample eventlistener section below shows all possible eventlistener +; subsection values. Create one or more 'real' eventlistener: sections to be +; able to handle event notifications sent by supervisord. + +;[eventlistener:theeventlistenername] +;command=/bin/eventlistener ; the program (relative uses PATH, can take args) +;process_name=%(program_name)s ; process_name expr (default %(program_name)s) +;numprocs=1 ; number of processes copies to start (def 1) +;events=EVENT ; event notif. types to subscribe to (req'd) +;buffer_size=10 ; event buffer queue size (default 10) +;directory=/tmp ; directory to cwd to before exec (def no cwd) +;umask=022 ; umask for process (default None) +;priority=-1 ; the relative start priority (default -1) +;autostart=true ; start at supervisord start (default: true) +;startsecs=1 ; # of secs prog must stay up to be running (def. 1) +;startretries=3 ; max # of serial start failures when starting (default 3) +;autorestart=unexpected ; autorestart if exited after running (def: unexpected) +;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) +;stopsignal=QUIT ; signal used to kill process (default TERM) +;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) +;stopasgroup=false ; send stop signal to the UNIX process group (default false) +;killasgroup=false ; SIGKILL the UNIX process group (def false) +;user=chrism ; setuid to this UNIX account to run the program +;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners +;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO +;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) +;stdout_events_enabled=false ; emit events on stdout writes (default false) +;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO +;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) +;stderr_events_enabled=false ; emit events on stderr writes (default false) +;environment=A="1",B="2" ; process environment additions +;serverurl=AUTO ; override serverurl computation (childutils) + +; The sample group section below shows all possible group values. Create one +; or more 'real' group: sections to create "heterogeneous" process groups. + +;[group:thegroupname] +;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions +;priority=999 ; the relative start priority (default 999) + +; The [include] section can just contain the "files" setting. This +; setting can list multiple files (separated by whitespace or +; newlines). It can also contain wildcards. The filenames are +; interpreted as relative to this file. Included files *cannot* +; include files themselves. + +;[include] +;files = relative/directory/*.ini From 4294e0961e65ed46d730fde0646dd906b2b66be7 Mon Sep 17 00:00:00 2001 From: Sebastian Baum Date: Tue, 19 Sep 2017 09:28:57 +0200 Subject: [PATCH 3/6] - installing and preparing supervisor --- attributes/supervisor.rb | 2 + recipes/queue_work.rb | 35 +++------------- recipes/supervisor.rb | 37 ++++++++++++++++ templates/program.conf.erb | 79 +++++++++++++++++++++++++++++++++++ templates/supervisor.conf.erb | 4 +- 5 files changed, 126 insertions(+), 31 deletions(-) create mode 100644 attributes/supervisor.rb create mode 100644 recipes/supervisor.rb create mode 100644 templates/program.conf.erb diff --git a/attributes/supervisor.rb b/attributes/supervisor.rb new file mode 100644 index 0000000..3e622d5 --- /dev/null +++ b/attributes/supervisor.rb @@ -0,0 +1,2 @@ +default['laravel-artisan']['supervisor']['main_conf_dir'] = '/var/supervisor' +default['laravel-artisan']['supervisor']['conf_dir'] = "#{node['laravel-artisan']['supervisor']['main_conf_dir']}/conf" \ No newline at end of file diff --git a/recipes/queue_work.rb b/recipes/queue_work.rb index dcb768d..86c0ddf 100644 --- a/recipes/queue_work.rb +++ b/recipes/queue_work.rb @@ -4,37 +4,14 @@ # # Copyright:: 2017, The Authors, All Rights Reserved. -include_recipe 'laravel-artisan::default' +#include_recipe 'laravel-artisan::default' -## install pip first -package 'python-pip' do - action :install -end +### Install and prepare supervisor +include_recipe 'laravel-artisan::supervisor' -#bash 'install something' do -# user 'root' -# cwd '/tmp' -# code <<-EOH -# -# EOH -#end - -execute 'install supervisor' do - command 'pip install supervisor' - action :run -end COMMAND = 'queue:work' -#supervisord_program "php artisan #{COMMAND} as a supervisor service" do -# name 'laravel-queue' -# command "#{node['laravel-artisan']['path']} #{node['laravel-artisan']['call']} #{COMMAND} #{node['laravel-artisan']['verbosity']}" -# action [:supervise, :start] -#end - - -#execute "php artisan #{COMMAND}" do -# cwd node['laravel-artisan']['path'] -# command "#{node['laravel-artisan']['call']} #{COMMAND} #{node['laravel-artisan']['verbosity']}" -# action :run -#end \ No newline at end of file +# TODOs +# - Add a supervisor config for php artisan queue:work +# - Start supervisor diff --git a/recipes/supervisor.rb b/recipes/supervisor.rb new file mode 100644 index 0000000..51a89ae --- /dev/null +++ b/recipes/supervisor.rb @@ -0,0 +1,37 @@ +# Install and prepare supervisor +# +# Cookbook:: laravel-artisan +# Recipe:: supervisor +# +# Copyright:: 2017, The Authors, All Rights Reserved. + +### install pip first +package 'python-pip' do + action :install +end + +### Install supervisor via pip +execute 'install supervisor' do + command 'pip install supervisor' + action :run +end + +### Create directory where all supervisor.conf files are stored. +directory 'create supervisor conf directory' do + path node['laravel-artisan']['supervisor']['conf_dir'] + recursive true + owner 'root' + group 'root' + mode '0755' + action :create +end + +### Create the main config file +template 'create main supervisor config file' do + source 'supervisor.conf.erb' + path "#{node['laravel-artisan']['supervisor']['main_conf_dir']}/supervisor.conf" + owner 'root' + group 'root' + mode '0644' +end + diff --git a/templates/program.conf.erb b/templates/program.conf.erb new file mode 100644 index 0000000..735be46 --- /dev/null +++ b/templates/program.conf.erb @@ -0,0 +1,79 @@ +; Program supervisor config file. +; +; For more information on the config file, please see: +; http://supervisord.org/configuration.html +; + +;[program:theprogramname] +;command=/bin/cat ; the program (relative uses PATH, can take args) +;process_name=%(program_name)s ; process_name expr (default %(program_name)s) +;numprocs=1 ; number of processes copies to start (def 1) +;directory=/tmp ; directory to cwd to before exec (def no cwd) +;umask=022 ; umask for process (default None) +;priority=999 ; the relative start priority (default 999) +;autostart=true ; start at supervisord start (default: true) +;startsecs=1 ; # of secs prog must stay up to be running (def. 1) +;startretries=3 ; max # of serial start failures when starting (default 3) +;autorestart=unexpected ; when to restart if exited after running (def: unexpected) +;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) +;stopsignal=QUIT ; signal used to kill process (default TERM) +;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) +;stopasgroup=false ; send stop signal to the UNIX process group (default false) +;killasgroup=false ; SIGKILL the UNIX process group (def false) +;user=chrism ; setuid to this UNIX account to run the program +;redirect_stderr=true ; redirect proc stderr to stdout (default false) +;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO +;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) +;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) +;stdout_events_enabled=false ; emit events on stdout writes (default false) +;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO +;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) +;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) +;stderr_events_enabled=false ; emit events on stderr writes (default false) +;environment=A="1",B="2" ; process environment additions (def no adds) +;serverurl=AUTO ; override serverurl computation (childutils) + +; The sample eventlistener section below shows all possible eventlistener +; subsection values. Create one or more 'real' eventlistener: sections to be +; able to handle event notifications sent by supervisord. + +;[eventlistener:theeventlistenername] +;command=/bin/eventlistener ; the program (relative uses PATH, can take args) +;process_name=%(program_name)s ; process_name expr (default %(program_name)s) +;numprocs=1 ; number of processes copies to start (def 1) +;events=EVENT ; event notif. types to subscribe to (req'd) +;buffer_size=10 ; event buffer queue size (default 10) +;directory=/tmp ; directory to cwd to before exec (def no cwd) +;umask=022 ; umask for process (default None) +;priority=-1 ; the relative start priority (default -1) +;autostart=true ; start at supervisord start (default: true) +;startsecs=1 ; # of secs prog must stay up to be running (def. 1) +;startretries=3 ; max # of serial start failures when starting (default 3) +;autorestart=unexpected ; autorestart if exited after running (def: unexpected) +;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) +;stopsignal=QUIT ; signal used to kill process (default TERM) +;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) +;stopasgroup=false ; send stop signal to the UNIX process group (default false) +;killasgroup=false ; SIGKILL the UNIX process group (def false) +;user=chrism ; setuid to this UNIX account to run the program +;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners +;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO +;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) +;stdout_events_enabled=false ; emit events on stdout writes (default false) +;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO +;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) +;stderr_events_enabled=false ; emit events on stderr writes (default false) +;environment=A="1",B="2" ; process environment additions +;serverurl=AUTO ; override serverurl computation (childutils) + +; The sample group section below shows all possible group values. Create one +; or more 'real' group: sections to create "heterogeneous" process groups. + +;[group:thegroupname] +;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions +;priority=999 ; the relative start priority (default 999) + diff --git a/templates/supervisor.conf.erb b/templates/supervisor.conf.erb index 6906427..7f229a0 100644 --- a/templates/supervisor.conf.erb +++ b/templates/supervisor.conf.erb @@ -144,5 +144,5 @@ serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket ; interpreted as relative to this file. Included files *cannot* ; include files themselves. -;[include] -;files = relative/directory/*.ini +[include] +files = conf/*.conf From 5023d1b9f69c5b0efe8f478ffb25e3bb301b8ebe Mon Sep 17 00:00:00 2001 From: Sebastian Baum Date: Tue, 19 Sep 2017 11:41:49 +0200 Subject: [PATCH 4/6] - supervising php artisan queue:work is working now --- attributes/queue.rb | 8 +++ attributes/supervisor.rb | 3 +- recipes/queue_work.rb | 26 +++++-- recipes/supervisor.rb | 29 +------- templates/program.conf.erb | 79 -------------------- templates/supervisor.conf.erb | 131 ++++++++-------------------------- 6 files changed, 62 insertions(+), 214 deletions(-) create mode 100644 attributes/queue.rb delete mode 100644 templates/program.conf.erb diff --git a/attributes/queue.rb b/attributes/queue.rb new file mode 100644 index 0000000..ff07892 --- /dev/null +++ b/attributes/queue.rb @@ -0,0 +1,8 @@ +default['laravel-artisan']['queue']['worker_name'] = 'laravel-worker' +default['laravel-artisan']['queue']['command'] = "php #{node['laravel-artisan']['path']}/artisan queue:work" +default['laravel-artisan']['queue']['autostart'] = true +default['laravel-artisan']['queue']['autorestart'] = true +default['laravel-artisan']['queue']['redirect_stderr'] = true +default['laravel-artisan']['queue']['user'] = 'www-data' +default['laravel-artisan']['queue']['stdout_logfile'] = "/var/log/supervisor/#{node['laravel-artisan']['queue']['worker_name']}.log" +default['laravel-artisan']['queue']['numprocs'] = 1 \ No newline at end of file diff --git a/attributes/supervisor.rb b/attributes/supervisor.rb index 3e622d5..c537e25 100644 --- a/attributes/supervisor.rb +++ b/attributes/supervisor.rb @@ -1,2 +1 @@ -default['laravel-artisan']['supervisor']['main_conf_dir'] = '/var/supervisor' -default['laravel-artisan']['supervisor']['conf_dir'] = "#{node['laravel-artisan']['supervisor']['main_conf_dir']}/conf" \ No newline at end of file +default['laravel-artisan']['supervisor']['conf_dir'] = "/etc/supervisor/conf.d" \ No newline at end of file diff --git a/recipes/queue_work.rb b/recipes/queue_work.rb index 86c0ddf..e0572be 100644 --- a/recipes/queue_work.rb +++ b/recipes/queue_work.rb @@ -1,17 +1,31 @@ # # Cookbook:: laravel-artisan -# Recipe:: queue:work +# Recipe:: queue_work # # Copyright:: 2017, The Authors, All Rights Reserved. -#include_recipe 'laravel-artisan::default' +include_recipe 'laravel-artisan::default' ### Install and prepare supervisor include_recipe 'laravel-artisan::supervisor' +template "create supervisor conf for #{node['laravel-artisan']['queue']['worker_name']}" do + source 'supervisor.conf.erb' + path "#{node['laravel-artisan']['supervisor']['conf_dir']}/#{node['laravel-artisan']['queue']['worker_name']}.conf" + owner 'root' + group 'root' + mode '0644' + variables node['laravel-artisan']['queue'] +end -COMMAND = 'queue:work' +service 'stop supervisor' do + service_name 'supervisor' + supports :stop => true, :status => true, :restart => true, :reload => true + action :stop +end -# TODOs -# - Add a supervisor config for php artisan queue:work -# - Start supervisor +service 'start supervisor' do + service_name 'supervisor' + supports :start => true, :status => true, :restart => true, :reload => true + action :start +end diff --git a/recipes/supervisor.rb b/recipes/supervisor.rb index 51a89ae..80ce2ee 100644 --- a/recipes/supervisor.rb +++ b/recipes/supervisor.rb @@ -5,33 +5,8 @@ # # Copyright:: 2017, The Authors, All Rights Reserved. -### install pip first -package 'python-pip' do +### Install supervisor from package repository +package 'supervisor' do action :install end -### Install supervisor via pip -execute 'install supervisor' do - command 'pip install supervisor' - action :run -end - -### Create directory where all supervisor.conf files are stored. -directory 'create supervisor conf directory' do - path node['laravel-artisan']['supervisor']['conf_dir'] - recursive true - owner 'root' - group 'root' - mode '0755' - action :create -end - -### Create the main config file -template 'create main supervisor config file' do - source 'supervisor.conf.erb' - path "#{node['laravel-artisan']['supervisor']['main_conf_dir']}/supervisor.conf" - owner 'root' - group 'root' - mode '0644' -end - diff --git a/templates/program.conf.erb b/templates/program.conf.erb deleted file mode 100644 index 735be46..0000000 --- a/templates/program.conf.erb +++ /dev/null @@ -1,79 +0,0 @@ -; Program supervisor config file. -; -; For more information on the config file, please see: -; http://supervisord.org/configuration.html -; - -;[program:theprogramname] -;command=/bin/cat ; the program (relative uses PATH, can take args) -;process_name=%(program_name)s ; process_name expr (default %(program_name)s) -;numprocs=1 ; number of processes copies to start (def 1) -;directory=/tmp ; directory to cwd to before exec (def no cwd) -;umask=022 ; umask for process (default None) -;priority=999 ; the relative start priority (default 999) -;autostart=true ; start at supervisord start (default: true) -;startsecs=1 ; # of secs prog must stay up to be running (def. 1) -;startretries=3 ; max # of serial start failures when starting (default 3) -;autorestart=unexpected ; when to restart if exited after running (def: unexpected) -;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) -;stopsignal=QUIT ; signal used to kill process (default TERM) -;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) -;stopasgroup=false ; send stop signal to the UNIX process group (default false) -;killasgroup=false ; SIGKILL the UNIX process group (def false) -;user=chrism ; setuid to this UNIX account to run the program -;redirect_stderr=true ; redirect proc stderr to stdout (default false) -;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO -;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) -;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) -;stdout_events_enabled=false ; emit events on stdout writes (default false) -;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO -;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) -;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) -;stderr_events_enabled=false ; emit events on stderr writes (default false) -;environment=A="1",B="2" ; process environment additions (def no adds) -;serverurl=AUTO ; override serverurl computation (childutils) - -; The sample eventlistener section below shows all possible eventlistener -; subsection values. Create one or more 'real' eventlistener: sections to be -; able to handle event notifications sent by supervisord. - -;[eventlistener:theeventlistenername] -;command=/bin/eventlistener ; the program (relative uses PATH, can take args) -;process_name=%(program_name)s ; process_name expr (default %(program_name)s) -;numprocs=1 ; number of processes copies to start (def 1) -;events=EVENT ; event notif. types to subscribe to (req'd) -;buffer_size=10 ; event buffer queue size (default 10) -;directory=/tmp ; directory to cwd to before exec (def no cwd) -;umask=022 ; umask for process (default None) -;priority=-1 ; the relative start priority (default -1) -;autostart=true ; start at supervisord start (default: true) -;startsecs=1 ; # of secs prog must stay up to be running (def. 1) -;startretries=3 ; max # of serial start failures when starting (default 3) -;autorestart=unexpected ; autorestart if exited after running (def: unexpected) -;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) -;stopsignal=QUIT ; signal used to kill process (default TERM) -;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) -;stopasgroup=false ; send stop signal to the UNIX process group (default false) -;killasgroup=false ; SIGKILL the UNIX process group (def false) -;user=chrism ; setuid to this UNIX account to run the program -;redirect_stderr=false ; redirect_stderr=true is not allowed for eventlisteners -;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO -;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) -;stdout_events_enabled=false ; emit events on stdout writes (default false) -;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO -;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) -;stderr_events_enabled=false ; emit events on stderr writes (default false) -;environment=A="1",B="2" ; process environment additions -;serverurl=AUTO ; override serverurl computation (childutils) - -; The sample group section below shows all possible group values. Create one -; or more 'real' group: sections to create "heterogeneous" process groups. - -;[group:thegroupname] -;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions -;priority=999 ; the relative start priority (default 999) - diff --git a/templates/supervisor.conf.erb b/templates/supervisor.conf.erb index 7f229a0..83b016a 100644 --- a/templates/supervisor.conf.erb +++ b/templates/supervisor.conf.erb @@ -1,100 +1,39 @@ -; Sample supervisor config file. +; Program supervisor config file. ; ; For more information on the config file, please see: ; http://supervisord.org/configuration.html ; -; Notes: -; - Shell expansion ("~" or "$HOME") is not supported. Environment -; variables can be expanded using this syntax: "%(ENV_HOME)s". -; - Quotes around values are not supported, except in the case of -; the environment= options as shown below. -; - Comments must have a leading space: "a=b ;comment" not "a=b;comment". -; - Command will be truncated if it looks like a config file comment, e.g. -; "command=bash -c 'foo ; bar'" will truncate to "command=bash -c 'foo ". -[unix_http_server] -file=/tmp/supervisor.sock ; the path to the socket file -;chmod=0700 ; socket file mode (default 0700) -;chown=nobody:nogroup ; socket file uid:gid owner -;username=user ; default is no username (open server) -;password=123 ; default is no password (open server) - -;[inet_http_server] ; inet (TCP) server disabled by default -;port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface -;username=user ; default is no username (open server) -;password=123 ; default is no password (open server) - -[supervisord] -logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log -logfile_maxbytes=50MB ; max main logfile bytes b4 rotation; default 50MB -logfile_backups=10 ; # of main logfile backups; 0 means none, default 10 -loglevel=info ; log level; default info; others: debug,warn,trace -pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid -nodaemon=false ; start in foreground if true; default false -minfds=1024 ; min. avail startup file descriptors; default 1024 -minprocs=200 ; min. avail process descriptors;default 200 -;umask=022 ; process file creation umask; default 022 -;user=chrism ; default is current user, required if root -;identifier=supervisor ; supervisord identifier, default is 'supervisor' -;directory=/tmp ; default is not to cd during start -;nocleanup=true ; don't clean up tempfiles at start; default false -;childlogdir=/tmp ; 'AUTO' child log dir, default $TEMP -;environment=KEY="value" ; key value pairs to add to environment -;strip_ansi=false ; strip ansi escape codes in logs; def. false - -; The rpcinterface:supervisor section must remain in the config file for -; RPC (supervisorctl/web interface) to work. Additional interfaces may be -; added by defining them in separate [rpcinterface:x] sections. - -[rpcinterface:supervisor] -supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface - -; The supervisorctl section configures how supervisorctl will connect to -; supervisord. configure it match the settings in either the unix_http_server -; or inet_http_server section. - -[supervisorctl] -serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket -;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket -;username=chris ; should be same as in [*_http_server] if set -;password=123 ; should be same as in [*_http_server] if set -;prompt=mysupervisor ; cmd line prompt (default "supervisor") -;history_file=~/.sc_history ; use readline history if available - -; The sample program section below shows all possible program subsection values. -; Create one or more 'real' program: sections to be able to control them under -; supervisor. - -;[program:theprogramname] -;command=/bin/cat ; the program (relative uses PATH, can take args) -;process_name=%(program_name)s ; process_name expr (default %(program_name)s) -;numprocs=1 ; number of processes copies to start (def 1) -;directory=/tmp ; directory to cwd to before exec (def no cwd) -;umask=022 ; umask for process (default None) -;priority=999 ; the relative start priority (default 999) -;autostart=true ; start at supervisord start (default: true) -;startsecs=1 ; # of secs prog must stay up to be running (def. 1) -;startretries=3 ; max # of serial start failures when starting (default 3) -;autorestart=unexpected ; when to restart if exited after running (def: unexpected) -;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) -;stopsignal=QUIT ; signal used to kill process (default TERM) -;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) -;stopasgroup=false ; send stop signal to the UNIX process group (default false) -;killasgroup=false ; SIGKILL the UNIX process group (def false) -;user=chrism ; setuid to this UNIX account to run the program -;redirect_stderr=true ; redirect proc stderr to stdout (default false) -;stdout_logfile=/a/path ; stdout log path, NONE for none; default AUTO -;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) -;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) -;stdout_events_enabled=false ; emit events on stdout writes (default false) -;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO -;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) -;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) -;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) -;stderr_events_enabled=false ; emit events on stderr writes (default false) -;environment=A="1",B="2" ; process environment additions (def no adds) -;serverurl=AUTO ; override serverurl computation (childutils) +[program:<%= @worker_name %>] +command=<%= @command %> ; the program (relative uses PATH, can take args) +process_name=%(program_name)s_%(process_num)02d ; process_name expr (default %(program_name)s) +numprocs=<%= @numprocs %> ; number of processes copies to start (def 1) +;directory=/tmp ; directory to cwd to before exec (def no cwd) +;umask=022 ; umask for process (default None) +;priority=999 ; the relative start priority (default 999) +autostart=<%= @autostart %> ; start at supervisord start (default: true) +;startsecs=1 ; # of secs prog must stay up to be running (def. 1) +;startretries=3 ; max # of serial start failures when starting (default 3) +autorestart=<%= @autorestart %> ; when to restart if exited after running (def: unexpected) +;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) +;stopsignal=QUIT ; signal used to kill process (default TERM) +;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) +;stopasgroup=false ; send stop signal to the UNIX process group (default false) +;killasgroup=false ; SIGKILL the UNIX process group (def false) +user=<%= @user %> ; setuid to this UNIX account to run the program +redirect_stderr=<%= @redirect_stderr %> ; redirect proc stderr to stdout (default false) +stdout_logfile=<%= @stdout_logfile %> ; stdout log path, NONE for none; default AUTO +;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) +;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) +;stdout_events_enabled=false ; emit events on stdout writes (default false) +;stderr_logfile=/a/path ; stderr log path, NONE for none; default AUTO +;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) +;stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) +;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) +;stderr_events_enabled=false ; emit events on stderr writes (default false) +;environment=A="1",B="2" ; process environment additions (def no adds) +;serverurl=AUTO ; override serverurl computation (childutils) ; The sample eventlistener section below shows all possible eventlistener ; subsection values. Create one or more 'real' eventlistener: sections to be @@ -138,11 +77,3 @@ serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket ;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions ;priority=999 ; the relative start priority (default 999) -; The [include] section can just contain the "files" setting. This -; setting can list multiple files (separated by whitespace or -; newlines). It can also contain wildcards. The filenames are -; interpreted as relative to this file. Included files *cannot* -; include files themselves. - -[include] -files = conf/*.conf From dd717ffcf59be44bc752bb62119da56fa0866970 Mon Sep 17 00:00:00 2001 From: Sebastian Baum Date: Tue, 19 Sep 2017 12:50:10 +0200 Subject: [PATCH 5/6] - added script to stop running artisan queue:work; little formatting and docu --- recipes/default.rb | 11 +++-------- recipes/queue_stop.rb | 24 ++++++++++++++++++++++++ recipes/queue_work.rb | 8 ++++++++ recipes/schedule_remove.rb | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 recipes/queue_stop.rb diff --git a/recipes/default.rb b/recipes/default.rb index ef0f165..4c1da33 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -8,22 +8,17 @@ # and check that the path to the executable is set properly. -## Check if the path to the artisan file is given +### Check if the path to the artisan file is given if node['laravel-artisan']['path'].empty? raise(Exception, 'Missing path to artisan file!'); end -# Check if the artisan file exists at the given location +### Check if the artisan file exists at the given location unless File.exists?("#{node['laravel-artisan']['path']}/artisan") raise(Exception, "No artisan file at the given locatation: #{node['laravel-artisan']['path']}") end +### Log that all checks have passed log 'checking laravel artisan prerequisits' do message 'Laravel artsan prerequisits check [SUCCESS]' end - -#execute 'php artisan help' do -# cwd node['laravel-artisan']['path'] -# command "#{node['laravel-artisan']['call']} help #{node['laravel-artisan']['verbosity']}" -# action :run -#end diff --git a/recipes/queue_stop.rb b/recipes/queue_stop.rb new file mode 100644 index 0000000..3845916 --- /dev/null +++ b/recipes/queue_stop.rb @@ -0,0 +1,24 @@ +# +# Cookbook:: laravel-artisan +# Recipe:: queue_stop +# +# Copyright:: 2017, The Authors, All Rights Reserved. + +### Remove the supervisor configuration for queue:work +file "remove supervisor conf for #{node['laravel-artisan']['queue']['worker_name']}" do + path "#{node['laravel-artisan']['supervisor']['conf_dir']}/#{node['laravel-artisan']['queue']['worker_name']}.conf" + action :delete +end + +### Stop supervisor +service 'stop supervisor' do + service_name 'supervisor' + action :stop +end + +### Start supervisor +service 'start supervisor' do + service_name 'supervisor' + action :start +end + diff --git a/recipes/queue_work.rb b/recipes/queue_work.rb index e0572be..d31f8aa 100644 --- a/recipes/queue_work.rb +++ b/recipes/queue_work.rb @@ -1,3 +1,9 @@ +# Start a laravel queue worker process. +# +# In order to run it as a service supervisor is installed and configured. +# For more details see: +# - https://laravel.com/docs/5.5/queues#supervisor-configuration +# # # Cookbook:: laravel-artisan # Recipe:: queue_work @@ -18,12 +24,14 @@ variables node['laravel-artisan']['queue'] end +### Stop the supervisor service service 'stop supervisor' do service_name 'supervisor' supports :stop => true, :status => true, :restart => true, :reload => true action :stop end +### Start the supervisor service service 'start supervisor' do service_name 'supervisor' supports :start => true, :status => true, :restart => true, :reload => true diff --git a/recipes/schedule_remove.rb b/recipes/schedule_remove.rb index 7bcfd41..a5bdc31 100644 --- a/recipes/schedule_remove.rb +++ b/recipes/schedule_remove.rb @@ -4,7 +4,7 @@ # # Copyright:: 2017, The Authors, All Rights Reserved. - +### Remove the crontab entry for the scheduler cron "laravel-scheduler" do action :delete end \ No newline at end of file From f916e08da37ec65fb6b31bf38b35ffa367586d81 Mon Sep 17 00:00:00 2001 From: Sebastian Baum Date: Tue, 19 Sep 2017 12:56:11 +0200 Subject: [PATCH 6/6] - finished first implementation of php artisan queue:work --- README.md | 3 +++ recipes/queue_stop.rb | 1 + 2 files changed, 4 insertions(+) diff --git a/README.md b/README.md index a792e77..89dcc52 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,7 @@ Commands that are particular useful for development are not supported. * config:clear * migrate:status * package:discover +* queue:work * schedule:run * view:clear @@ -86,6 +87,8 @@ Using AWS Opsworks you can pass in the path via custom json: * `laravel-artisan::config_clear` - Remove the configuaration cache file. * `laravel-artisan::migrate_status` - Show the status of each migration. * `laravel-artisan::package_discover` - Rebuild the cached package manifest. +* `laravel-artisan::queue_work` - Start processing jobs on the queue as a daemon. +* `laravel-artisan::queue_stop` - Stop processing jobs on the queue as a daemon. * `laravel-artisan::schedule_run` - Run the scheduled commands. * `laravel-artisan::schedule_remove` - Remove the cronjob that runs `php artisan schedule:run` * `laravel-artisan::view_clear` - Clear all compiled view files. \ No newline at end of file diff --git a/recipes/queue_stop.rb b/recipes/queue_stop.rb index 3845916..3b7324e 100644 --- a/recipes/queue_stop.rb +++ b/recipes/queue_stop.rb @@ -1,3 +1,4 @@ +# Stop the artisan queue:work process. # # Cookbook:: laravel-artisan # Recipe:: queue_stop