Setting rcorder to *optionally* require something?

Today I ran into an issue upon booting, where a service (step-ca, of security/step-certificates) failed, saying that it could not connect to mysql. Manually starting it after boot time worked fine. I guessed that it was trying to start up before mysql had, and rcorder seemed to confirm this (listing it earlier than mysql-server).

I guess that to fix it for my machine, at least until the next update of the port, I could just add REQUIRE: mysql to /usr/local/etc/rc.d/step-ca. But I don't know how to fix it permanently for my machine (e.g. is there some other place I can put that require, where it won't get thrown away the next time the port is updated), and I also don't understand how -- or even if -- it should be "really" fixed (i.e. not just for my machine):

The complication with the latter is that you don't need mysql to run step-ca. It's just something that you can configure it to use. I have so configured it, but not everybody would. And to be clear, "you can configure it" here means that there are runtime options you can set via the program's standard configuration -- not anything OS-specific like a FreeBSD ports system build option (security/step-certificates doesn't have any options at all).

I've been looking at stuff like man rcorder, and although I easily could have missed it, I've yet to find anything explaining how to deal with possibilities like this.
 
Two things:

(1) I tried adding mysql to the requirements in /usr/local/etc/rc.d/step-ca, and it worked fine (both from the point of view of rcorder and from that of actually starting up at boot time).

(2) It occurred to me (though I haven't tried this yet) that I could instead make my own entirely new file in /usr/local/etc/rc.d that more or less just contains REQUIRE: mysql and BEFORE: step-ca, and is otherwise no-op. Presumably that would solve the issue of being overwritten the next time the port is updated. But even if this would work, it still leaves questions: Is this the (or a) "right" way to fix it for my machine specifically? Is there a better way? And how to fix it for everyone, not just me, and not just people who actually do use mysql for step-ca?
 
I don't have neither databases/mysql80-server (current default of MySQL server) nor security/step-certificates, so this is just a wild guess reading security/step-certificates/files/step-ca.in and databases/mysql80-server/files/mysql-server.in.

databases/mysql80-server/files/mysql-server.in has
sh:
# PROVIDE: mysql
# REQUIRE: LOGIN
# KEYWORD: shutdown
and security/step-certificates/files/step-ca.in has
sh:
# PROVIDE: step-ca
# REQUIRE: LOGIN networking
# KEYWORD: shutdown

networking here should be uppercase NETWORKING, but LOGIN requires DAEMON and DAEMON requires NETWORKING and SERVERS. So networking/NETWORKING woudn't be needed. But putting this aside for now.

There are no dependency (at least for direct dependency) between the 2 ports, and both has the same priorities for rcorder (as actual REQUIRE is LOGIN for both ports). So the startup order is not assured.
If anyone want to constraint the order, a dummy rc.d script would be needed as you already pointed out.
 
I just tried my "entirely new file in /usr/local/etc/rc.d" idea, and it works. So, for the benefit of anyone who happens upon this thread in the future, the following file does the trick, and shouldn't suffer from the "overwritten when the port gets updated" problem:
Code:
#!/bin/sh

# PROVIDE: step-ca-require-mysql
# REQUIRE: mysql
# BEFORE: step-ca

. /etc/rc.subr

name="step_ca_require_mysql"

start_cmd="${name}_start"
stop_cmd=":"

load_rc_config "${name}"

step_ca_require_mysql_start()
{
   echo "Ensuring MySQL comes before Step CA in rcorder"
}

run_rc_command "$1"
I'm still interested in whether or not this (or something basically like this) really is the way to handle such situations, since it's essentially an "everyone for themselves" solution, as opposed to what I would think of as a "real" solution (i.e. automatically handled via the ports system with no manual intervention necessary, other than perhaps setting a flag in an rc script or whatever). In the meantime, though, I figured I should publish this "good enough for now" solution in case it might help someone.
 
(2) It occurred to me (though I haven't tried this yet) that I could instead make my own entirely new file in /usr/local/etc/rc.d that more or less just contains REQUIRE: mysql and BEFORE: step-ca, and is otherwise no-op. Presumably that would solve the issue of being overwritten the next time the port is updated. But even if this would work, it still leaves questions: Is this the (or a) "right" way to fix it for my machine specifically? Is there a better way? And how to fix it for everyone, not just me, and not just people who actually do use mysql for step-ca?
This is the way I am doing it. I have decided it is the right way - only I do not put these into /usr/local/etc (leave that for the ports), but have created another, third place for all site-local installations.

A genuine way to do it conditionally (only where needed) is vastly more difficult, and may not even be desireable (too much A.I.)
The practical approach is rather to have a kind of hierarchy: some things are useful for a majority of people, and go via PR/change-request. Other things depend on local (site-wide) conventions (like the decision to use mysql), and yet again other things are specific to a certain machine.
In productive environments it is normal that the site and the machine both need some amount of individual configuration to be most fit for their tasks. On single personal machines it tends to get a bit more chaotic, because one is not forced to document what was locally configured and why.
 
I'm still interested in whether or not this (or something basically like this) really is the way to handle such situations, since it's essentially an "everyone for themselves" solution, as opposed to what I would think of as a "real" solution (i.e. automatically handled via the ports system with no manual intervention necessary, other than perhaps setting a flag in an rc script or whatever).
According to your first post, /usr/local/etc/rc.d/step-ca (installed from security/step-certificates/files/step-ca.in) should require mysql, if the only supported database server is mysql. In this case, your first probosal (fixing security/step-certificates/files/step-ca.in) should be the only way to go.

But if security/step-certificates actually supports multiple database servers such as postgresql, mariady and so on to be chosen, option'ify or flavorize the port and install one script as of the selection (like step-ca-mysql, step-ca-pgsql and so on) would be needed.
 
Back
Top