Subversion Repositories SmartDukaan

Rev

Rev 32336 | Rev 32408 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package com.spice.profitmandi.service.SshServer;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import org.springframework.stereotype.Service;
@Service
public class SSHServiceImpl implements SSHService {
            @Override
            public void RestartServer(String ipAddress, int port, String username, String password, String remoteDirectoryPath, String command,String rebootCommand) {
                try {
                    JSch jsch = new JSch();
                    Session session = jsch.getSession(username, ipAddress, port);
                    session.setPassword(password);
                    session.setConfig("StrictHostKeyChecking", "no");
                    session.connect();
                    // Restart server
                    ChannelExec restartChannel = (ChannelExec) session.openChannel("exec");
                    restartChannel.setCommand(command);
                    //Reboot server
                    restartChannel.setCommand(rebootCommand);
                    restartChannel.connect();
                    while (!restartChannel.isClosed()) {
                        Thread.sleep(1000);
                    }
                    restartChannel.disconnect();
                    session.disconnect();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }