Class: Adminix::Helpers::Systemctl
- Inherits:
-
Object
- Object
- Adminix::Helpers::Systemctl
- Defined in:
- lib/adminix/helpers/systemctl.rb
Constant Summary collapse
- TMP_SCRIPT_PATH =
'/tmp/write_systemctl_script.sh'.freeze
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Systemctl
constructor
A new instance of Systemctl.
- #to_s ⇒ Object
- #write ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Systemctl
Returns a new instance of Systemctl.
6 7 8 9 10 11 12 |
# File 'lib/adminix/helpers/systemctl.rb', line 6 def initialize(opts = {}) @adminix_bin = opts[:adminix_bin] || Helpers::Command.which('adminix') @user = opts[:user] || Helpers::Command.whoami @group = opts[:group] || Helpers::Command.whoami @working_dir = opts[:working_dir] || Helpers::Command.home @systemctl_path = Adminix.config.systemctl[:watcher_service_path] end |
Instance Method Details
#to_s ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/adminix/helpers/systemctl.rb', line 24 def to_s "#!/bin/bash\n" \ "touch #{@systemctl_path}\n" \ "cat << EOT > #{@systemctl_path}\n" \ "[Unit]\n" \ "Description=Adminix\n" \ "Requires=network.target\n\n" \ "[Service]\n" \ "Type=simple\n" \ "User=#{@user}\n" \ "Group=#{@group}\n" \ "WorkingDirectory=#{@working_dir}\n" \ "ExecStart=#{@adminix_bin} watch\n" \ "Restart=always\n" \ "RestartSec=5\n" \ "StandardInput=null\n" \ "StandardOutput=syslog\n" \ "StandardError=syslog\n" \ "SyslogIdentifier=%n\n" \ "KillMode=mixed\n" \ "TimeoutStopSec=5\n" \ "TimeoutSec=300\n\n" \ "[Install]\n" \ "WantedBy=multi-user.target\n" \ "EOT\n" \ "# Run this command to configure your shell:\n" \ '# eval $(adminix write_systemctl)' end |
#write ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/adminix/helpers/systemctl.rb', line 14 def write Helpers::Files.rm(TMP_SCRIPT_PATH) Helpers::Files.write_plain_file(TMP_SCRIPT_PATH, to_s) Helpers::Output.([ "sudo sh #{TMP_SCRIPT_PATH}", '# Run this command to configure your shell:', '# eval $(adminix write_systemctl)' ]) end |