From c43322d19a97c1617a00866f195454622a3d635e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mina=20Gali=C4=87?= Date: Fri, 8 Dec 2023 19:23:30 +0000 Subject: [PATCH] hack(sysvinit): On *BSD, create /run as symlink On *BSD, `/run` is not ephemeral, but the way cloud-init behaves, it expects it to be. This is hack is partial fix for GH-4180 / GH-4231. But to be good Unix citizens, we should still make /run relocatable in the code and in the installer. Sponsored by: The FreeBSD Foundation Fixes GH-4180 Fixes GH-4231 --- sysvinit/freebsd/cloudinitlocal.tmpl | 9 +++++++++ sysvinit/freebsd/dsidentify.tmpl | 9 +++++++++ sysvinit/netbsd/cloudinitlocal.tmpl | 10 ++++++++++ sysvinit/netbsd/dsidentify.tmpl | 10 ++++++++++ sysvinit/openbsd/cloudinitlocal.tmpl | 7 +++++++ tools/build-on-openbsd | 5 +++++ 6 files changed, 50 insertions(+) diff --git a/sysvinit/freebsd/cloudinitlocal.tmpl b/sysvinit/freebsd/cloudinitlocal.tmpl index ec9b1fb8b824..3eb017172c1d 100755 --- a/sysvinit/freebsd/cloudinitlocal.tmpl +++ b/sysvinit/freebsd/cloudinitlocal.tmpl @@ -15,10 +15,19 @@ PATH="{{ prefix }}/sbin:{{ prefix }}/bin:/usr/sbin:/usr/bin:/sbin:/bin" name="cloudinitlocal" command="{{prefix}}/bin/cloud-init" +start_precmd="cloudlocal_precmd" start_cmd="cloudlocal_start" stop_cmd=":" rcvar="cloudinit_enable" +cloudlocal_precmd() +{ + if ! test -L /run ; then + rm -rf /run + ln -s /var/run /run + fi +} + cloudlocal_start() { echo -n "${command} starting" diff --git a/sysvinit/freebsd/dsidentify.tmpl b/sysvinit/freebsd/dsidentify.tmpl index d18e0042d68d..da4166329152 100755 --- a/sysvinit/freebsd/dsidentify.tmpl +++ b/sysvinit/freebsd/dsidentify.tmpl @@ -17,10 +17,19 @@ PATH="{{ prefix }}/sbin:{{ prefix }}/bin:/usr/sbin:/usr/bin:/sbin:/bin" name="dsidentify" command="{{ prefix }}/lib/cloud-init/ds-identify" +start_precmd="dsidentify_precmd" start_cmd="dsidentify_start" stop_cmd=":" rcvar="cloudinit_enable" +dsidentify_precmd() +{ + if ! test -L /run ; then + rm -rf /run + ln -s /var/run /run + fi +} + dsidentify_start() { if checkyesno cloudinit_dsidentify_enable; then diff --git a/sysvinit/netbsd/cloudinitlocal.tmpl b/sysvinit/netbsd/cloudinitlocal.tmpl index ba840ab4bd8b..bb20c6b4ad9f 100755 --- a/sysvinit/netbsd/cloudinitlocal.tmpl +++ b/sysvinit/netbsd/cloudinitlocal.tmpl @@ -13,7 +13,17 @@ That makes it easy for image builders to create images without ``dsidentify``. $_rc_subr_loaded . /etc/rc.subr name="cloudinitlocal" +start_precmd="cloud_init_local_precmd" start_cmd="start_cloud_init_local" + +cloud_init_local_precmd() +{ + if ! test -L /run ; then + rm -rf /run + ln -s /var/run /run + fi +} + start_cloud_init_local() { test -e {{prefix}}/etc/cloud/cloud-init.disabled \ diff --git a/sysvinit/netbsd/dsidentify.tmpl b/sysvinit/netbsd/dsidentify.tmpl index 4ce7e067ee1c..fbdb88ac91f3 100755 --- a/sysvinit/netbsd/dsidentify.tmpl +++ b/sysvinit/netbsd/dsidentify.tmpl @@ -8,7 +8,17 @@ $_rc_subr_loaded . /etc/rc.subr name="dsidentify" +start_precmd="dsidentify_precmd" start_cmd="start_dsidentify" + +dsidentify_precmd() +{ + if ! test -L /run ; then + rm -rf /run + ln -s /var/run /run + fi +} + start_dsidentify() { test -e {{prefix}}/etc/cloud/cloud-init.disabled \ diff --git a/sysvinit/openbsd/cloudinitlocal.tmpl b/sysvinit/openbsd/cloudinitlocal.tmpl index c58eb97561f6..bf294ec8c9a4 100755 --- a/sysvinit/openbsd/cloudinitlocal.tmpl +++ b/sysvinit/openbsd/cloudinitlocal.tmpl @@ -17,6 +17,13 @@ daemon_user=root rc_bg="YES" # (undefined or "YES") rc_usercheck="YES" +rc_pre() { + if ! test -L /run ; then + rm -rf /run + ln -s /var/run /run + fi +} + rc_start() { if test -e /etc/cloud/cloud-init.disabled; then echo -n "cloud-init is disabled via cloud-init.disabled file." | logger -t ${daemon} diff --git a/tools/build-on-openbsd b/tools/build-on-openbsd index 611353da3ec5..7bbbac7fd607 100755 --- a/tools/build-on-openbsd +++ b/tools/build-on-openbsd @@ -44,6 +44,11 @@ else RC_LOCAL="/etc/rc.local" RC_LOCAL_CONTENT=" +if ! test -L /run ; then + rm -rf /run + ln -s /var/run /run +fi + /usr/lib/cloud-init/ds-identify cloud-init init --local