Unable to restart the service "foreman-maintain service restart"

Problem: Unable to restart the service “foreman-maintain service restart”

Expected outcome: Service should be restarted successfully

**Foreman and Proxy versions:**Foreman 3.13 Katello 4.15

**Foreman and Proxy plugin versions:**Foreman 3.13 Katello 4.15

Distribution and version: Rocky 9

Other relevant data:

We are trying to restart the foreman-maintain service and we are getting the error as below:

foreman-maintain service restart
Running Restart Services
================================================================================
Check if command is run as root user:                                 [OK]
--------------------------------------------------------------------------------
Restart applicable services:

Restarting the following service(s):
redis, postgresql (candlepin), postgresql (foreman), postgresql (pulpcore), pulpcore-api, pulpcore-content, pulpcore-worker@1.service, pulpcore-worker@2.service, pulpcore-worker@3.service, pulpcore-worker@4.service, pulpcore-worker@5.service, pulpcore-worker@6.service, pulpcore-worker@7.service, pulpcore-worker@8.service, tomcat, dynflow-sidekiq@orchestrator, foreman, httpd, puppetserver, dynflow-sidekiq@worker-1, dynflow-sidekiq@worker-hosts-queue-1, foreman-proxy
| restarting postgresql (pulpcore)#<Thread:0x00007f38300f8dd0 /usr/share/gems/gems/foreman_maintain-1.8.1/definitions/features/service.rb:94 run> terminated with exception (report_on_exception is true):
/usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/concerns/metadata.rb:227:in `evaluate_confines': Recursive confine block call detected (RuntimeError)
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/concerns/metadata.rb:204:in `present?'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/detector.rb:113:in `each'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/detector.rb:113:in `find'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/detector.rb:113:in `detect_feature'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/detector.rb:11:in `feature'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/concerns/finders.rb:9:in `feature'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/definitions/features/instance.rb:58:in `downstream'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain.rb:171:in `pkg_and_cmd_name'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain.rb:179:in `command_name'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/utils/service/remote_db.rb:42:in `restart'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/definitions/features/service.rb:94:in `block (2 levels) in fork_threads_for_services'
#<Thread:0x00007f38300fa130 /usr/share/gems/gems/foreman_maintain-1.8.1/definitions/features/service.rb:94 run> terminated with exception (report_on_exception is true):
/usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/concerns/metadata.rb:227:in `evaluate_confines': Recursive confine block call detected (RuntimeError)
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/concerns/metadata.rb:204:in `present?'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/detector.rb:113:in `each'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/detector.rb:113:in `find'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/detector.rb:113:in `detect_feature'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/detector.rb:11:in `feature'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/concerns/finders.rb:9:in `feature'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/definitions/features/instance.rb:58:in `downstream'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain.rb:171:in `pkg_and_cmd_name'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain.rb:179:in `command_name'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/utils/service/remote_db.rb:42:in `restart'
        from /usr/share/gems/gems/foreman_maintain-1.8.1/definitions/features/service.rb:94:in `block (2 levels) in fork_threads_for_services'
                                    [FAIL]
Recursive confine block call detected
--------------------------------------------------------------------------------
Scenario [Restart Services] failed.

The following steps ended up in failing state:

  [service-restart]

Resolve the failed steps and rerun the command.
In case the failures are false positives, use
--whitelist="service-restart"

Could you please help us on this issue. Please let us know if any other logs required for the same.

Hi All,

Is anyone faced this kind of error? Please help us.

Do I see it right, you’re running Foreman with an external database?

Can you edit /usr/share/gems/gems/foreman_maintain-1.8.1/lib/foreman_maintain/utils/service/remote_db.rb and replace line 42 (which should read command_name = ForemanMaintain.command_name) with command_name = 'foreman-maintain'

Does that fix the issue for you?

Thanks a lot for your help. Its working now.

foreman-maintain service restart
Running Restart Services
================================================================================
Check if command is run as root user:                                 [OK]
--------------------------------------------------------------------------------
Restart applicable services:

Restarting the following service(s):
redis, postgresql (candlepin), postgresql (foreman), postgresql (pulpcore), pulpcore-api, pulpcore-content, pulpcore-worker@1.service, pulpcore-worker@2.service, pulpcore-worker@3.service, pulpcore-worker@4.service, pulpcore-worker@5.service, pulpcore-worker@6.service, pulpcore-worker@7.service, pulpcore-worker@8.service, tomcat, dynflow-sidekiq@orchestrator, foreman, httpd, puppetserver, dynflow-sidekiq@worker-1, dynflow-sidekiq@worker-hosts-queue-1, foreman-proxy
- restarting postgresql (pulpcore)
postgresql (candlepin) is remote and is UP. Remote databases are not managed by foreman-maintain and therefore was not restarted.


postgresql (foreman) is remote and is UP. Remote databases are not managed by foreman-maintain and therefore was not restarted.


postgresql (pulpcore) is remote and is UP. Remote databases are not managed by foreman-maintain and therefore was not restarted.

- All services restarted                                              [OK]
--------------------------------------------------------------------------------

Thanks for confirming.

I wonder why this happened tho, it should not get into a recursive loop detecting whether you’re on Foreman or Satellite. Certainly something to investigate.

I’ve opened a PR to fix that: reword remote-db restart message to avoid command name by evgeni · Pull Request #975 · theforeman/foreman_maintain · GitHub