2 Commity c244cd67d8 ... 9137769ede

Autor SHA1 Wiadomość Data
  Lukas Angerer 9137769ede Default configuration update 1 rok temu
  Lukas Angerer 6338395691 Scripts and service units for autostarting CronAlarm 1 rok temu

+ 16 - 0
data/settings.json

@@ -8,10 +8,18 @@
       {
         "Name": "Weekdays",
         "Options": [
+          {
+            "Label": "06:15 - New Work",
+	    "Pattern": "15 06 * * MON-FRI"
+	  },
           {
             "Label": "06:20 - Work",
             "Pattern": "20 06 * * MON-FRI"
           },
+          {
+            "Label": "08:00 - Holidays (early)",
+            "Pattern": "00 08 * * MON-FRI"
+          },
           {
             "Label": "08:30 - Holidays",
             "Pattern": "30 08 * * MON-FRI"
@@ -25,6 +33,10 @@
       {
         "Name": "Saturday",
         "Options": [
+          {
+            "Label": "09:00 - Sleeping In",
+            "Pattern": "00 09 * * SAT"
+          },
           {
             "Label": "08:20 - Long-Jog",
             "Pattern": "20 08 * * SAT"
@@ -42,6 +54,10 @@
       {
         "Name": "Sunday",
         "Options": [
+          {
+            "Label": "08:30 - Swimming",
+            "Pattern": "30 08 * * SUN"
+          },
           {
             "Label": "09:00 - Lazy",
             "Pattern": "00 09 * * SUN"

+ 5 - 0
scripts/cron-api.py

@@ -1,6 +1,7 @@
 #!/usr/bin/python3
 
 import os
+import subprocess
 from flask import Flask, Response, json, request
 from cron.Parser import Parser
 
@@ -25,4 +26,8 @@ def set_section(name):
     return Response(cronFile.get_section(name), mimetype="text/plain")
 
 if __name__ == "__main__":
+    print("Running as user:")
+    subprocess.run("whoami")
+    print("Checking crontab access with 'crontab -l'")
+    print(subprocess.run(["crontab", "-l"], capture_output = True, text = True).stdout.count('\n'))
     api.run(host = "0.0.0.0", port = 5000)

+ 22 - 0
scripts/mopidy-init.sh

@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# enable Job Control
+set -m
+
+mopidy -q &
+
+until mpc version
+do
+	echo "waiting for mopidy to become available..."
+	sleep 1
+done
+
+mpc load JM
+mpc playlist
+mpc random on
+mpc next
+mpc current
+
+# get mopidy to the foreground
+fg
+

+ 24 - 0
service-units/cron-alarm.service

@@ -0,0 +1,24 @@
+[Unit]
+Description=CronAlarm Web UI
+# user services CANNOT reference system services
+#Requires=docker.service
+#After=docker.service
+
+[Service]
+Restart=always
+# Shutdown container (if running) when unit is stopped
+ExecStartPre=/usr/bin/docker compose -f %h/projects/CronAlarm/docker-compose.yml down -v
+# Start container when unit is started
+ExecStart=/usr/bin/docker compose -f %h/projects/CronAlarm/docker-compose.yml up
+# Stop container when unit is stopped
+ExecStop=/usr/bin/docker compose -f %h/projects/CronAlarm/docker-compose.yml down -v
+
+# Hardening
+ProtectSystem=full
+PrivateTmp=true
+SystemCallArchitectures=native
+MemoryDenyWriteExecute=true
+NoNewPrivileges=true
+
+[Install]
+WantedBy=default.target

+ 14 - 0
service-units/cron-api.service

@@ -0,0 +1,14 @@
+[Unit]
+Description=CronAlarm Host API
+
+[Service]
+Type=simple
+Restart=always
+ExecStart= %h/projects/CronAlarm/scripts/cron-api.py
+
+# Hardening
+#MemoryDenyWriteExecute=true
+#NoNewPrivileges=true
+
+[Install]
+WantedBy=default.target

+ 12 - 0
service-units/mopidy.service

@@ -0,0 +1,12 @@
+[Unit]
+Description=Mopidy Server
+
+[Service]
+Type=simple
+Restart=always
+ExecStart= %h/projects/CronAlarm/scripts/mopidy-init.sh
+
+# No hardening since Mopidy has to load plugins and such
+
+[Install]
+WantedBy=default.target