Conversation
--- 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
|
|
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.) |
|
Updated chonify So its less hit or miss.. Added n worked a QuadLet ie But via systemd container units... wich basically pulls newest containers from docker hub etc... 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... |
|
Added background for daemon pidfile etc... To inityfy ... `[Service] command="/usr/bin/my_app" one-shot task (like systemd Type=simple but not persistent)command_background=false could likely be added also... |
No description provided.