バックグラウンドで太陽黒点を実行するための以下のエイリアスは、それらのインスタンスを見つけて殺すための以下のエイリアスで機能します。 .
$user_id は、この sunspot_ports() が呼び出される前に設定され、rebash への最初のログインがソース ~.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() 内に配置してみました。ログインすると太陽黒点ポートが正しく出力されるので、このコードが実行されることがわかります。
また、jvm では fork が許可されていないため、これを jruby コードのどこかではなく .bashrc の関数として使用する必要があります (それ以外の場合は、スペック テストで sunspot-solr start と sunspot-solr end を使用します)。