From nobody Tue Jun 10 09:33:22 2025 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4bGk9t3LC2z5tX9R; Tue, 10 Jun 2025 09:33:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4bGk9t2bS8z3NPP; Tue, 10 Jun 2025 09:33:22 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749548002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EyB1F0QhmupGHaaobmIkYy/vqD0ID5glXnB6289mtHI=; b=g3IqGoEoxYkAT5ft96xQERkkq4qjOcf1YnK/8EmzRqj3JRBDAcVu5QinvvrmB9MEnKZllR YuhWjoKnw1geLHGvclgQb8XlZtyT22wrcKKC5EyGZegTnZgxl/zH59ppvbXSNEWtCW5nYy 1uHse061keX0dH19GwcWFgWdH+9Z8HzmSgD96865PfoJayXR9bsZbdB4XHHnTEQESBgiLD WkFiOFlf73Sv8NsySgEdISf02cRHvSiPg9DeicHAFhWdgMnb+DD9v1nvpy2uoxCUvk2sE1 uANlW5T+nPqRQjfUFv3Tq4rx4+FwVkbreMFbzafKBl2z5d7OajwqRQBPbMEv8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1749548002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=EyB1F0QhmupGHaaobmIkYy/vqD0ID5glXnB6289mtHI=; b=Cg7OYwt5K1Tn1D5KoWlG4ffdRHdUgsFOVb+dGhdCPdAhHNmoT7x8skm9pJwtN/+eP5W+bB UMVQfPjzG045Ey5zqk5NYeLw3W+7C11SB1lTUC53eN1iNMU2mlUFgWHoX7ECtht62EoTcD Ed7p0Iqbqm3OwTQzPlAmQlr5I6ZwLzCxHvINRPByF1JeJa0lsS8CkyDrCsvUL2lY+WrKKm nXiVyDR93QVB5P5bYafEv2JMrrQ9Lr+ztnCFHbGy3y94aycBy7mfDWU8oYskznVdKL5zsE K0d3R58bkZ+vZwYsTjSdpErlXytaazgD4XX1QzbvJ9yn5ChlcLP44WjxxZBW/A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1749548002; a=rsa-sha256; cv=none; b=GEu8Dn7FjygCdQd4uvN2iGuJVv6+G/8O7ta9BFv1rw3v6jOFIel30JI42/m8I+O9PwQ6LD x6dHKV+neKO34xuOKOIS8taRnyc/iosTtj8gXoO8/eED83NW/GRcPHyA1/UuGbvEYZ98m3 RklHJSuyWEWUNbHA4vq7EmFvbksBJVIBsNxHfMiRyNKMWt2MeOu3Tqm7fd7Dl1e/15RNmC oB6UBDbiYBJT2yQojU+lG70Xj5MAatPVPSeUoZsRskVu+PKeDM5kmeW8E6KGDZ7uftrlyX 2K1ewVl5/cFVVAaKDFan1VVqcZXfr8UEHqRzIz/ZyDbo64rknXvc6+IlrR0XlA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4bGk9t1w3czbyB; Tue, 10 Jun 2025 09:33:22 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 55A9XMjQ099024; Tue, 10 Jun 2025 09:33:22 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 55A9XMaW099021; Tue, 10 Jun 2025 09:33:22 GMT (envelope-from git) Date: Tue, 10 Jun 2025 09:33:22 GMT Message-Id: <202506100933.55A9XMaW099021@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Baptiste Daroussin Subject: git: 8feca60d6ee9 - main - nuageinit: runcmd should also be executed late List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8feca60d6ee983ef3c81903675b4d9c3218c7e7a Auto-Submitted: auto-generated The branch main has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=8feca60d6ee983ef3c81903675b4d9c3218c7e7a commit 8feca60d6ee983ef3c81903675b4d9c3218c7e7a Author: Baptiste Daroussin AuthorDate: 2025-06-10 09:28:49 +0000 Commit: Baptiste Daroussin CommitDate: 2025-06-10 09:28:49 +0000 nuageinit: runcmd should also be executed late Execute the runcmd specified in cloudinit at the same moment as the user_data script aka late in the boot process, to respect cloudinit specifications --- libexec/nuageinit/nuageinit | 13 ++++++++++--- libexec/nuageinit/tests/nuageinit.sh | 12 +++++++----- libexec/rc/rc.d/nuageinit_user_data_script | 4 ++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/libexec/nuageinit/nuageinit b/libexec/nuageinit/nuageinit index f2f15f0d36f0..cd5912c54975 100755 --- a/libexec/nuageinit/nuageinit +++ b/libexec/nuageinit/nuageinit @@ -379,11 +379,18 @@ if line == "#cloud-config" then nuage.chpasswd(obj.chpasswd) end if obj.runcmd then + f = nil for _, c in ipairs(obj.runcmd) do - if not os.execute(c) then - nuage.warn("Failed to execute '" .. c .. "'") - -- execute the next command anyway -- + if f == nil then + nuage.mkdir_p(root .. "/var/cache/nuageinit") + f = assert(io.open(root .. "/var/cache/nuageinit/runcmds", "w")) + f:write("#!/bin/sh\n") end + f:write(c .. "\n") + end + if f ~= nil then + f:close() + sys_stat.chmod(root .. "/var/cache/nuageinit/runcmds", 493) end end if obj.packages then diff --git a/libexec/nuageinit/tests/nuageinit.sh b/libexec/nuageinit/tests/nuageinit.sh index be8b186d933b..3d0033a648de 100644 --- a/libexec/nuageinit/tests/nuageinit.sh +++ b/libexec/nuageinit/tests/nuageinit.sh @@ -728,18 +728,20 @@ runcmd: - plop EOF chmod 755 "${PWD}"/media/nuageinit/user_data - atf_check -s exit:0 -e inline:"sh: plop: not found\nnuageinit: Failed to execute 'plop'\n" /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 + atf_check -s exit:0 /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 + test -f var/cache/nuageinit/runcmds || atf_fail "File not created" + test -x var/cache/nuageinit/runcmds || atf_fail "Missing execution permission" + atf_check -o inline:"#!/bin/sh\nplop\n" cat var/cache/nuageinit/runcmds cat > media/nuageinit/user_data << 'EOF' #cloud-config runcmd: - - echo "yeah!" > "${PWD}"/media/nuageinit/runcmd_echo - - uname -s > "${PWD}"/media/nuageinit/runcmd_uname + - echo "yeah!" + - uname -s EOF chmod 755 "${PWD}"/media/nuageinit/user_data atf_check /usr/libexec/nuageinit "${PWD}"/media/nuageinit config-2 - atf_check -s exit:0 -o inline:"yeah!\n" cat "${PWD}"/media/nuageinit/runcmd_echo - atf_check -s exit:0 -o inline:"FreeBSD\n" cat "${PWD}"/media/nuageinit/runcmd_uname + atf_check -o inline:"#!/bin/sh\necho \"yeah!\"\nuname -s\n" cat var/cache/nuageinit/runcmds } config2_userdata_packages_head() diff --git a/libexec/rc/rc.d/nuageinit_user_data_script b/libexec/rc/rc.d/nuageinit_user_data_script index 94d5d008a7fc..97ccc45f8658 100755 --- a/libexec/rc/rc.d/nuageinit_user_data_script +++ b/libexec/rc/rc.d/nuageinit_user_data_script @@ -15,6 +15,10 @@ rcvar="nuageinit_enable" execute_user_data_script() { + if [ -x /var/cache/nuageinit/runcmds ]; then + echo "Executing 'runcmd'" | tee -e /var/log/nuageinit.log + /var/cache/nuageinit/runcmds 2>&1 | tee -a /var/log/nuageinit.log + fi test -x /var/cache/nuageinit/user_data || return echo "Executing user_data script" | tee -a /var/log/nuageinnit.log /var/cache/nuageinit/user_data 2>&1 | tee -a /var/log/nuageinit.log