I have a case where I'm trying to create a systemd_unit in Chef to create a service. Once the service has been created (assuming its not up-to-date), I want to start it, and then only if the service was just created I want to call a bash script to perform some initialization on it.
I started out with this:
systemd_unit 'mysvc.service' do
content({
.
.
.
})
action [ :create ]
notifies :run, 'bash[mysvc.init]', :delayed
end
bash 'mysvc.init' do
code <<-CODE
.
.
.
CODE
action :nothing
end
systemd_unit 'mysvc.service' do
action [ :enable, :start ]
end
My expectation here is that if the :create ran on the systemd_unit, the my bash script would execute. Since the bash script is marked as :nothing, it would not run any other time.
Unfortunately, that's not quite the behavior I get. What actually happens is if either the :create or the [ :enable, :start] blocks of the systemd_unit get executed, then my bash script runs. This won't work becuase if I've already initialized the data in my service, attempting to reinitialize will fail.
How can I get my bash script to run only when the service is newly created?