Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ebouliane committed Dec 1, 2015
1 parent 7dfebb6 commit 47485bc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
30 changes: 14 additions & 16 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,39 @@
# check_file (String: default [/tmp/pp.scheduled-reboot])
# - The check file that is created with Start DateTime added to the end.
#
#
#
class scheduled_runonce (
$class_enabled = true,
$datetime_start = "2012-06-10 12:53:00",
$datetime_end = "2012-06-10 12:53:59",
$command_var = "/sbin/shutdown -ra now",
$check_file_prefix = "/tmp/pp.scheduled-task-once",
$datetime_start = '2012-06-10 12:53:00',
$datetime_end = '2012-06-10 12:53:59',
$command_var = '/sbin/shutdown -ra now',
$check_file_prefix = '/tmp/pp.scheduled-runonce',
) {
# Verify if target host is Linux
if $::kernel == 'Linux' {
# Get current date/time and convert to Linux string. Remove any carriage returns as well.
$dt_current = regsubst(generate('/bin/date', '+%s'),'\n','')
$dt_start = regsubst(generate('/bin/date', '-d',$datetime_start,'+%s'),'\n','')
$dt_end = regsubst(generate('/bin/date', '-d',$datetime_end,'+%s'),'\n','')
$check_file = "${check_file_prefix}.${dt_start}"
$check_file = '${check_file_prefix}.${dt_start}'

# Check if Class is disabled (Helps to disable some hosts)
# Check if Class is disabled (Helps to disable some hosts)
if $class_enabled == true {
# Check if Date/Time is within allowed period
# Check if Date/Time is within allowed period
if $dt_start <= $dt_current and $dt_end >= $dt_current {
# Prep Command that is to be run
$command_string = "touch ${check_file};${command_var}"
exec{"scheduled_reboot_command":
# Prep Command that is to be run
$command_string = 'touch ${check_file};${command_var}'
exec { "scheduled_reboot_command":
command => $command_string,
user => root,
onlyif => "/usr/bin/test ! -f ${check_file}",
onlyif => '/usr/bin/test ! -f ${check_file}',
path => ['/usr/bin','/sbin'],
}
notice('Reboot command will run. ${command_string}')
notice('Reboot command will run. ${command_string}')
} else {
notice('Not the right time. Current Date/Time: ${dt_current}. Start Date/Time: ${dt_start}. End Date/Time: ${dt_end}.')
}
} else {
notice('Class disabled.')
}
notice('Class disabled.')
}
}
}
5 changes: 3 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": [],
"license": "Apache-2.0",
"name": "Ramorous-scheduled_runonce",
"version": "0.1.14",
"version": "0.1.15",
"operatingsystem_support": [
{
"operatingsystem": "RedHat",
Expand All @@ -25,7 +25,8 @@
},
{"operatingsystem": "FreeBSD"}
],
"project_page": "",
"project_page": "https://forge.puppetlabs.com/Ramorous/scheduled_runonce",
"issues_url": "https://github.com/Ramorous/puppet-scheduled_runonce/issues",
"requirements": [],
"tags": []
}

0 comments on commit 47485bc

Please sign in to comment.