add spawn start stop buttons
This commit is contained in:
parent
d3579504aa
commit
7022b48bda
5 changed files with 21 additions and 21 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
class ServersController < ApplicationController
|
class ServersController < ApplicationController
|
||||||
before_action :set_server, only: [ :show, :destroy, :start, :stop, :restart ]
|
before_action :set_server, only: [ :show, :destroy, :start, :stop, :restart, :spawn ]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@servers = current_user.servers.includes(:server_template).order(created_at: :desc)
|
@servers = current_user.servers.includes(:server_template).order(created_at: :desc)
|
||||||
|
|
@ -36,6 +36,14 @@ class ServersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def spawn
|
||||||
|
authorize_user!
|
||||||
|
Activity.log(current_user, "spawning", "Server", @server.id, { name: @server.name })
|
||||||
|
SpawnServerJob.perform_later(@server.id)
|
||||||
|
@server.update(status: :starting)
|
||||||
|
redirect_to @server, notice: "Server spawning..."
|
||||||
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
authorize_user!
|
authorize_user!
|
||||||
L4dServer::SystemdManager.start(@server)
|
L4dServer::SystemdManager.start(@server)
|
||||||
|
|
|
||||||
|
|
@ -18,17 +18,15 @@
|
||||||
|
|
||||||
.server-actions
|
.server-actions
|
||||||
- case @server.status
|
- case @server.status
|
||||||
- when "stopped"
|
- when "stopped", "failed"
|
||||||
= form_with url: start_server_path(@server), method: :post, local: true do |f|
|
= button_to "Spawn Server", spawn_server_path(@server), method: :post, class: "btn btn--primary"
|
||||||
= f.submit "Start", class: "btn btn--success"
|
= button_to "Start Server", start_server_path(@server), method: :post, class: "btn btn--success"
|
||||||
- when "starting", "running"
|
- when "starting", "running"
|
||||||
= form_with url: stop_server_path(@server), method: :post, local: true do |f|
|
= button_to "Stop Server", stop_server_path(@server), method: :post, class: "btn btn--warning"
|
||||||
= f.submit "Stop", class: "btn btn--warning"
|
= button_to "Restart Server", restart_server_path(@server), method: :post, class: "btn btn--warning"
|
||||||
= form_with url: restart_server_path(@server), method: :post, local: true do |f|
|
|
||||||
= f.submit "Restart", class: "btn btn--warning"
|
|
||||||
|
|
||||||
= link_to "Delete Server", server_path(@server), method: :delete, data: { confirm: "Sure?" }, class: "btn btn--danger"
|
= button_to "Delete Server", server_path(@server), method: :delete, data: { confirm: "Are you sure? This will stop and remove the server." }, class: "btn btn--danger"
|
||||||
= link_to "Back", servers_path, class: "btn"
|
= link_to "Back to Servers", servers_path, class: "btn"
|
||||||
|
|
||||||
section.logs
|
section.logs
|
||||||
h3 Live Logs
|
h3 Live Logs
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ Rails.application.routes.draw do
|
||||||
|
|
||||||
resources :servers do
|
resources :servers do
|
||||||
member do
|
member do
|
||||||
|
post :spawn
|
||||||
post :start
|
post :start
|
||||||
post :stop
|
post :stop
|
||||||
post :restart
|
post :restart
|
||||||
|
|
|
||||||
|
|
@ -26,13 +26,8 @@ module L4dServer
|
||||||
private
|
private
|
||||||
|
|
||||||
def render_config
|
def render_config
|
||||||
lines = []
|
# config is now a text field, not an association
|
||||||
|
@template.config.to_s
|
||||||
@template.config_options.each do |option|
|
|
||||||
lines << "#{option.config_key} \"#{option.config_value}\""
|
|
||||||
end
|
|
||||||
|
|
||||||
lines.join("\n")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -81,11 +81,9 @@ module L4dServer
|
||||||
|
|
||||||
def render_unit
|
def render_unit
|
||||||
template = @server.server_template
|
template = @server.server_template
|
||||||
overlays_str = template.template_overlays.ordered.map { |to| "/opt/l4d2/overlays/#{to.overlay.name}" }.join(":")
|
|
||||||
|
|
||||||
startup_args = template.startup_params.map { |param| "#{param.param_key} #{param.param_value}" }.join(" ")
|
# startup_params is now a text field, not an association
|
||||||
|
startup_args = template.startup_params.to_s.strip
|
||||||
ExecStart = "/opt/l4d2/servers/#{@server.id}/merged/srcds_run -norestart -pidfile /opt/l4d2/servers/#{@server.id}/pid -game left4dead2 -ip 0.0.0.0 -port #{@server.port} +hostname \"#{@server.name}\" +map c1m1_hotel #{startup_args}".strip
|
|
||||||
|
|
||||||
<<~UNIT
|
<<~UNIT
|
||||||
[Unit]
|
[Unit]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue