mirror of
https://github.com/rapid7/metasploitable3.git
synced 2024-07-02 17:55:46 +02:00
Tweaks to the recipes to avoid repetition of work, and ub1404 dev, * let apt cookbook handle apt-update globally * do not download, configure, make, make install if the package is already installed * add guards for file deletion to first check whether file is present * use docker cookbook for image building and running, to only build if not alrady built and only run if not already running * drop mysql table and recreate each time Also, * bump Docker cookbook to 4.9.3 * bump mysql cookbook to 8.5.1 * add apt cookbook for better apt-update management * bump depends versions and add apt * modify readme with customization instructions * modify all chef runlists to call apt first in the runlist * add a vagrantfile for dev of ub1404
106 lines
2.8 KiB
Ruby
106 lines
2.8 KiB
Ruby
module MysqlCookbook
|
|
require_relative 'mysql_service_base'
|
|
class MysqlService < MysqlServiceBase
|
|
resource_name :mysql_service
|
|
|
|
# installation type and service_manager
|
|
property :install_method, %w(package auto), default: 'auto', desired_state: false
|
|
property :service_manager, %w(sysvinit upstart systemd auto), default: 'auto', desired_state: false
|
|
|
|
# mysql_server_installation
|
|
property :version, String, default: lazy { default_major_version }, desired_state: false
|
|
property :major_version, String, default: lazy { major_from_full(version) }, desired_state: false
|
|
property :package_name, String, default: lazy { default_package_name }, desired_state: false
|
|
property :package_options, [String, nil], desired_state: false
|
|
property :package_version, [String, nil], default: nil, desired_state: false
|
|
|
|
################
|
|
# Helper Methods
|
|
################
|
|
|
|
def copy_properties_to(to, *properties)
|
|
properties = self.class.properties.keys if properties.empty?
|
|
properties.each do |p|
|
|
# If the property is set on from, and exists on to, set the
|
|
# property on to
|
|
if to.class.properties.include?(p) && property_is_set?(p)
|
|
to.send(p, send(p))
|
|
end
|
|
end
|
|
end
|
|
|
|
action_class do
|
|
def installation(&block)
|
|
case new_resource.install_method
|
|
when 'auto'
|
|
install = mysql_server_installation(new_resource.name, &block)
|
|
when 'package'
|
|
install = mysql_server_installation_package(new_resource.name, &block)
|
|
when 'none'
|
|
Chef::Log.info('Skipping MySQL installation. Assuming it was handled previously.')
|
|
return
|
|
end
|
|
copy_properties_to(install)
|
|
install
|
|
end
|
|
|
|
def svc_manager(&block)
|
|
case new_resource.service_manager
|
|
when 'auto'
|
|
svc = mysql_service_manager(new_resource.name, &block)
|
|
when 'sysvinit'
|
|
svc = mysql_service_manager_sysvinit(new_resource.name, &block)
|
|
when 'upstart'
|
|
svc = mysql_service_manager_upstart(new_resource.name, &block)
|
|
when 'systemd'
|
|
svc = mysql_service_manager_systemd(new_resource.name, &block)
|
|
end
|
|
copy_properties_to(svc)
|
|
svc
|
|
end
|
|
end
|
|
|
|
#########
|
|
# Actions
|
|
#########
|
|
|
|
action :create do
|
|
installation do
|
|
action :install
|
|
end
|
|
|
|
svc_manager do
|
|
action :create
|
|
end
|
|
end
|
|
|
|
action :start do
|
|
svc_manager do
|
|
action :start
|
|
end
|
|
end
|
|
|
|
action :delete do
|
|
svc_manager do
|
|
action :delete
|
|
end
|
|
|
|
installation do
|
|
action :delete
|
|
end
|
|
end
|
|
|
|
action :restart do
|
|
svc_manager do
|
|
action :restart
|
|
end
|
|
end
|
|
|
|
action :stop do
|
|
svc_manager do
|
|
action :stop
|
|
end
|
|
end
|
|
end
|
|
end
|