Subversion Repositories SmartDukaan

Rev

Rev 32337 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
32336 jai.hind 1
package com.spice.profitmandi.service.SshServer;
2
import com.jcraft.jsch.ChannelExec;
3
import com.jcraft.jsch.JSch;
4
import com.jcraft.jsch.Session;
5
import org.springframework.stereotype.Service;
6
@Service
7
public class SSHServiceImpl implements SSHService {
8
            @Override
9
            public void RestartServer(String ipAddress, int port, String username, String password, String remoteDirectoryPath, String command) {
10
                try {
11
                    JSch jsch = new JSch();
12
                    Session session = jsch.getSession(username, ipAddress, port);
13
                    session.setPassword(password);
14
                    session.setConfig("StrictHostKeyChecking", "no");
15
                    session.connect();
16
 
17
                    // Restart server
18
                    ChannelExec restartChannel = (ChannelExec) session.openChannel("exec");
19
                    restartChannel.setCommand(command);
20
                    restartChannel.connect();
21
                    while (!restartChannel.isClosed()) {
22
                        Thread.sleep(1000);
23
                    }
24
                    restartChannel.disconnect();
25
                    session.disconnect();
26
                } catch (Exception e) {
27
                    e.printStackTrace();
28
                }
29
            }
30
        }