3

Mina SSHD クライアントを使用して、OpenSSH サーバーでリモート コマンドを実行しています。リモート サーバーで実行時間の長いコマンドを実行していますが、クライアント セッションが閉じられたときにコマンドを終了させたいと考えています。

PC端末からこのコマンドを実行すると:

\#ssh -t user@server sleep 12345

これは私がリモートマシンで見つけたものです:

\# ps -axf

---- Omitted for clarity

12158 ?        Ss     0:29 /usr/sbin/sshd -4
22708 ?        Ss     0:11  \\_ sshd: user@pts/3,pts/4
16894 pts/3    Ss     0:00  |   \\_ -bash
17750 pts/3    R+     0:00  |   |   \\_ ps -axf
17606 pts/4    Ss+    0:00  |   \\_ sleep 12345

---- Omitted for clarity

自分のマシンで ssh クライアントを強制終了すると、リモート マシンで「sleep 12345」が終了します。

ただし、Mina Java SSH クライアントを使用してまったく同じことを実行すると、これが表示されます。

    SshClient client = SshClient.setUpDefaultClient();
    client.start();
    ConnectFuture connect = client.connect("user", "server", 22);

    connect.await(10000); //ms
    ClientSession session = connect.getSession();
    session.addPasswordIdentity("password");
    AuthFuture auth = session.auth();
    auth.await(10000);

    ClientChannel channel = session.createExecChannel("sleep 12345");

    OpenFuture open = channel.open();
    open.await(10000);
    Thread.sleep(15000); // ms, wait for command to run
    channel.close(true);
    session.close(true);
    client.stop();


\# ps -axf

---- Omitted for clarity

27364 ?        Ss     0:00  \\_ sshd: user@pts/0  
3277 pts/0    Ss     0:00  |   \\_ -bash
22306 pts/0    R+     0:00  |       \\_ ps axf
21699 ?        Ss     0:00  \\_ sshd: user@notty  
21796 ?        Ss     0:00      \\_ sleep 12345

---- Omitted for clarity

コードが終了すると、コマンドの親が init pid になります。

\# ps -axf 

21796 ?        Ss     0:00 sleep 12345


\#ps -ef | grep sleep

root     21796     1  0 08:26 ?        00:00:00 sleep 12345

セッションを閉じたときにリモートサーバーでコマンドを終了させるためのフラグまたはオプションが Mina にありますか?

4

1 に答える 1