Skip to content

Commit 9b6588c

Browse files
Merge pull request #39 from rossta/feat/custom-systemctl-command
Support configuration of custom systemctl status command
2 parents af0863b + 22f5f7a commit 9b6588c

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/litestream.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def initialize
3333
end
3434
end
3535

36-
mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key
36+
mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key, :systemctl_command
3737

3838
class << self
3939
def verify!(database_path)
@@ -85,10 +85,14 @@ def replica_access_key
8585
@@replica_access_key || configuration.replica_access_key
8686
end
8787

88+
def systemctl_command
89+
@@systemctl_command || "systemctl status litestream"
90+
end
91+
8892
def replicate_process
8993
info = {}
9094
if !`which systemctl`.empty?
91-
systemctl_status = `systemctl status litestream`.chomp
95+
systemctl_status = `#{Litestream.systemctl_command}`.chomp
9296
# ["● litestream.service - Litestream",
9397
# " Loaded: loaded (/lib/systemd/system/litestream.service; enabled; vendor preset: enabled)",
9498
# " Active: active (running) since Tue 2023-07-25 13:49:43 UTC; 8 months 24 days ago",

test/test_litestream.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
require "test_helper"
44

55
class TestLitestream < Minitest::Test
6+
def teardown
7+
Litestream.systemctl_command = nil
8+
end
9+
610
def test_that_it_has_a_version_number
711
refute_nil ::Litestream::VERSION
812
end
@@ -28,6 +32,29 @@ def test_replicate_process_systemd
2832
end
2933
end
3034

35+
def test_replicate_process_systemd_custom_command
36+
stubbed_status = ["● myapp-litestream.service - Litestream",
37+
" Loaded: loaded (/lib/systemd/system/litestream.service; enabled; vendor preset: enabled)",
38+
" Active: active (running) since Tue 2023-07-25 13:49:43 UTC; 8 months 24 days ago",
39+
" Main PID: 1179656 (litestream)",
40+
" Tasks: 9 (limit: 1115)",
41+
" Memory: 22.9M",
42+
" CPU: 10h 49.843s",
43+
" CGroup: /system.slice/litestream.service",
44+
" └─1179656 /usr/bin/litestream replicate",
45+
"",
46+
"Warning: some journal files were not opened due to insufficient permissions."].join("\n")
47+
Litestream.systemctl_command = "systemctl --user status myapp-litestream.service"
48+
49+
Litestream.stub :`, stubbed_status do
50+
info = Litestream.replicate_process
51+
52+
assert_equal info[:status], "running"
53+
assert_equal info[:pid], "1179656"
54+
assert_equal info[:started].class, DateTime
55+
end
56+
end
57+
3158
def test_replicate_process_ps
3259
stubbed_ps_list = [
3360
"40358 ttys008 0:01.11 ruby --yjit bin/rails litestream:replicate",

0 commit comments

Comments
 (0)