My application needs a cron job. However, the operating system user that runs the application has other cron jobs it also needs to run that don’t belong to my application. I want to script the release, so that all changes are executed automatically.
I create a directory
cron.d/ which contains one file per application. When my application is released
cron.d/application.cron is replaced with a new version.
After copying out my application cron file, I create a merged crontab:
cat cron.d/*.cron => full-crontab, and install it
The underlying principle is to keep the configuration for separate applications as separate as possible, and only merge them together as late as possible.
- Split your configuration into one fragment per independently released application (+ “the rest”)
- When releasing an application, replace this application’s fragment with a new copy included in the installation package
- Merge the fragments together. For sequential files like crontab files, this may be as simple as concatenating them. For XML files, it’s may a bit harder. But even then, it may be enough to do
cat opening-tag.txt *.part closing-tag.txt.
- Install the merged configuration
- Apache httpd/conf.d files are automatically merged, essentially implementing this approach unnecessary