From 030ca77c432acf61eace1534c561443403d794eb Mon Sep 17 00:00:00 2001
From: Thomas Bellman <bellman@lysator.liu.se>
Date: Wed, 20 Dec 2017 16:53:10 +0100
Subject: [PATCH] Add class for disabling console screensaver.

By default, the console screensaver is enabled on Linux systems (at
least RedHat:ish systems).  That makes it difficult to see kernel
crash messages on the console on physical servers, as the screensaver
typically is activated, and you can't deactivate it since the kernel
is dead and does not respond to key presses...

This adds a class console::screensaver::disable which disables the
console screensaver when the machine boots.
---
 manifests/screensaver/disable.pp | 53 ++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)
 create mode 100644 manifests/screensaver/disable.pp

diff --git a/manifests/screensaver/disable.pp b/manifests/screensaver/disable.pp
new file mode 100644
index 0000000..e33c69a
--- /dev/null
+++ b/manifests/screensaver/disable.pp
@@ -0,0 +1,53 @@
+# Copyright © 2017   Thomas Bellman, Linköping, Sweden
+# Licensed under the GNU LGPL v3+; see the README file for more information.
+
+
+/*
+ * Turn off the screensaver on the VGA console.
+ * This is useful in case of kernel crashes; if the screensaver was activated
+ * at the time of the crash, you can't see the crash message, and you can't
+ * deactivate the screensaver, since the kernel has died...
+ */
+class console::screensaver::disable
+{
+    # Need redirection to tty1 in case we have console=ttyS1
+    $setterm_cmd = 'TERM=linux setterm -blank 0 -powerdown 0 >/dev/tty1'
+
+    case $::initsystem
+    {
+	'sysvinit', 'upstart': {
+	    ensure_line {
+		'console::screensaver::disable::setterm':
+		    file => '/etc/rc.d/rc.local',
+		    line => $setterm_cmd,
+		    pattern => '(TERM=\S*\s)?(setterm.*-blank|setterm.*-powerdown).*';
+	    }
+	}
+	'systemd': {
+	    $lines = [
+		'# This file is under Puppet control',
+		'',
+		'[Unit]',
+		'Description=Disable screensaver on the console',
+		'',
+		'[Service]',
+		'Type=oneshot',
+		"ExecStart=/bin/sh -c '${setterm_cmd}'",
+		'',
+		'[Install]',
+		'WantedBy=basic.target',
+	    ]
+	    file {
+		'/etc/systemd/system/screensaver-disable.service':
+		    ensure => file,
+		    content => inline_template('<%=@lines.join("\n")+"\n" %>'),
+		    owner => 'root', group => 'root', mode => '0444',
+		    before => Service['screensaver-disable'];
+	    }
+	    service {
+		'screensaver-disable':
+		    enable => true, ensure => running;
+	    }
+	}
+    }
+}
-- 
GitLab