• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Feature request: option to run a software item only after the host has been renamed and joined to the domain (with record failed Chocolatey packages)

    Scheduled Pinned Locked Moved Unsolved FOG Problems
    7 Posts 2 Posters 83 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • L
      lperoma
      last edited by

      Hello everyone,

      I would like to propose a small option on a software item (or on a group association): “run only after the host has been renamed and joined to the domain”.

      Today, on a fresh deploy, the agent enrolls, runs the snapins and then runs the Chocolatey software module, and only after that does it rename the host and join it to the domain, which ends in a reboot. That order is fine for Chrome or VLC. It is a problem for installers that do their real work in a second stage after the first one returns. Our case is the Avast Business agent: the MSI returns 0 in about ten seconds, but the antivirus itself is downloaded and installed afterwards, over the next few minutes. If the join reboot lands in the middle, the install can be left half done, and from FOG’s side everything looks fine because the Chocolatey package reported success.

      What we do today is a workaround inside the package script: if the computer name is still the image name, the script throws on purpose, so nothing gets installed, and then we rely on FOG running the software again after the reboot. It works, but it has some rough edges that a native option would remove:

      • When the script throws, the software status row for that host is not updated. It keeps the old state (converged from a previous run), so the web UI never shows that the package failed. We only knew from the host itself.

      • We had to rely on the retry. By watching the web server log we saw that after each boot the agent runs the Chocolatey module about four times, roughly a minute apart, and then not again for hours (we saw passes about every six hours). So if the retry after the join reboot is missed, the next chance is a long way off.

      • The software status list of the host survives a new deploy. When an image is deployed, pending tasks such as snapins are cleared, but the old software status rows stay, so a freshly cloned host still shows software as converged or installed from the previous install. That is also why a failed package could not be told apart from an old success. The machine is new after a deploy, so that list should not be kept.

      • We first tried to detect “not joined yet” with the domain membership, but that does not work: the agent renames the host and joins the domain in the same step, and both only become effective after the reboot, so right before it Windows already reports the host as part of the domain while it still has the image name. The host name was the only reliable signal.

      So the request would be, in order of importance:

      1. An option per software item (or per group) to defer it until after the rename/join reboot.

      2. Recording a failed Chocolatey run in the software status (failed, with the output), instead of leaving the previous status.

      3. Clearing the host’s software status list when a deploy finishes, the same way pending snapin tasks are cleared, since the machine is new.

      I am not sure the ordering is the only thing behind our Avast problem, since we also had a separate crash of the vendor installer that seems unrelated, so I am only asking for the generic behavior, which would help with any installer that continues working after it returns.

      Happy to share logs or test a patch if it helps. Thanks!

      Tom ElliottT 2 Replies Last reply Reply Quote 0
      • Tom ElliottT
        Tom Elliott @lperoma
        last edited by

        @lperoma Thanks for the detail. On the first two points: the next agent release will hold software until the rename/join reboot has happened, and a finished deploy will clear the host’s software status.

        On the status row not updating: the server writes that row on every report, failures included, so something else is happening. Could you post the agent log lines from the pass where the script threw? Look for the line that starts with software "<your package id>":, plus the matching lines in the web server log. Also, which page shows the stale converged: the host’s Software tab, or the installed-software inventory?

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        1 Reply Last reply Reply Quote 0
        • Tom ElliottT
          Tom Elliott @lperoma
          last edited by

          @lperoma Both changes are out now, so you can test them.

          • Agent 0.1.30 waits for the rename/join restart before it runs software, and the snapins wait with it. Agents update themselves to it. After the restart, the first check-in runs the software under the new name. You can drop the name check from your package script.
          • A finished deploy now clears the host’s software status. That is on dev-branch, so update your server to dev-branch to get it.

          One thing to know: if a user stays logged in on a renamed PC, the restart waits for them to log off, so software waits too. Turn on “Enforce Hostname | AD Join Reboots” on the host to restart after the grace period instead. Details: https://docs.fogproject.org/en/latest/management/web/software/#software-waits-for-a-rename-or-a-domain-join

          The log lines for the stale status are still useful if you can grab them.

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          L 1 Reply Last reply Reply Quote 0
          • L
            lperoma @Tom Elliott
            last edited by lperoma

            @Tom-Elliott
            Test result with the agent log: software waits for the rename/join restart, but not while the rejoin is still blocked

            Thanks a lot, Tom, for the quick work on this, for the agent change and for #2214. I tested it on a fresh Deploy: image captured with agent 0.1.35, server 1.6.1.59 (27a1194fb, dev-branch with #2214). The deferral works, but software still ran twice before it kicked in. Times are UTC (web server and agent logs are UTC+1 and have been converted).

            14:02:30  Post_Stage3.php, deploy finished (task complete, software status list cleared by #2214)
            14:02:41  PXE boot.php (reboot after imaging)
            14:03:06  Agent 0.1.35 enrolls (GET enroll, identity/check 409, POST enroll 200, identity/check 200)
            14:04:06  PXE boot.php (second reboot, before the domain join)
            14:04:22  Agent contacts (enroll, identity/check, poll 14:04:23)
            14:04:26  "Run before software" snapin downloaded; result rc 0 at 14:05:11
            14:06:49  SOFTWARE PASS 1: our package downloaded from the Chocolatey feed (200)
            14:07:43  8 x POST /agent/v1/result: six packages "installed", rc 0; our Avast package has no status row. Agent update payload downloaded
            14:07:54  Agent is now 0.1.36, update state ok
            14:08:07  SOFTWARE PASS 2: package downloaded again; at 14:08:20 the six packages are "converged", still no row for the Avast package
            14:08:23  POST /fog/agent/v1/directory/rejoin/start
            14:08:25  AD: computer account password set (pwdLastSet) = the domain join
            14:08:39  PXE boot.php: the rename/join restart
            14:08:48  AD: computer object changed (whenChanged), first boot under the new name
            14:08:49  First agent contact after the restart (enroll, identity/check, poll 14:08:54)
            14:09:11  SOFTWARE PASS 3 (first one after the restart): package downloaded again (200)
            14:09:31  Avast console: NO_SERVICES / ANTIVIRUS: INSTALLING
            14:09:37  Avast package reported "installed", rc 0 (first time it has a status row); the other six "converged"
            14:10:01  Pass 4: all seven packages "converged"
            14:13:17  Avast console: SAFE / ANTIVIRUS: ACTIVATED (3 min 46 s after INSTALLING)
            

            The matching agent log lines (fog-agent.log, local time +01:00):

            15:04:25  directory rejoin: blocked (directory_observation_required)
            15:07:42  software "avast-business-agent": installed, exit 4294967295, outcome failed, installed ""
            15:07:54  directory rejoin: blocked (directory_observation_required)
            15:08:19  software "avast-business-agent": installed, exit 4294967295, outcome failed, installed ""
            15:08:24  directory rejoin: native success; Windows restart and verification pending
            15:08:25  software: deferred; a rename or domain join is waiting for its restart
            15:08:25  reboot: applied (directory-rejoin: directory rejoin needs a Windows restart, mode reboot)
            15:08:54  directory rejoin: verified after Windows restart
            15:09:35  software "avast-business-agent": installed, exit 0, outcome success, installed "1.0.0"
            

            What I see:

            • The deferral works. software: deferred appears right after the join, and pass 3 only ran after directory rejoin: verified after Windows restart.
            • The gap is before the join. From enrollment (15:03) until 15:08:24 the rejoin was blocked (directory_observation_required), so nothing was pending and software ran twice while the computer was still named INSTALACION (the image name). What is that observation, and could software also wait while a join is expected but still blocked?
            • The failed run was not stored. The agent logged outcome failed (exit 4294967295) for our package in both early passes, and the 7 results were posted, but the host had only 6 software status rows, none for that package, until after the restart (point 2 of my first post is still open).
            • The Avast install worked, but only thanks to our own name check in the package script, which made it skip passes 1 and 2 and let pass 3 through.
            • The status list was empty right after the deploy finished, so #2214 works. That one is a big help, thank you.

            Happy to test a patch or send more logs.

            Tom ElliottT 1 Reply Last reply Reply Quote 0
            • Tom ElliottT
              Tom Elliott @lperoma
              last edited by

              @lperoma Thanks, that log made both problems clear.

              Software before the join. While the server holds the join (directory_observation_required is the server waiting for the agent’s fresh view of the domain), there was no restart pending yet, so nothing told the agent to wait. Agent 0.1.37 also waits while the server holds a join and the PC’s name is not yet the host’s name. The log then says software: deferred; the server has not renamed this machine yet. Agents update themselves to it.

              The missing status row. Your script’s failure exits with -1, which Windows reports as 4294967295. The status column only holds values up to 2147483647, so the database refused the row, and the server told the agent it was stored anyway. The fix stores it as -1, and a Return Codes entry accepts either form. If the server ever cannot store a result, it now says so, and the agent tries again on the next check-in. That fix is https://github.com/FOGProject/fogproject/pull/2301 and lands on dev-branch when its checks pass. Until then, exit 1 instead of throw in the package script gets you a status row.

              With both, you should be able to drop the name check from your package script. A fresh deploy with 0.1.37 and the log lines again would confirm it.

              Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

              Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

              Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

              L 1 Reply Last reply Reply Quote 0
              • L
                lperoma @Tom Elliott
                last edited by

                @Tom-Elliott

                Thanks Tom, that explains both. I re-ran the same test with your fixes in place.

                Setup: server updated to dev-branch 4c426a799 (includes #2301, schema 492). Fresh BIOS image captured with agent 0.1.38, so there was no self-update during the run. Same host (test-bios), same package avast-business-agent 1.0.0 (the name check in its script is still there).

                Result: software now waits for the join. All times UTC (agent log is +01:00, minus one hour).

                Time Source Event
                17:09:23 server Deploy task 16969 created
                17:09:45 server PXE: boot.php, bzImage, init.xz
                17:10:05 server Task check-in, copy starts
                17:12:34 server Post_Stage3.php, copy done. softwareStatus for the host is empty (#2214 OK)
                17:13:08 agent this state was made on another machine ... enrolling as this machine, host 667
                17:14:20 agent Service starts after the next reboot (0.1.38, no update)
                17:14:26 agent directory rejoin: blocked (directory_observation_required) and software: deferred; the server has not renamed this machine yet
                17:14:29 server POST directory/rejoin/start
                17:14:30.7 AD pwdLastSet of the computer account: joined
                17:14:31 agent directory rejoin: native success; Windows restart and verification pending
                17:14:33 agent software: deferred; a rename or domain join is waiting for its restart, then reboot: applied (directory-rejoin...)
                17:14:56 agent directory rejoin: verified after Windows restart
                17:15:40 agent Snapin 129 (before software): exit 0, success
                17:15:40 agent software: Chocolatey is missing; bootstrapping from https://community.chocolatey.org/install.ps1 (done 17:15:52)
                17:17:28 server Feed: avast-business-agent 1.0.0 downloaded
                17:17:45 Avast console ANTIVIRUS: INSTALLING
                17:18:34 agent 7 packages installed, exit 0, outcome success (googlechrome, vlc, 7zip, avast-business-agent, qemu-virtio-driver, qemu-guest-agent, chocolateygui). The server stored all 7 rows, Avast included
                17:18:58 agent All 7 converged
                17:21:15 Avast console ANTIVIRUS: ACTIVATED

                Compared with the earlier run (0.1.35, before your fix), software ran twice before the join and the Avast row was missing; now software runs once, after the join, and everything is stored.

                What I could not test: the Avast install succeeded, so the failure path (exit code -1 / 4294967295, your #2301) was not exercised, and the name check never had to act (the name was already final). Before I remove it I would like to test a package that fails on purpose and check that the row is stored with -1. Does that sound right?

                Two small questions:

                1. The join block (directory_observation_required) lasted about 5 minutes in the first run and about 6 seconds here. Is that expected, or did something change on the server side?
                2. At 17:14:26 and 17:14:33 the log says reconcile: a provider failed; will retry next poll. Which provider is that, and should I worry?

                One observation: the image has no Chocolatey installed, so the agent bootstraps it from the public site (12 seconds). That works, but a machine with no internet access would fail there.

                Thanks again for the quick fixes.

                Tom ElliottT 1 Reply Last reply Reply Quote 0
                • Tom ElliottT
                  Tom Elliott @lperoma
                  last edited by

                  @lperoma Thanks, that is the result we wanted: one software run, after the join, with every row stored.

                  The failure test. Yes, that is the right test. Make the package exit -1 (or throw). The Software Status row should then show failed with return code -1. Once you see that, you can drop the name check.

                  5 minutes against 6 seconds. Nothing in the join code changed between your two server builds. The difference I see is the agent: in the first run it updated itself from 0.1.35 to 0.1.36 during the wait, and the join started about 30 seconds after the new agent came up. In the second run there was no update. So the short wait is the normal case.

                  “a provider failed; will retry next poll”. That line is the software wait itself, not a failure. The wording is wrong, and the next agent release logs waiting; will run on a later poll instead. Nothing to worry about.

                  Chocolatey without internet. You can host the bootstrap yourself. Set “Chocolatey Install Script” to a copy of install.ps1 on your own server, and “Chocolatey Package Source” to a chocolatey .nupkg you host. Or put Chocolatey in the image. Details: https://docs.fogproject.org/en/latest/management/web/software/

                  Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                  Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                  Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  • First post
                    Last post

                  44

                  Online

                  12.8k

                  Users

                  17.7k

                  Topics

                  157.6k

                  Posts
                  Copyright © 2012-2026 FOG Project