Reputation: 506
I have a problem trying to run shell script via Chef (with docker-provisioning).
This is how I try to execute my script:
bash 'shell_try' do
user "root"
run = "#{some_path_to_script}/my_script.sh some_params"
code " #{run} > stdout.txt 2> stderr.txt"
end
(note that this script should run another scripts, processes and write logs)
Here's no errors in the output, but when I log into machine and run ps aux
process isn't running.
I guess something wrong with permissions (or env variables), because when I try the same command manually - it works.
Upvotes: 1
Views: 1012
Reputation: 506
Finally find a solution (thanks to @coderanger) -
Install supervisor:
Add my service to supervisor:
supervisor_service "name" do action :enable #action :start command '/path/script.sh start'
end
Run supervisor service
All done!
Upvotes: 1
Reputation: 2265
Please see the Chef documentation for your resource: https://docs.chef.io/resource_bash.html. The bash
resource does not support a run
attribute. Text of the code
attribute is run as a bash script. The default action is to run
the script unless told otherwise by the resource.
bash 'shell_try' do
user "root"
code " #{run} > stdout.txt 2> stderr.txt"
action :run
end
The code
attribute is written to a temporary file where it is then run using the attributes specified in the resource.
The line run = "#{some_path_to_script}/my_script.sh some_params"
at this point does nothing.
Upvotes: 0
Reputation: 54267
A bash
resource just runs the provided script text directly, if you wanted to run a long-running process generally you would set up an Upstart or systemd service and use the service
resource to start it.
Upvotes: 1