-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libnodectld: introduce VpsPostStart class
After VPS is started, nodectld reads its SSH host keys and os-release information. Since both require running osctl ct show, it's now done through a single point so as to not run it multiple times needlessly.
- Loading branch information
Showing
5 changed files
with
69 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require 'libosctl' | ||
require 'singleton' | ||
|
||
module NodeCtld | ||
class VpsPostStart | ||
include Singleton | ||
include OsCtl::Lib::Utils::Log | ||
include OsCtl::Lib::Utils::System | ||
include Utils::OsCtl | ||
|
||
class << self | ||
%i[run].each do |v| | ||
define_method(v) do |*args, **kwargs, &block| | ||
instance.send(v, *args, **kwargs, &block) | ||
end | ||
end | ||
end | ||
|
||
# @param vps_id [Integer] | ||
# @param in_seconds [Integer, nil] | ||
def run(vps_id, in_seconds: nil) | ||
in_seconds ||= $CFG.get(:vps_post_start, :default_schedule_delay) | ||
|
||
Thread.new do | ||
sleep(in_seconds) | ||
post_run(vps_id) | ||
end | ||
|
||
nil | ||
end | ||
|
||
def log_type | ||
'vps-post-start' | ||
end | ||
|
||
protected | ||
|
||
def post_run(vps_id) | ||
ct = OsCtlContainer.new(osctl_parse(%i[ct show], [vps_id])) | ||
return if ct.state != 'running' | ||
|
||
VpsSshHostKeys.update_ct(ct) | ||
VpsOsRelease.update_ct(ct) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters