miah/chef-redis — pull request #7 by tdg5 (2012-12-18 11:41:27+00:00)
Title: Create init script during precompile to fix first run

There is currently an issue where the first run of the server_source recipe will always fail because the initial update to the redis config tries to immediately restart a service that doesn't exist yet. A subsequent run will succeed because the config file is not changed which allows the recipe to create the service.

There are currently two pull requests that include commits that claim to solve this first run issue by differing config creation until after the init script and service have been created, however I found that this strategy doesn't work either. Worse, this strategy will always fail because the service needs the config to start, but the config won't ever be created because the recipe always fails when trying to start the service.

There's a sort of chicken and egg scenario in that the service needs the config file to start, and the config wants to restart the service immediately, which means the init/service must already exist. The service must come before the config and the config must come before the service.

The simplest way to fix the first run issue is to make it so the config file doesn't cause an immediate restart if it's not a requirement.

Alternatively, immediate restarts can be maintained by changing it so that the init script is created during precompile that way it's already there for the config file to use. This is the strategy employed by this pull request.

Initially, I tried switching template-notifies-service to service-subscribes-to-template, but this had the same problem. I also tried deferring starting the service until the end of the recipe, however the template will try to restart the service immediately which fails since it doesn't yet exist. I preferred to avoid conditioning the service restart as it felt hacky.

This is the simplest solution I've found that still allows the service to be immediately restarted on a config change. This change has been tested with v2.6 on Ubuntu Server 12.04 AMD64.