Skip to content

updated perls#3

Open
necrose99 wants to merge 5 commits intogoose121:masterfrom
Necrohol:master
Open

updated perls#3
necrose99 wants to merge 5 commits intogoose121:masterfrom
Necrohol:master

Conversation

@necrose99
Copy link
Copy Markdown

No description provided.

--- initify/cronify.pl
+++ patched/cronify.pl
@@ -10,13 +10,13 @@
 	if ($1 =~ /^(hourly|daily|monthly|yearly)$/) {
 	    # Use cron's special strings for better readability
-	    @timestamp = ('@' . "$1");
+	    @timestamp = ("\@" . "$1");
 	} elsif ($1 =~ /minutely/) {
 	    @timestamp = ("*", "*", "*", "*", "*");
 	} elsif ($1 =~ /weekly/) {
-	    # Systemd does weekly on Mondays, but cron
-	    # does it on Sundays. We don't want unexpected
-	    # behaviour, so we force cron to do it on Mondays
-	    @timestamp = ("0", "0", "*", "*", "Mon");
+	    # Standardize to Cron numeric DOW (1 = Monday)
+	    @timestamp = ("0", "0", "*", "*", "1");
 	} elsif ($1 =~ /quarterly/) {
 	    @timestamp = ("0", "0", "1,4,7,10", "1", "*");
@@ -40,19 +40,20 @@
 		foreach $day (split /,/, $days) {
 		    $day =~ m/(${dotw})(?:\.\.(${dotw}))?/;
-		    print $2, "\n";
-		    push @ts_dotw, (($1 == $2) ? "$1" : "$1-$2");
+		    # Fix: Store captures immediately to prevent loop overwrite
+		    my $start = $1; my $end = $2;
+		    push @ts_dotw, (defined($end) ? "$start-$end" : "$start");
 		}
 	    }
 	    
-	    $timestamp[4] = join ",", @ts_dotw;
+	    $timestamp[4] = join(",", @ts_dotw);
 	    
 	    $date = shift @sysd_date;
-	    $date =~ m/([0-9]{4}|\*)-([0-9]{1,2}|\*)-([0-9]{1,2}|\*)/;
-	    if($1 != "*") {
+	    if($date =~ m/^([0-9]{4}|\*)-([0-9]{1,2}|\*)-([0-9]{1,2}|\*)$/) {
+	        if($1 ne "*") {
 		    print STDERR "Warning: Ignoring non-'*' year field in timer\n";
-	    }
-	    $date =~ m/^([0-9]{4}|\*)-([0-9]{1,2}|\*)-([0-9]{1,2}|\*)$/;
-	    $timestamp[2] = $2;
-	    $timestamp[3] = $3;
+	        }
+	        $timestamp[3] = $2; # Month
+	        $timestamp[2] = $3; # Day of Month
+	    }
 
 	    $time = shift @sysd_date;
