litestream_rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +172 -13
- data/app/controllers/litestream_rails/application_controller.rb +7 -0
- data/app/controllers/litestream_rails/processes_controller.rb +9 -0
- data/app/views/layouts/litestream_rails/_style.html +259 -618
- data/app/views/layouts/litestream_rails/application.html.erb +3 -3
- data/app/views/litestream_rails/processes/show.html.erb +106 -0
- data/config/routes.rb +2 -2
- data/lib/litestream_rails/version.rb +1 -1
- data/lib/litestream_rails.rb +58 -13
- metadata +8 -8
- data/app/controllers/litestream_rails/databases_controller.rb +0 -32
- data/app/views/litestream_rails/databases/index.html.erb +0 -85
@@ -7,12 +7,12 @@
|
|
7
7
|
|
8
8
|
<%= render "layouts/litestream_rails/style" %>
|
9
9
|
</head>
|
10
|
-
<body class="h-full flex flex-col
|
11
|
-
<main class="
|
10
|
+
<body class="h-full flex flex-col">
|
11
|
+
<main class="container mx-auto max-w-4xl mt-4 px-2 grow">
|
12
12
|
<%= content_for?(:content) ? yield(:content) : yield %>
|
13
13
|
</main>
|
14
14
|
|
15
|
-
<footer class="container mx-auto
|
15
|
+
<footer class="container mx-auto mt-24 flex items-center justify-between border-t px-2 py-4 text-base">
|
16
16
|
<p>
|
17
17
|
<code><strong>Litestream</strong> <em>Rails</em></code> |
|
18
18
|
Made by <a href="https://twitter.com/fractaledmind" class="text-blue-500 hover:underline decoration-blue-500">@fractaledmind</a> and <a href="https://github.com/fractaledmind/litestream_rails/graphs/contributors" class="text-blue-500 hover:underline decoration-blue-500">friends</a>! Want to help? It's <a href="https://github.com/fractaledmind/litestream_rails" class="text-blue-500 hover:underline decoration-blue-500">open source</a>!
|
@@ -0,0 +1,106 @@
|
|
1
|
+
<section id="process_<%= @process[:pid] %>" class="space-y-6">
|
2
|
+
<div class="flex items-center justify-between">
|
3
|
+
<h1 class="flex items-baseline gap-2 text-2xl font-bold">
|
4
|
+
Litestream
|
5
|
+
<small class="inline-flex rounded-full bg-green-100 px-2 text-sm font-semibold text-green-800">
|
6
|
+
<%= @process[:status] %>
|
7
|
+
</small>
|
8
|
+
</h1>
|
9
|
+
|
10
|
+
<small class="text-base">
|
11
|
+
#<code><%= @process[:pid] %></code>
|
12
|
+
</small>
|
13
|
+
</div>
|
14
|
+
|
15
|
+
<dl class="grid grid-cols-[fit-content(100%)_1fr] gap-x-4">
|
16
|
+
<dt class="font-bold">Started at</dt>
|
17
|
+
<dd class="">
|
18
|
+
<abbr title="<%= @process[:started] %>" class="underline decoration-dashed decoration-gray-500 cursor-help">
|
19
|
+
<time datetime="<%= @process[:started] %>"><%= @process[:started].to_formatted_s(:db) %></time>
|
20
|
+
</abbr>
|
21
|
+
</dd>
|
22
|
+
</dl>
|
23
|
+
</section>
|
24
|
+
<br>
|
25
|
+
<br>
|
26
|
+
|
27
|
+
<section id="generations" class="">
|
28
|
+
<div class="mb-3 flex items-center justify-between border-b">
|
29
|
+
<h2 class="text-2xl font-bold">Databases</h2>
|
30
|
+
<p class="text-right">Total: <strong><%= @databases.size %></strong></p>
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<ul class="list-[square] list-outside ml-4">
|
34
|
+
<% @databases.each do |database| %>
|
35
|
+
<li>
|
36
|
+
<div class="flex items-center justify-between">
|
37
|
+
<h2 class="text-lg font-bold">
|
38
|
+
<code><%= database['path'] %></code>
|
39
|
+
</h2>
|
40
|
+
<button type="button" class="rounded-md bg-slate-800 px-2.5 py-1.5 text-sm font-semibold text-white shadow-sm hover:bg-slate-700">Restore</button>
|
41
|
+
</div>
|
42
|
+
|
43
|
+
<br />
|
44
|
+
<section id="generations" class="ml-6">
|
45
|
+
<% database['generations'].each do |generation| %>
|
46
|
+
<details id="<%= generation['generation'] %>" open="open">
|
47
|
+
<summary class="cursor-pointer rounded p-2 hover:bg-gray-50">
|
48
|
+
<code><%= generation['generation'] %></code>
|
49
|
+
(<em><%= generation['lag'] %> lag</em>)
|
50
|
+
</summary>
|
51
|
+
|
52
|
+
<dl class="ml-7 grid grid-cols-[fit-content(100%)_1fr] gap-x-4">
|
53
|
+
<dt class="font-bold">Start</dt>
|
54
|
+
<dd class="">
|
55
|
+
<abbr title="<%= generation['start'] %>" class="underline decoration-dashed decoration-gray-500 cursor-help">
|
56
|
+
<time datetime="<%= generation['start'] %>"><%= DateTime.parse(generation['start']).to_formatted_s(:db) %></time>
|
57
|
+
</abbr>
|
58
|
+
</dd>
|
59
|
+
|
60
|
+
<dt class="font-bold">End</dt>
|
61
|
+
<dd class="">
|
62
|
+
<abbr title="<%= generation['end'] %>" class="underline decoration-dashed decoration-gray-500 cursor-help">
|
63
|
+
<time datetime="<%= generation['end'] %>"><%= DateTime.parse(generation['end']).to_formatted_s(:db) %></time>
|
64
|
+
</abbr>
|
65
|
+
</dd>
|
66
|
+
|
67
|
+
<div class="col-span-2">
|
68
|
+
<dt class="font-bold">Snapshots</dt>
|
69
|
+
<dd class="">
|
70
|
+
<table class="min-w-full divide-y divide-gray-300">
|
71
|
+
<thead>
|
72
|
+
<tr>
|
73
|
+
<th scope="col" class="whitespace-nowrap px-2 py-2 text-left text-sm font-semibold text-gray-900">Created at</th>
|
74
|
+
<th scope="col" class="whitespace-nowrap px-2 py-2 text-right text-sm font-semibold text-gray-900">Index</th>
|
75
|
+
<th scope="col" class="whitespace-nowrap px-2 py-2 text-right text-sm font-semibold text-gray-900">Size</th>
|
76
|
+
</tr>
|
77
|
+
</thead>
|
78
|
+
|
79
|
+
<tbody class="bg-white">
|
80
|
+
<% generation['snapshots'].each do |snapshot| %>
|
81
|
+
<tr class="align-top even:bg-gray-50">
|
82
|
+
<td scope="col" class="whitespace-nowrap px-2 py-2 text-sm text-gray-900">
|
83
|
+
<abbr title="<%= snapshot['created'] %>" class="underline decoration-dashed decoration-gray-500 cursor-help">
|
84
|
+
<time datetime="<%= snapshot['created'] %>"><%= DateTime.parse(snapshot['created']).to_formatted_s(:db) %></time>
|
85
|
+
</abbr>
|
86
|
+
</td>
|
87
|
+
<td scope="col" class="whitespace-nowrap px-2 py-2 text-sm text-gray-900 text-right">
|
88
|
+
<%= snapshot['index'] %>
|
89
|
+
</td>
|
90
|
+
<td scope="col" class="whitespace-nowrap px-2 py-2 text-sm text-gray-900 text-right">
|
91
|
+
<%= number_to_human_size snapshot['size'] %>
|
92
|
+
</td>
|
93
|
+
</tr>
|
94
|
+
<% end %>
|
95
|
+
</tbody>
|
96
|
+
</table>
|
97
|
+
</dd>
|
98
|
+
</div>
|
99
|
+
</dl>
|
100
|
+
</details>
|
101
|
+
<% end %>
|
102
|
+
</section>
|
103
|
+
</li>
|
104
|
+
<% end %>
|
105
|
+
</ul>
|
106
|
+
</section>
|
data/config/routes.rb
CHANGED
data/lib/litestream_rails.rb
CHANGED
@@ -10,25 +10,77 @@ module LitestreamRails
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
# use method instead of attr_accessor to ensure
|
13
|
-
# this works if variable set after
|
13
|
+
# this works if variable set after LitestreamRails is loaded
|
14
14
|
def username
|
15
15
|
@username ||= ENV["LITESTREAMRAILS_USERNAME"] || @@username
|
16
16
|
end
|
17
17
|
|
18
18
|
# use method instead of attr_accessor to ensure
|
19
|
-
# this works if variable set after
|
19
|
+
# this works if variable set after LitestreamRails is loaded
|
20
20
|
def password
|
21
21
|
@password ||= ENV["LITESTREAMRAILS_PASSWORD"] || @@password
|
22
22
|
end
|
23
23
|
|
24
|
+
def replicate_process
|
25
|
+
info = {}
|
26
|
+
if !`which systemctl`.empty?
|
27
|
+
systemctl_status = `systemctl status litestream`.chomp
|
28
|
+
# ["● litestream.service - Litestream",
|
29
|
+
# " Loaded: loaded (/lib/systemd/system/litestream.service; enabled; vendor preset: enabled)",
|
30
|
+
# " Active: active (running) since Tue 2023-07-25 13:49:43 UTC; 8 months 24 days ago",
|
31
|
+
# " Main PID: 1179656 (litestream)",
|
32
|
+
# " Tasks: 9 (limit: 1115)",
|
33
|
+
# " Memory: 22.9M",
|
34
|
+
# " CPU: 10h 49.843s",
|
35
|
+
# " CGroup: /system.slice/litestream.service",
|
36
|
+
# " └─1179656 /usr/bin/litestream replicate",
|
37
|
+
# "",
|
38
|
+
# "Warning: some journal files were not opened due to insufficient permissions."]
|
39
|
+
systemctl_status.split("\n").each do |line|
|
40
|
+
line.strip!
|
41
|
+
if line.start_with?("Main PID:")
|
42
|
+
_key, value = line.split(":")
|
43
|
+
pid, _name = value.strip.split(" ")
|
44
|
+
info[:pid] = pid
|
45
|
+
elsif line.start_with?("Active:")
|
46
|
+
_key, value = line.split(":")
|
47
|
+
value, _ago = value.split(";")
|
48
|
+
status, timestamp = value.split(" since ")
|
49
|
+
info[:started] = DateTime.strptime(timestamp.strip, "%Y-%m-%d %H:%M:%S %Z")
|
50
|
+
info[:status] = status.split("(").first.strip
|
51
|
+
end
|
52
|
+
end
|
53
|
+
else
|
54
|
+
litestream_replicate_ps = `ps -a | grep litestream | grep replicate`.chomp
|
55
|
+
litestream_replicate_ps.split("\n").each do |line|
|
56
|
+
next unless line.include?("litestream replicate")
|
57
|
+
pid, * = line.split(" ")
|
58
|
+
info[:pid] = pid
|
59
|
+
state, _, lstart = `ps -o "state,lstart" #{pid}`.chomp.split("\n").last.partition(/\s+/)
|
60
|
+
|
61
|
+
info[:status] = case state[0]
|
62
|
+
when "I" then "idle"
|
63
|
+
when "R" then "running"
|
64
|
+
when "S" then "sleeping"
|
65
|
+
when "T" then "stopped"
|
66
|
+
when "U" then "uninterruptible"
|
67
|
+
when "Z" then "zombie"
|
68
|
+
end
|
69
|
+
info[:started] = DateTime.strptime(lstart.strip, "%a %b %d %H:%M:%S %Y")
|
70
|
+
end
|
71
|
+
end
|
72
|
+
info
|
73
|
+
end
|
74
|
+
|
24
75
|
def databases
|
25
|
-
databases =
|
76
|
+
databases = Litestream::Commands.databases
|
26
77
|
|
27
78
|
databases.each do |db|
|
28
|
-
generations =
|
29
|
-
snapshots =
|
79
|
+
generations = Litestream::Commands.generations(db["path"])
|
80
|
+
snapshots = Litestream::Commands.snapshots(db["path"])
|
81
|
+
db["path"] = db["path"].gsub(Rails.root.to_s, "[ROOT]")
|
30
82
|
|
31
|
-
db[
|
83
|
+
db["generations"] = generations.map do |generation|
|
32
84
|
id = generation["generation"]
|
33
85
|
replica = generation["name"]
|
34
86
|
generation["snapshots"] = snapshots.select { |snapshot| snapshot["generation"] == id && snapshot["replica"] == replica }
|
@@ -37,12 +89,5 @@ module LitestreamRails
|
|
37
89
|
end
|
38
90
|
end
|
39
91
|
end
|
40
|
-
|
41
|
-
private
|
42
|
-
|
43
|
-
def text_table_to_hashes(string)
|
44
|
-
keys, *rows = string.split("\n").map { _1.split(/\s+/) }
|
45
|
-
rows.map { keys.zip(_1).to_h }
|
46
|
-
end
|
47
92
|
end
|
48
93
|
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: litestream_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Margheim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: litestream
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.6.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.6.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: actionpack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -90,10 +90,10 @@ files:
|
|
90
90
|
- README.md
|
91
91
|
- Rakefile
|
92
92
|
- app/controllers/litestream_rails/application_controller.rb
|
93
|
-
- app/controllers/litestream_rails/
|
93
|
+
- app/controllers/litestream_rails/processes_controller.rb
|
94
94
|
- app/views/layouts/litestream_rails/_style.html
|
95
95
|
- app/views/layouts/litestream_rails/application.html.erb
|
96
|
-
- app/views/litestream_rails/
|
96
|
+
- app/views/litestream_rails/processes/show.html.erb
|
97
97
|
- config/routes.rb
|
98
98
|
- lib/litestream_rails.rb
|
99
99
|
- lib/litestream_rails/engine.rb
|
@@ -1,32 +0,0 @@
|
|
1
|
-
module LitestreamRails
|
2
|
-
class DatabasesController < ApplicationController
|
3
|
-
around_action :force_english_locale!
|
4
|
-
|
5
|
-
# GET /databases
|
6
|
-
def index
|
7
|
-
@databases = LitestreamRails.databases
|
8
|
-
[{"path"=>"/Users/fractaled/Code/Playgrounds/wrocloverb/storage/production.sqlite3",
|
9
|
-
"replicas"=>"s3",
|
10
|
-
"generations"=>
|
11
|
-
[{"generation"=>"5f4341bc3d22d615",
|
12
|
-
"name"=>"s3",
|
13
|
-
"lag"=>"3s",
|
14
|
-
"start"=>"2024-04-17T19:48:09Z",
|
15
|
-
"end"=>"2024-04-17T19:48:09Z",
|
16
|
-
"snapshots"=>[{"index"=>"0", "size"=>"4645465", "created"=>"2024-04-17T19:48:09Z"}]},
|
17
|
-
{"generation"=>"a184b05a685589f3",
|
18
|
-
"name"=>"s3",
|
19
|
-
"lag"=>"19h46m52s",
|
20
|
-
"start"=>"2024-04-17T00:01:19Z",
|
21
|
-
"end"=>"2024-04-17T00:01:19Z",
|
22
|
-
"snapshots"=>[{"index"=>"1", "size"=>"4645465", "created"=>"2024-04-17T00:01:19Z"}]}]}]
|
23
|
-
end
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def force_english_locale!(&action)
|
28
|
-
I18n.with_locale(:en, &action)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
@@ -1,85 +0,0 @@
|
|
1
|
-
<ul>
|
2
|
-
<% @databases.each do |database| %>
|
3
|
-
<li>
|
4
|
-
<section id="error_12" class="space-y-6">
|
5
|
-
<div class="flex items-center justify-between">
|
6
|
-
<h1 class="flex items-center gap-2 text-2xl font-bold">
|
7
|
-
<code><%= database['path'] %></code>
|
8
|
-
</h1>
|
9
|
-
</div>
|
10
|
-
</section>
|
11
|
-
<br />
|
12
|
-
<section id="generations" class="-mx-2 mt-4 sm:mx-0 sm:rounded-md">
|
13
|
-
<div class="mb-3 flex items-center justify-between border-b">
|
14
|
-
<h2 class="text-2xl font-bold">Generations</h2>
|
15
|
-
<p class="text-right">Total: <strong><%= database['generations'].size %></strong></p>
|
16
|
-
</div>
|
17
|
-
|
18
|
-
<div class="min-w-full">
|
19
|
-
<% database['generations'].each do |generation| %>
|
20
|
-
<section id="<%= generation['generation'] %>" class="">
|
21
|
-
<details open="open">
|
22
|
-
<summary class="cursor-pointer rounded p-2 hover:bg-gray-50">
|
23
|
-
<code><%= generation['generation'] %></code>
|
24
|
-
(<em><%= generation['lag'] %> lag</em>)
|
25
|
-
</summary>
|
26
|
-
<div class="">
|
27
|
-
<dl class="grid flex-1 grid-cols-2 gap-x-4">
|
28
|
-
<div class="flex flex-wrap items-center justify-between gap-x-2">
|
29
|
-
<dt class="font-bold">Start</dt>
|
30
|
-
<dd class="inline-flex items-center gap-1">
|
31
|
-
<abbr title="<%= generation['start'] %>" class="cursor-help">
|
32
|
-
<time datetime="<%= generation['start'] %>"><%= DateTime.parse(generation['start']).to_formatted_s(:db) %></time>
|
33
|
-
</abbr>
|
34
|
-
</dd>
|
35
|
-
</div>
|
36
|
-
<div class="flex flex-wrap items-center justify-between gap-x-2">
|
37
|
-
<dt class="font-bold">End</dt>
|
38
|
-
<dd class="inline-flex items-center gap-1">
|
39
|
-
<abbr title="<%= generation['end'] %>" class="cursor-help">
|
40
|
-
<time datetime="<%= generation['end'] %>"><%= DateTime.parse(generation['end']).to_formatted_s(:db) %></time>
|
41
|
-
</abbr>
|
42
|
-
</dd>
|
43
|
-
</div>
|
44
|
-
<div class="col-span-2">
|
45
|
-
<dt class="font-bold">Snapshots</dt>
|
46
|
-
<dd class="">
|
47
|
-
<table class="min-w-full divide-y divide-gray-300">
|
48
|
-
<thead>
|
49
|
-
<tr>
|
50
|
-
<th scope="col" class="py-3.5 pl-4 pr-3 text-left text-sm font-semibold text-gray-900 sm:pl-3">Created</th>
|
51
|
-
<th scope="col" class="px-3 py-3.5 text-right text-sm font-semibold text-gray-900">Index</th>
|
52
|
-
<th scope="col" class="px-3 py-3.5 text-right text-sm font-semibold text-gray-900">Size</th>
|
53
|
-
</tr>
|
54
|
-
</thead>
|
55
|
-
|
56
|
-
<tbody class="bg-white">
|
57
|
-
<% generation['snapshots'].each do |snapshot| %>
|
58
|
-
<tr class="align-top even:bg-gray-50">
|
59
|
-
<td scope="col" class="whitespace-nowrap px-3 py-4 pt-7 text-left text-gray-500">
|
60
|
-
<abbr title="<%= snapshot['created'] %>" class="cursor-help">
|
61
|
-
<time datetime="<%= snapshot['created'] %>"><%= DateTime.parse(snapshot['created']).to_formatted_s(:db) %></time>
|
62
|
-
</abbr>
|
63
|
-
</td>
|
64
|
-
<td scope="col" class="whitespace-nowrap px-3 py-4 pt-7 text-right text-gray-500">
|
65
|
-
<%= snapshot['index'] %>
|
66
|
-
</td>
|
67
|
-
<td scope="col" class="whitespace-nowrap px-3 py-4 pt-7 text-right text-gray-500">
|
68
|
-
<%= number_to_human_size snapshot['size'] %>
|
69
|
-
</td>
|
70
|
-
</tr>
|
71
|
-
<% end %>
|
72
|
-
</tbody>
|
73
|
-
</table>
|
74
|
-
</dd>
|
75
|
-
</div>
|
76
|
-
</dl>
|
77
|
-
</div>
|
78
|
-
</details>
|
79
|
-
</section>
|
80
|
-
<% end %>
|
81
|
-
</div>
|
82
|
-
</section>
|
83
|
-
</li>
|
84
|
-
<% end %>
|
85
|
-
</ul>
|