Added vps restart
This commit is contained in:
@@ -0,0 +1,37 @@
|
|||||||
|
package com.litoralregas.openvpn.vps;
|
||||||
|
|
||||||
|
import com.litoralregas.openvpn.ssh.SshCommandResult;
|
||||||
|
import com.litoralregas.openvpn.ssh.SshService;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/vps")
|
||||||
|
public class VpsController {
|
||||||
|
|
||||||
|
private final SshService sshService;
|
||||||
|
|
||||||
|
public VpsController(SshService sshService) {
|
||||||
|
this.sshService = sshService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/openvpn/restart")
|
||||||
|
public ResponseEntity<?> restartOpenVpn() {
|
||||||
|
|
||||||
|
SshCommandResult restart = sshService.executeOnConfiguredVps(
|
||||||
|
"sudo systemctl restart openvpn-server@server"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (restart.exitCode() != 0) {
|
||||||
|
return ResponseEntity.internalServerError().body(restart);
|
||||||
|
}
|
||||||
|
|
||||||
|
SshCommandResult status = sshService.executeOnConfiguredVps(
|
||||||
|
"systemctl is-active openvpn-server@server"
|
||||||
|
);
|
||||||
|
|
||||||
|
return ResponseEntity.ok(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user