A puppet novice, I'm currently working on a deployment script that will start a couple of foreverjs services from rc.local
at boot time.
My concern is that, in Ubuntu, rc.local
comes with an exit 0
at the bottom of the file.
I don't see a way of using stdlib's file_line
directive to ensure that my lines appear above the exit command (or anywhere else in particular, should the need arise).
I can do it with an exec
block and some ugly sed, but there must be a more standard, elegant way in puppet?
You can use the PuppetLabs Concat module to dynamically insert parts into the
rc.local
file, like so:Define the file as a concat file, and add a header (hash-bang, "managed by Puppet" comment, etc) - note the below may not work, I'm unsure of Puppet's newline handling off the top of my head!
Add your custom parts, making sure to specify the correct
target
and anorder
value that is higher than your header:Add the
exit 0
footer:Et fin!
You can use
concat::fragment
across multiple subclasses (and also multiple modules, though this really isn't recommended!) as long as you set the correcttarget
value and you have that file declared as aconcat
resource. Theorder
parameter allows you to position elements within the file.Check the module's usage readme for more.
If you have the cron service installed you can use it for this purpose by using the @reboot time specification. What makes this easier to manage with puppet is that you can just create a separate file in /etc/cron.d instead of trying to edit a single monolithic file.
I tested that the following works: