summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Hess2015-11-24 09:58:45 -0400
committerJoey Hess2015-11-24 09:58:45 -0400
commit38d205fdce91a51b32989d16a33096bd9bcfd2c2 (patch)
treec5b07ef33e27751c00b89d5c229a423ab1b9ed24
parenteaac29e5cdb25102de5a48f4bd54a60c9d8bf24d (diff)
parent776c11f6a9187da03324b879e744a8f07b480a09 (diff)
Merge branch 'joeyconfig'
-rw-r--r--config-joey.hs2
-rw-r--r--src/Propellor/Property/SiteSpecific/JoeySites.hs41
-rw-r--r--src/Utility/Scheduled.hs1
3 files changed, 44 insertions, 0 deletions
diff --git a/config-joey.hs b/config-joey.hs
index 34b48027..98cb195a 100644
--- a/config-joey.hs
+++ b/config-joey.hs
@@ -80,6 +80,8 @@ darkstar = host "darkstar.kitenet.net"
& JoeySites.postfixClientRelay (Context "darkstar.kitenet.net")
& JoeySites.dkimMilter
+ & JoeySites.alarmClock "*-*-* 7:30" (User "joey")
+ "/usr/bin/timeout 45m /home/joey/bin/goodmorning"
& imageBuilt "/tmp/img" c MSDOS (grubBooted PC)
[ partition EXT2 `mountedAt` "/boot"
diff --git a/src/Propellor/Property/SiteSpecific/JoeySites.hs b/src/Propellor/Property/SiteSpecific/JoeySites.hs
index d6a50309..d22eb615 100644
--- a/src/Propellor/Property/SiteSpecific/JoeySites.hs
+++ b/src/Propellor/Property/SiteSpecific/JoeySites.hs
@@ -6,6 +6,7 @@ module Propellor.Property.SiteSpecific.JoeySites where
import Propellor.Base
import qualified Propellor.Property.Apt as Apt
import qualified Propellor.Property.File as File
+import qualified Propellor.Property.ConfFile as ConfFile
import qualified Propellor.Property.Gpg as Gpg
import qualified Propellor.Property.Ssh as Ssh
import qualified Propellor.Property.Git as Git
@@ -929,3 +930,43 @@ userDirHtml = File.fileProperty "apache userdir is html" (map munge) conf
munge = replace "public_html" "html"
conf = "/etc/apache2/mods-available/userdir.conf"
+-- Alarm clock: see
+-- <http://joeyh.name/blog/entry/a_programmable_alarm_clock_using_systemd/>
+--
+-- oncalendar example value: "*-*-* 7:30"
+alarmClock :: String -> User -> String -> Property NoInfo
+alarmClock oncalendar (User user) command = combineProperties
+ "goodmorning timer installed"
+ [ "/etc/systemd/system/goodmorning.timer" `File.hasContent`
+ [ "[Unit]"
+ , "Description=good morning"
+ , ""
+ , "[Timer]"
+ , "Unit=goodmorning.service"
+ , "OnCalendar=" ++ oncalendar
+ , "WakeSystem=true"
+ , "Persistent=false"
+ , ""
+ , "[Install]"
+ , "WantedBy=multi-user.target"
+ ]
+ `onChange` (Systemd.daemonReloaded
+ `before` Systemd.restarted "goodmorning.timer")
+ , "/etc/systemd/system/goodmorning.service" `File.hasContent`
+ [ "[Unit]"
+ , "Description=good morning"
+ , "RefuseManualStart=true"
+ , "RefuseManualStop=true"
+ , "ConditionACPower=true"
+ , "StopWhenUnneeded=yes"
+ , ""
+ , "[Service]"
+ , "Type=oneshot"
+ , "ExecStart=/bin/systemd-inhibit --what=handle-lid-switch --why=goodmorning /bin/su " ++ user ++ " -c \"" ++ command ++ "\""
+ ]
+ `onChange` Systemd.daemonReloaded
+ , Systemd.enabled "goodmorning.timer"
+ , Systemd.started "goodmorning.timer"
+ , "/etc/systemd/logind.conf" `ConfFile.containsIniSetting`
+ ("Login", "LidSwitchIgnoreInhibited", "no")
+ ]
diff --git a/src/Utility/Scheduled.hs b/src/Utility/Scheduled.hs
index ead8f771..d23aaf03 100644
--- a/src/Utility/Scheduled.hs
+++ b/src/Utility/Scheduled.hs
@@ -36,6 +36,7 @@ import Data.Time.LocalTime
import Data.Time.Calendar
import Data.Time.Calendar.WeekDate
import Data.Time.Calendar.OrdinalDate
+import Data.Time.Format ()
import Data.Tuple.Utils
import Data.Char
import Control.Applicative