class Helpers::NewSystemd
Class NewSystemd
Used to create a systemd service
Example:¶ ↑
require Helpers
string = <<EOF
- Description
- Service
-
Type=simple
- Installation
-
WantedBy = EOF new_systemd =
Helpers::NewSystemd.new
(string, “tor.service”) new_systemd.add
Public Class Methods
new(string, name)
click to toggle source
Method new
Parameters:¶ ↑
-
string = the string of for whole content file
-
name = the name of the service (e.g: tor.service)
Calls superclass method
Helpers::NewFile::new
# File lib/spior/helpers.rb, line 88 def initialize(string, name) super @systemd_dir = search_systemd_dir @dest = @systemd_dir + "/" + @name end
Public Instance Methods
add()
click to toggle source
Method add
Create a temporary file and move the service @name to the systemd directory
Calls superclass method
Helpers::NewFile#add
# File lib/spior/helpers.rb, line 97 def add @systemctl = Helpers::Exec.new("systemctl") super @systemctl.run("daemon-reload") end
Private Instance Methods
search_systemd_dir()
click to toggle source
Method search_systemd_dir
Search the current directory for systemd services + Gentoo can install at /lib/systemd/system or /usr/lib/systemd/system
# File lib/spior/helpers.rb, line 107 def search_systemd_dir if Dir.exist? "/lib/systemd/system" "/lib/systemd/system" elsif Dir.exist? "/usr/lib/systemd/system" "/usr/lib/systemd/system" else raise "No directory systemd found" exit end end