Commit c153aab5 authored by Chris Roberts's avatar Chris Roberts

Initial commit

parents
# v0.1.0
* Initial commit
# Dpkg Autostart
`dpkg` likes to start services after installation as the Debian convention
dictates. This can be annoying and problematic, especially when you don't
want services to be immediately started before custom configuration can
be applied. Instead of disabling all services from auto starting on installation
as the `dpkg_deb_unautostart` cookbook does, lets allow specifc services
to be targeted.
## Usage
### LWRP
Include the cookbook as a dependency in your metadata:
```ruby
depends 'dpkg_autostart'
```
Then, within your recipe, disable the service with the LWRP:
```ruby
dpkg_autostart 'mysql-server' do
allow false
end
```
That's it. When `dpkg` attempts to start the service after install (generally
via `apt`) it will be instructed not to. This allows the proper configuration
files to be generated, and the service to be started after everything is
ready.
### Attribute
You can also provide a list of services to disable via node attribute. Add
the default recipe to the run list:
```ruby
run_list 'recipe[dpkg_autostart]'
```
and set the services you want to restrict from auto starting:
```ruby
node[:dpkg_autostart][:disabled_services] = ['mysql-server', 'apache2']
```
# Info
* Repository: https://github.com/hw-cookbooks/dpkg_autostart
* IRC: Freenode @ #heavywater
## Related
* deb_pkg_unautostart: http://ckbk.it/deb_pkg_unautostart
\ No newline at end of file
default[:dpkg_autostart][:disable_actions] = %w(start restart)
default[:dpkg_autostart][:disabled_services] = []
name 'dpkg_autostart'
version '0.1.0'
maintainer 'Chris Roberts'
maintainer_email 'chrisroberts.code@gmail.com'
description 'Control service actions initialized from dpkg'
license 'Apache 2.0'
# Dummy call to initialize resource
dpkg_autostart 'attribute_loader' do
allow true
end
actions :set
default_action :set
def allow(val)
node.run_state[:dpkg_autostart_disabled] ||= []
node.run_state[:dpkg_autostart_disabled].push(name) unless val
begin
node.run_context.resource_collection.lookup('template[dpkg_autostart_file]')
rescue Chef::Exceptions::ResourceNotFound
template = Chef::Resource::Template.new('dpkg_autostart_file', node.run_context)
template.cookbook 'dpkg_autostart'
template.source 'policy-rc.d.erb'
template.path '/usr/sbin/policy-rc.d'
template.mode 0755
# Force this to the front of the line
node.run_context.resource_collection.all_resources.unshift(template)
end
end
#!/bin/bash
DISABLE_ACTIONS=( <%= node[:dpkg_autostart][:disable_actions].join(' ') %> )
DISABLED_SERVICES=( <%=
(
Array(node[:dpkg_autostart][:disabled_services]) +
Array(node.run_state[:dpkg_autostart_disabled])
).uniq.join(' ')
%> )
longoptions='quiet,force,try-anyway,disclose-deny,query,no-fallback,help'
getopt=$(getopt -o '' --longoptions $longoptions -- "$@")
if [ $? != 0 ]; then
echo "ERROR!"
exit 1;
fi
eval set -- "$getopt"
while true; do
case "$1" in
--quiet)
QUIET=1
shift
;;
--force)
FORCE=1
shift
;;
--try-anyway)
TRY_ANYWAY=1
shift
;;
--disclose-deny)
DISCLOSE_DENY=1
shift
;;
--query)
QUERY=1
shift
;;
--no-fallback)
NO_FALLBACK=1
shift
;;
--)
shift
break
;;
*)
echo "There should probably be some help text here!"
exit 1
;;
esac
done
SRV_NAME=$1
shift
SRV_ACTION=$1
SRV_ARGS=$*
SRV_DISABLED=0
ACT_DISABLED=0
if [ ! -f "/etc/init.d/${SRV_NAME}" ]; then
exit 100
fi
for i in "${DISABLED_SERVICES}"
do
if [ $i = $SRV_NAME ]; then
SRV_DISABLED=1
fi
done
for i in "${DISABLE_ACTIONS}"
do
if [ $i = $SRV_ACTION ]; then
ACT_DISABLED=1
fi
done
if [ $SRV_DISABLED -eq 1 -a $ACT_DISABLED -eq 1 ]; then
exit 101
else
exit 104
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment