Skip to content

Commit

Permalink
determin inactive users and clean their PUNs too
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Nov 7, 2024
1 parent c43e125 commit acd0817
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions nginx_stage/lib/nginx_stage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,21 @@ def self.active_users
end.compact
end

# List of inactive users.
# @return [Array<String>] the list of inactive users.
def self.inactive_users
Dir[pun_pid_path(user: '*')].map do |v|
name = v[/#{pun_pid_path(user: '(.+)')}/, 1]
User.new(name)

# return nil here becasue we actually _want_ to rescue.
# i.e., a User is inactive if it _can't_ be instanitated.
nil
rescue ArgumentError => e
name
end.compact
end

# Get a hash of all the staged app configs
# @example List of all staged app configs
# staged_apps
Expand Down
15 changes: 15 additions & 0 deletions nginx_stage/lib/nginx_stage/generators/nginx_clean_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,21 @@ class NginxCleanGenerator < Generator
$stderr.puts "#{$!.to_s}"
end
end

NginxStage.inactive_users.each do |u|
begin
puts "#{u} (disabled)"
pid_path = PidFile.new NginxStage.pun_pid_path(user: u)

`kill -s TERM #{pid_path.pid}`
FileUtils.rm_rf(Pathname.new(pid_path.to_s).parent)
FileUtils.rm(NginxStage.pun_secret_key_base_path(user: u).to_s)
FileUtils.rm(NginxStage.pun_config_path(user: u).to_s)

rescue StandardError => e
warn "Error trying to clean up disabled user #{u}: #{e.message}"
end
end
end

def cleanup_stale_files(pid_path, socket)
Expand Down

0 comments on commit acd0817

Please sign in to comment.