Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuration of custom systemctl status command #39

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/litestream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def initialize
end
end

mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key
mattr_writer :username, :password, :queue, :replica_bucket, :replica_key_id, :replica_access_key, :systemctl_command

class << self
def verify!(database_path)
Expand Down Expand Up @@ -85,10 +85,14 @@ def replica_access_key
@@replica_access_key || configuration.replica_access_key
end

def systemctl_command
@@systemctl_command || "systemctl status litestream"
end

def replicate_process
info = {}
if !`which systemctl`.empty?
systemctl_status = `systemctl status litestream`.chomp
systemctl_status = `#{Litestream.systemctl_command}`.chomp
# ["● litestream.service - Litestream",
# " Loaded: loaded (/lib/systemd/system/litestream.service; enabled; vendor preset: enabled)",
# " Active: active (running) since Tue 2023-07-25 13:49:43 UTC; 8 months 24 days ago",
Expand Down
27 changes: 27 additions & 0 deletions test/test_litestream.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
require "test_helper"

class TestLitestream < Minitest::Test
def teardown
Litestream.systemctl_command = nil
end

def test_that_it_has_a_version_number
refute_nil ::Litestream::VERSION
end
Expand All @@ -28,6 +32,29 @@ def test_replicate_process_systemd
end
end

def test_replicate_process_systemd_custom_command
stubbed_status = ["● myapp-litestream.service - Litestream",
" Loaded: loaded (/lib/systemd/system/litestream.service; enabled; vendor preset: enabled)",
" Active: active (running) since Tue 2023-07-25 13:49:43 UTC; 8 months 24 days ago",
" Main PID: 1179656 (litestream)",
" Tasks: 9 (limit: 1115)",
" Memory: 22.9M",
" CPU: 10h 49.843s",
" CGroup: /system.slice/litestream.service",
" └─1179656 /usr/bin/litestream replicate",
"",
"Warning: some journal files were not opened due to insufficient permissions."].join("\n")
Litestream.systemctl_command = "systemctl --user status myapp-litestream.service"

Litestream.stub :`, stubbed_status do
info = Litestream.replicate_process

assert_equal info[:status], "running"
assert_equal info[:pid], "1179656"
assert_equal info[:started].class, DateTime
end
end

def test_replicate_process_ps
stubbed_ps_list = [
"40358 ttys008 0:01.11 ruby --yjit bin/rails litestream:replicate",
Expand Down
Loading