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;@Servicepublic class SSHServiceImpl implements SSHService {@Overridepublic 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 serverChannelExec restartChannel = (ChannelExec) session.openChannel("exec");restartChannel.setCommand(command);//Reboot serverrestartChannel.setCommand(rebootCommand);restartChannel.connect();while (!restartChannel.isClosed()) {Thread.sleep(1000);}restartChannel.disconnect();session.disconnect();} catch (Exception e) {e.printStackTrace();}}}