How to get the final command to be executed by sshkit - rake

I want to create a gem that has de ability to take a task and wrap all commands in another command.
For example, the capistrano3-unicorn gem unicorn:start task will execute on the server something like bundle exec unicorn -c unicorn.rb -E production, but the execute method is wrapped by a within method, so the command to be executed on the server will be something like cd /home/deploy/application/myapp/current && bundle exec unicorn -c unicorn.rb -E production
I want to be able to create a rake task that takes that unicorn:start task and wrap it inside another task.
For example if I want to create an upstart config file for the app, I could adds this command to a upstart.conf template and the run service my-unicorn-app start
That would be a use case I'm trying to pursue.
In SSHKit formatters the write command is called with a command arg that have what I'm looking for. But I need this at capistrano task level.
Thanks

I think what you're asking is how to access the exact command that is sent via SSH. What you're looking for is the #command method, on the return value of which you can call #to_command. Since #command is a private method, we need to use #send.
namespace :unicorn
task :set_restart_command do
on(roles(:web)) do
within release_path do
set(:unicorn_start_command,
send(:command, :unicorn, "-c unicorn.rb -E production").to_command)
end
end
end
end
Now, in another task, you can use fetch(:unicorn_start_command)

Related

Run a specific talend component using the shell executable

My question is similar to this: Execute only one talend component. Except instead of using the Talend Open Studio, I want to be able to run a specific component from the shell executable I get from building the job.
I have set up my job in a way that if a component is succeeded, the OnComponentOk trigger is used to run the next component. To run the job I run sudo bash NAME_OF_THE_JOB.sh. Is it possible to run only one component, perhaps by passing arguments to the bash shell file?
A Talend job is a single java program. Components are translated to java functions. There are no arguments that allow you to execute a single component.
What you could do is write your job in such a way to execute a component whose name is passed via a context variable but it's not pretty.
You can test the component name passed via a variable named componentName using Run If triggers:
tRunJob_1
/
if("tRunJob_1".equals(context.componentName)
/
/
Start ---if("tJava_2".equals(context.componentName))-- tJava_2
\
\
if("tRest_1".equals(context.componentName))
\
tRest_1
As you can see, this can get very cumbersome, and requires you to know the component's name in order to run it.
You can then launch your job by passing the component name as argument :
sudo bash NAME_OF_THE_JOB.sh --context_param componentName=tJava_2

How to use debugger on perl script executed by "exec"

I trying to figure out how a Perl script which is doing test status reporting, is working. The script executes another piece of perl script via exec. I am able single step through code in first script but when it hits exec, the script executed by exec runs till completion. Is there a way by which I will be able single step and look at variables in the script executed by exec?
Add below to the script which is being called with exec
#!/usr/bin/perl -d

How to call a bash script as a post-deploy trigger with fortrabbit.yml

I'm using the following (excerpt) to run a script after deploy:
post-deploy:
script: bash refresh.sh
It never gets called, even though I can run it just fine if I ssh into the machine and execute the same command inside ~/htdocs.
What can I do to run this or similar scripts (e.g. php deploy.php) after deployment on Fortrabbit?
A bash script will not work, it must be a php script. However, inside your php script you can call anything using backticks:
http://php.net/manual/en/language.operators.execution.php

How to create one shortcut for list of commands

I have two commands which I have to run every time to open an application. How do I create a shortcut for these two commands in one shortcut. Let me give an example:
I have two commands:
D:\spl\v231_CCB\bin>splenviron.cmd -e v231_CCB
D:\spl\v231_CCB\bin>spl start
If I want to run the command 1 first and command 2 second then how do I create the shortcut according on my desktop?
splenviron.cmd -e v231_CCB && spl start
works for windows/ubuntu
If you want a shortcut, you should create a script, bat(windows) or sh(unix) file that will execute the above command. Or, as other smart people said it already, create an alias for this command :)
Create a batch file with this and then click that.
#echo off
pushd "D:\spl\v231_CCB\bin"
call splenviron.cmd -e v231_CCB
call spl start
The execution of spl will depend if splenviron.cmd runs and terminates, or keeps running.

How can I call a rake task on a git submodule?

I have a project including a number of vendored javascripts, e.g. jQuery. I'm including these scripts as git submodules. However, for my build process, I need the built script, not the whole repository of that script. So I'm trying to set up a rake task to build each script - preferably using the script's own rakefile - and then copy the built script into my asset directory.
file "app/vendor/scriptname.js" do
# Call the task that builds the script here
sh "cp app/vendor/script-submodule/dist/scriptname.js app/vendor/"
end
desc "Make vendor scripts available for build"
task :vendor => "app/vendor/scriptname.js" do
end
If I use import 'app/vendor/scriptname/Rakefile' in my Rakefile, I should have access to the rake task that builds the script, right? How would I call it? Or should I just use sh "cd app/vendor/script-submodule/ && rake dist" and call it good?
I'm working out a similar problem and it would seem to work just fine by calling the rake task as you normally would. Here's what my example looks like, see if you can get yours to fit.
# Rakefile
#!/usr/bin/env rake
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
load 'engines/foo_engine/Rakefile'
MyApp::Application.load_tasks
Then in my submodule's Rakefile:
# engines/foo_engine/Rakefile
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each do |f|
load f
end
And a sample rake task:
# engines/foo_engine/lib/tasks/foo/bar/task.rake
namespace :foo do
namespace :bar do
desc "FooBar task"
task :foo_bar => :environment do
# perform task
end
end
end
Then from the command prompt:
rake foo:bar:task