【发布时间】:2011-12-07 16:32:29
【问题描述】:
下面的别名用于在后台运行太阳黑子 以下用于查找和杀死这些实例的别名有效 太阳黑子端口的 ENV 变量可访问 但, 运行 sunspot、处理命令和杀死 sunspot 的函数只有在我在函数之外获取 .bashrc 后才能工作。
$user_id 在此之前设置 sunspot_ports() 在首次登录时被调用并正确打印 rebash 是 source ~.bashrc 的别名
我也有开发和生产的别名 - 这只是代表代码。
sunspot_ports ()
{
#alias sunspot_run_test to the user's port
sunspot_test_port=$(($user_id +5300))
echo "Your sunspot test port: $sunspot_test_port"
alias sunspot_run_test="RAILS_ENV=test sunspot-solr run -p${sunspot_test_port} &"
alias sunspot_kill_test="fuser -n tcp ${sunspot_test_port} -k"
export sunspot_production_port sunspot_development_port sunspot_test_port
}
solr_test()
{
#only makes the aliases be recognized when it is outside the function
#rebash
#aliases not recognized without a rebash prior to the function
sunspot_run_test
#commands not recognized even with rebash
#"RAILS_ENV=test sunspot-solr run -p${sunspot_test_port} &"
sleep 10;
"$@";
sunspot_kill_test;
#commands not recognized even with rebash
#"fuser -n tcp ${sunspot_test_port} -k"
}
我尝试在函数中获取 .bashrc,用扩展命令替换别名,并将函数放在 sunspot_ports() 中的每个组合中。当我登录时,太阳黑子端口打印正确,所以我知道这段代码会运行。
另外,我需要在 .bashrc 中将其作为一个函数,而不是在我的 jruby 代码中的某个位置,因为 jvm 不允许分叉(否则我只会在我的规范测试中使用 sunspot-solr start 和 sunspot-solr end )
【问题讨论】:
标签: jrubyonrails sunspot-rails bash bash-function