Subversion Repositories SmartDukaan

Rev

Rev 32336 | Rev 32408 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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