diff --git a/README.md b/README.md index 66cda97..74610d0 100644 --- a/README.md +++ b/README.md @@ -71,4 +71,4 @@ This will set up an environment with: ## Contributing -Feel free to fork this repository and make your own changes. If you have any improvements or suggestions, please open an issue or submit a pull request. \ No newline at end of file +Feel free to fork this repository and make your own changes. If you have any improvements or suggestions, please open an issue or submit a pull request. diff --git a/hosts/tilo/configuration.nix b/hosts/tilo/configuration.nix index 6e4a455..531b04a 100644 --- a/hosts/tilo/configuration.nix +++ b/hosts/tilo/configuration.nix @@ -14,6 +14,7 @@ ../../modules/ssh.nix ../../modules/endlessh.nix ../../programs/nano.nix + ./services ]; system = { diff --git a/hosts/tilo/services/default.nix b/hosts/tilo/services/default.nix new file mode 100644 index 0000000..7be23ca --- /dev/null +++ b/hosts/tilo/services/default.nix @@ -0,0 +1,3 @@ +{ + imports = [./nextcloud-cron.nix]; +} diff --git a/hosts/tilo/services/nextcloud-cron.nix b/hosts/tilo/services/nextcloud-cron.nix new file mode 100644 index 0000000..a516701 --- /dev/null +++ b/hosts/tilo/services/nextcloud-cron.nix @@ -0,0 +1,33 @@ +{pkgs, ...}: { + systemd = { + timers."nextcloud-cron" = { + wantedBy = ["timers.target"]; + timerConfig = { + OnBootSec = "20m"; + OnUnitActiveSec = "20m"; + Unit = "nextcloud-cron.service"; + }; + }; + services."nextcloud-cron" = { + script = '' + CONTAINER_NAME="nextcloud-nextcloud-1" + + is_container_running() { + ${pkgs.docker}/bin/docker inspect -f '{{.State.Running}}' "$CONTAINER_NAME" 2>/dev/null | grep -q "true" + } + + while ! is_container_running; do + echo "Waiting for $CONTAINER_NAME to start..." + sleep 10 + done + + echo "$CONTAINER_NAME is running. Executing CRON job..." + ${pkgs.docker}/bin/docker exec -u www-data -it nextcloud-nextcloud-1 php /var/www/html/cron.php + ''; + serviceConfig = { + Type = "oneshot"; + User = "root"; + }; + }; + }; +}