just-containers / s6-overlay

s6 overlay for containers (includes execline, s6-linux-utils & a custom init)
Other
3.69k stars 208 forks source link

s6-rc-compile: undefined service name base #516

Closed geeky-akshay closed 1 year ago

geeky-akshay commented 1 year ago

My services are declared in directory /etc/s6-overlay/s6-rc.d s6-overlay/ └── s6-rc.d ├── httpd │   ├── dependencies.d │   │   └── base │   ├── run │   └── type ├── user │   ├── contents.d │   │   └── httpd │   └── type └── user2 ├── contents.d └── type

I added a new service XYZ to the /etc/s6-overlay/s6-rc.d directory s6-overlay/ └── s6-rc.d ├── httpd │   ├── dependencies.d │   │   └── base │   ├── run │   └── type ├── user │   ├── contents.d │   │   └── httpd │   └── type ├── user2 │   ├── contents.d │   └── type └── XYZ ├── run └── type

Now, I want to add the service XYZ to the live database. For that, I'm trying to compile a new database using s6-rc-compile program. But, It is giving me error "undefined service name base"

s6-rc-compile -v3 /etc/s6-rc/compiled-$(date +%s) /etc/s6-overlay/s6-rc.d s6-rc-compile: info: parsing /etc/s6-overlay/s6-rc.d/XYZ s6-rc-compile: info: XYZ has type longrun s6-rc-compile: info: parsing /etc/s6-overlay/s6-rc.d/httpd s6-rc-compile: info: httpd has type longrun s6-rc-compile: info: parsing /etc/s6-overlay/s6-rc.d/user s6-rc-compile: info: user has type bundle s6-rc-compile: info: parsing /etc/s6-overlay/s6-rc.d/user2 s6-rc-compile: info: user2 has type bundle s6-rc-compile: info: making bundles for pipelines s6-rc-compile: info: resolving bundle names s6-rc-compile: info: converting bundle array s6-rc-compile: info: resolving service names s6-rc-compile: fatal: during dependency resolution for service httpd: undefined service name base

Any solution for this ?

skarnet commented 1 year ago

You don't need to run s6-rc-compile yourself, it will automatically be done for you when the container boots. :-)

If you're curious: this happens here, and the answer to your question is that base is defined in the /package/admin/s6-overlay/etc/s6-rc/sources directory, which is added to the list of sources used by s6-rc-compile.

Don't forget to add an XYZ file in /etc/s6-overlay/s6-rc.d/user/contents.d if you want XYZ to automatically be started, and you'll be fine. Just edit your sources!

geeky-akshay commented 1 year ago

The reason I'm running s6-rc-compile is that I want to add service XYZ after the container is started. What will be the best way to do it ? One way is, compile the database (which I'm doing) and then update the live database using s6-rc-update command.

Yes, base is defined in /package/admin/s6-overlay/etc/s6-rc/sources

geeky-akshay commented 1 year ago

Do I need to do s6-rc-compile /etc/s6-rc/compiled-$(date +%s) /etc/s6-overlay/s6-rc.d /package/admin/s6-overlay/etc/s6-rc/sources ? It doesn't give the error after executing above command.

skarnet commented 1 year ago

s6-overlay isn't very well suited to that level of dynamism. The point of s6 is to have a reproducible setup that is guaranteed to boot every time and give you the same functionality; changing stuff dynamically defeats that.

So the real safety-and-reliability-freak answer is: please re-examine your whole design and see if you can't organize your services differently, so that you don't need to add services after booting the container.

Now, if that's not possible: given how s6-rc works, updating your sources, compiling a new database, then running s6-rc-update is the technically correct way to achieve what you want, and if you can make it work that way, more power to you. You're a power user, welcome; but these aren't the kind of solutions I want to advertise in a GitHub issue because they certainly won't be available to everyone.

The "somewhat approved" method in s6-overlay for changing your service set after a container is started is the S6_STAGE2_HOOK variable, that you can set to a script that will modify your source database - the script will be run early, before the s6-rc-compile invocation. So you don't need to fiddle with compiled databases, just edit your source once and then you're set.