Added vps restart

This commit is contained in:
litoral05
2026-05-06 12:09:39 +01:00
parent 0ac9f29ee0
commit 75565a9b2e
@@ -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);
}
}