-	    $time =~ m/^([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?$/;
-	    if(int($3)) {
+	    if($time =~ m/^([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?$/) {
+	        if(defined($3) && int($3)) {
 		    print STDERR "Warning: Ignoring non-zero seconds field in timer\n";
-	    }
-	    $time =~ m/^([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?$/;
-	    $timestamp[0] = $1;
-	    $timestamp[1] = $2;
+	        }
+	        # CRITICAL FIX: Cron is Minute(0) Hour(1)
+	        $timestamp[0] = $2; # Minute
+	        $timestamp[1] = $1; # Hour
+	    }
 	}
 	push @timestamps, \@timestamp;
--- initify.pl
+++ initify.pl
@@ -65,22 +65,39 @@
     }
 }
 
-my @cmds;
-
 my @cmd_path;
 my @cmd_argl;
 
-map {my @sep = split(/ /, $_, 2);
+foreach (@cmds_start) {
+     my @sep = split(/ /, $_, 2);
      push(@cmd_path, $sep[0]);
-     push(@cmd_argl, $sep[1]);
-} @cmds_start;
+     push(@cmd_argl, $sep[1] // "");
+}
+
+# --- NEW PATCH LOGIC START ---
+
+# 1. Handle Systemd placeholders (%i, %I) for OpenRC sub-services
+# This allows /etc/init.d/openvpn.home to use 'home' as the config name
+foreach (@cmd_argl) { s/%[iI]/\${RC_SVCNAME#*.}/g; }
+$pidfile =~ s/%[iI]/\${RC_SVCNAME#*.}/g;
+
+# 2. Determine OpenRC Supervisor requirements
+my $ssd_opts = "";
+if (lc($type) eq "simple") {
+    # OpenRC needs to force backgrounding for 'simple' types
+    $ssd_opts = "--background --make-pidfile";
+    $pidfile = "/run/\${RC_SVCNAME}.pid" unless $pidfile;
+}
+
+# --- NEW PATCH LOGIC END ---
 
 open(FH, '>', "$service") || die("Cannot create $service: $!\n");
 
 print FH <<"EOF";
 #!/sbin/openrc-run
 
-command=$cmd_path[0]
-command_args="$cmd_argl[0]"
-pidfile=$pidfile
+name="\$RC_SVCNAME"
+description="$desc"
+
+command="$cmd_path[0]"
+command_args="$cmd_argl[0] $ssd_opts"
+pidfile="$pidfile"
 
-name="$svc_name"
-description="$desc"
+depend() {
+    after net
+}
 EOF
@necrose99
Copy link
Copy Markdown
Author

necrose99 commented Mar 27, 2026

--- initify/cronify.pl
+++ patched/cronify.pl
@@ -10,13 +10,13 @@
 	if ($1 =~ /^(hourly|daily|monthly|yearly)$/) {
 	    # Use cron's special strings for better readability
-	    @timestamp = ('@' . "$1");
+	    @timestamp = ("\@" . "$1");
 	} elsif ($1 =~ /minutely/) {
 	    @timestamp = ("*", "*", "*", "*", "*");
 	} elsif ($1 =~ /weekly/) {
-	    # Systemd does weekly on Mondays, but cron
-	    # does it on Sundays. We don't want unexpected
-	    # behaviour, so we force cron to do it on Mondays
-	    @timestamp = ("0", "0", "*", "*", "Mon");
+	    # Standardize to Cron numeric DOW (1 = Monday)
+	    @timestamp = ("0", "0", "*", "*", "1");
 	} elsif ($1 =~ /quarterly/) {
 	    @timestamp = ("0", "0", "1,4,7,10", "1", "*");
@@ -40,19 +40,20 @@
 		foreach $day (split /,/, $days) {
 		    $day =~ m/(${dotw})(?:\.\.(${dotw}))?/;
-		    print $2, "\n";
-		    push @ts_dotw, (($1 == $2) ? "$1" : "$1-$2");
+		    # Fix: Store captures immediately to prevent loop overwrite
+		    my $start = $1; my $end = $2;
+		    push @ts_dotw, (defined($end) ? "$start-$end" : "$start");
 		}
 	    }
 	    
-	    $timestamp[4] = join ",", @ts_dotw;
+	    $timestamp[4] = join(",", @ts_dotw);
 	    
 	    $date = shift @sysd_date;
-	    $date =~ m/([0-9]{4}|\*)-([0-9]{1,2}|\*)-([0-9]{1,2}|\*)/;
-	    if($1 != "*") {
+	    if($date =~ m/^([0-9]{4}|\*)-([0-9]{1,2}|\*)-([0-9]{1,2}|\*)$/) {
+	        if($1 ne "*") {
 		    print STDERR "Warning: Ignoring non-'*' year field in timer\n";
-	    }
-	    $date =~ m/^([0-9]{4}|\*)-([0-9]{1,2}|\*)-([0-9]{1,2}|\*)$/;
-	    $timestamp[2] = $2;
-	    $timestamp[3] = $3;
+	        }
+	        $timestamp[3] = $2; # Month
+	        $timestamp[2] = $3; # Day of Month
+	    }
 
 	    $time = shift @sysd_date;
-	    $time =~ m/^([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?$/;
-	    if(int($3)) {
+	    if($time =~ m/^([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?$/) {
+	        if(defined($3) && int($3)) {
 		    print STDERR "Warning: Ignoring non-zero seconds field in timer\n";
-	    }
-	    $time =~ m/^([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?$/;
-	    $timestamp[0] = $1;
-	    $timestamp[1] = $2;
+	        }
+	        # CRITICAL FIX: Cron is Minute(0) Hour(1)
+	        $timestamp[0] = $2; # Minute
+	        $timestamp[1] = $1; # Hour
+	    }
 	}
 	push @timestamps, \@timestamp;

@goose121
Copy link
Copy Markdown
Owner

hi! I appreciate the pull request, but it seems like there's a lot going on here; could you please explain the changes you're proposing, and maybe group your changes into logical chunks by commit rather than whole files if you know how? (e.g. "updated style", "fixed date handling", etc.)

@necrose99
Copy link
Copy Markdown
Author

Updated chonify

So its less hit or miss..

Added n worked a QuadLet ie
Podlet podman... systemd podman-docker Compose equivalent...

But via systemd container units... wich basically pulls newest containers from docker hub etc...
And runs the container as a service... ie run
Gps enabled chrony
dduncandocker/gps-chrony on homeassistant
And as a QuadLet via podman-docker, you can have it start soon after boot...

Quadlet .container in openrc equivalent out...

Wrapper incude/source... intify chronify as main logic... via Quadlet openrc.pl

Gentoo openrc cgroups wiki refranced... for further tweaking...

@necrose99
Copy link
Copy Markdown
Author

necrose99 commented Mar 27, 2026

Added background for daemon pidfile etc...
if daemon Types of units add the background bits to the openrc script/s as a use case...

To inityfy ...

`[Service]
Type=forking
ExecStart=/path/to/your/daemon -P /run/yourdaemon.pid
PIDFile=/run/yourdaemon.pid

command="/usr/bin/my_app"
command_background="true"
pidfile="/run/${RC_SVCNAME}.pid"

one-shot task (like systemd Type=simple but not persistent)

command_background=false could likely be added also...
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants