Created
February 10, 2019 13:15
-
-
Save pmeinhardt/0a9a72c2f9a07f51304bdb2ed581e52e to your computer and use it in GitHub Desktop.
Capistrano Cachetool plugin (http://gordalina.github.io/cachetool/)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :cachetool do | |
CACHETOOL = 'cachetool.phar'.freeze | |
desc <<~DESC | |
Installs #{CACHETOOL} to the shared directory. | |
This is best used after deploy:starting: | |
namespace :deploy do | |
after :starting, 'cachetool:install_executable' | |
end | |
In order to use the .phar file, the cachetool command needs to be mapped: | |
stages.each do |stage| | |
after stage, :map_commands do | |
SSHKit.config.command_map[:cachetool] = "php \#{shared_path.join('#{CACHETOOL}')}" | |
end | |
end | |
DESC | |
task :install_executable do | |
on roles(fetch(:cachetool_roles)) do | |
within shared_path do | |
if test '[', '!', '-e', CACHETOOL, ']' | |
execute :curl, '-s', '-O', fetch(:cachetool_download_url) | |
execute :chmod, '+x', 'cachetool.phar' | |
end | |
end | |
end | |
end | |
task :run, %i[command] do |t, args| | |
on roles(fetch(:cachetool_roles)) do | |
within fetch(:cachetool_working_dir) do | |
flags = fetch(:cachetool_flags) + args.extras | |
execute :cachetool, args.command, *flags | |
end | |
end | |
end | |
COMMANDS = [ | |
['help', 'Displays help for a command'], | |
['list', 'Lists commands'], | |
['self-update', '[selfupdate] Updates cachetool.phar to the latest version'], | |
['apc:bin:dump', 'Get a binary dump of files and user variables'], | |
['apc:bin:load', 'Load a binary dump into the APC file and user variables'], | |
['apc:cache:clear', 'Clears APC cache (user, system or all)'], | |
['apc:cache:info', 'Shows APC user & system cache information'], | |
['apc:cache:info:file', 'Shows APC file cache information'], | |
['apc:key:delete', 'Deletes an APC key'], | |
['apc:key:exists', 'Checks if an APC key exists'], | |
['apc:key:fetch', 'Shows the content of an APC key'], | |
['apc:key:store', 'Store an APC key with given value'], | |
['apc:regexp:delete', 'Deletes all APC key matching a regexp'], | |
['apc:sma:info', 'Show APC shared memory allocation information'], | |
['apcu:cache:clear', 'Clears APCu cache'], | |
['apcu:cache:info', 'Shows APCu user & system cache information'], | |
['apcu:cache:info:keys', 'Shows APCu keys cache information'], | |
['apcu:key:delete', 'Deletes an APCu key'], | |
['apcu:key:exists', 'Checks if an APCu key exists'], | |
['apcu:key:fetch', 'Shows the content of an APCu key'], | |
['apcu:key:store', 'Store an APCu key with given value'], | |
['apcu:regexp:delete', 'Deletes all APCu key matching a regexp'], | |
['apcu:sma:info', 'Show APCu shared memory allocation information'], | |
['opcache:configuration', 'Get configuration information about the cache'], | |
['opcache:invalidate:scripts', 'Remove scripts from the opcode cache'], | |
['opcache:reset', 'Resets the contents of the opcode cache'], | |
['opcache:status', 'Show summary information about the opcode cache'], | |
['opcache:status:scripts', 'Show scripts in the opcode cache'], | |
['stat:clear', 'Clears the file status cache, including the realpath cache'], | |
['stat:realpath_get', 'Show summary information of realpath cache entries'], | |
['stat:realpath_size', 'Display size of realpath cache'], | |
].freeze | |
COMMANDS.each do |(name, description)| | |
desc description | |
task name do |t, args| | |
invoke! 'cachetool:run', name, *args.extras | |
end | |
end | |
end | |
namespace :load do | |
task :defaults do | |
set :cachetool_roles, :all | |
set :cachetool_flags, [] | |
set :cachetool_working_dir, -> { release_path } | |
set :cachetool_download_url, 'http://gordalina.github.io/cachetool/downloads/cachetool.phar' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment