View on GitHub


Test Coverage
#!/usr/bin/env ruby

require 'sys_watchdog'

def red mytext; "\e[31m#{mytext}\e[0m"; end

def help_msg
    sys_watchdog v#{SysWatchdogVersion::VERSION.dup}

    Usage: sys_watchdog [setup|test|start|stop|once|uninstall|help|version]

    When called without options executes the system tests each 60 seconds. This is the normal operation when working with a system daemon starter like systemd or upstart.

      setup        Create the configuration file, create the working directory and configure periodic run with systemd or cron.
      test         Similar to once, but also sets the log output to STDOUT.
      start        Start periodic run. If using systemd it will run 'systemctl start sys_watchdog'. If using cron it will enable/uncomment the cronjob line.  
      stop         Stop periodic run.
      once         Run tests once and exit, rather than run each 60 seconds which is the normal behavior.
      uninstall    Deletes created files and services. After that, if you want to completlly uninstall, run 'gem uninstall sys_watchdog'.
      -v, version  Prints version and exit.
      -h, help     Prints the current message.


setup_commands = %w(setup start stop uninstall)

case ARGV[0]

when 'test'
  sw = log_file: STDOUT once: true

when 'once' once: true

when nil

when 'version', '-v', '--version'
  puts SysWatchdogVersion::VERSION.dup

when 'help', '-h'
  puts help_msg

when *setup_commands ARGV[0].to_sym

  STDERR.puts red("Error: '#{ARGV[0]}' is not a valid option.")
  puts ""
  puts help_msg