| @@ 817-846 (lines=30) @@ | ||
| 814 | * |
|
| 815 | * @throws \Pterodactyl\Exceptions\DisplayException |
|
| 816 | */ |
|
| 817 | public function suspend($id, $deleted = false) |
|
| 818 | { |
|
| 819 | $server = Models\Server::with('node')->findOrFail($id); |
|
| 820 | ||
| 821 | DB::beginTransaction(); |
|
| 822 | ||
| 823 | try { |
|
| 824 | ||
| 825 | // Already suspended, no need to make more requests. |
|
| 826 | if ($server->suspended) { |
|
| 827 | return true; |
|
| 828 | } |
|
| 829 | ||
| 830 | $server->suspended = 1; |
|
| 831 | $server->save(); |
|
| 832 | ||
| 833 | $server->node->guzzleClient([ |
|
| 834 | 'X-Access-Token' => $server->node->daemonSecret, |
|
| 835 | 'X-Access-Server' => $server->uuid, |
|
| 836 | ])->request('POST', '/server/suspend'); |
|
| 837 | ||
| 838 | return DB::commit(); |
|
| 839 | } catch (TransferException $ex) { |
|
| 840 | DB::rollBack(); |
|
| 841 | throw new DisplayException('An error occured while attempting to contact the remote daemon to suspend this server.', $ex); |
|
| 842 | } catch (\Exception $ex) { |
|
| 843 | DB::rollBack(); |
|
| 844 | throw $ex; |
|
| 845 | } |
|
| 846 | } |
|
| 847 | ||
| 848 | /** |
|
| 849 | * Unsuspends a server. |
|
| @@ 856-885 (lines=30) @@ | ||
| 853 | * |
|
| 854 | * @throws \Pterodactyl\Exceptions\DisplayException |
|
| 855 | */ |
|
| 856 | public function unsuspend($id) |
|
| 857 | { |
|
| 858 | $server = Models\Server::with('node')->findOrFail($id); |
|
| 859 | ||
| 860 | DB::beginTransaction(); |
|
| 861 | ||
| 862 | try { |
|
| 863 | ||
| 864 | // Already unsuspended, no need to make more requests. |
|
| 865 | if ($server->suspended === 0) { |
|
| 866 | return true; |
|
| 867 | } |
|
| 868 | ||
| 869 | $server->suspended = 0; |
|
| 870 | $server->save(); |
|
| 871 | ||
| 872 | $server->node->guzzleClient([ |
|
| 873 | 'X-Access-Token' => $server->node->daemonSecret, |
|
| 874 | 'X-Access-Server' => $server->uuid, |
|
| 875 | ])->request('POST', '/server/unsuspend'); |
|
| 876 | ||
| 877 | return DB::commit(); |
|
| 878 | } catch (TransferException $ex) { |
|
| 879 | DB::rollBack(); |
|
| 880 | throw new DisplayException('An error occured while attempting to contact the remote daemon to un-suspend this server.', $ex); |
|
| 881 | } catch (\Exception $ex) { |
|
| 882 | DB::rollBack(); |
|
| 883 | throw $ex; |
|
| 884 | } |
|
| 885 | } |
|
| 886 | ||
| 887 | /** |
|
| 888 | * Updates the SFTP password for a server. |
|