How to access plone 6 site from console script?

In of my plone add-on I defined a console script do_something:

      do_something = my.addon.scripts.do_something

Now, in my script I want to access the plone site. How can I do this in Plone 6?

I need something similar to this get_plone_site we used in Plone 4.

Console scripts create a script in the buildout but they don't have access to the zope instance itself. They are run independently of the Zope process so if you need to interact with the Plone site you should use the REST API.

Instead, you can define a [zopectl.command] section in your, and this will create additional bin/instance XXXX commands which will have access to the Zope database through the app.Plone variable.

Here's some demo code:

    reindex_catalog_indexes = addon.scripts.reindex_catalog_indexes:main

from plone import api
from zope.component.hooks import setSite
import transaction

def main(app, *args):
    # ...


Thank you very much, @erral!

@erral, one more question, please. I can't find instance in my bin folder. This is all I have:

root@blabla:/app# ls bin
Activate.ps1   diazocompiler	  fstail       mkwsgiinstance  pip3.11		     repozo	  update_locale        zdaemon	    zope-sendmail
__pycache__    diazopreprocessor  futurize     mxdev	       plone-register-flags  roman  waitress-serve       zeo-nagios
activate       diazorun		  i18nextract  normalizer      plone-register-icons  runwsgi	  wheel		       zeoctl
activate.csh   fsdump		  icalendar    pasteurize      python	  runzeo	  zconfig	       zeopack  fsoids		  jsonschema   pip	       python3		  testldap	  zconfig_schema2html  zodbconvert
addzopeuser    fsrefs		  markdown_py  pip3	       python3.11		  unidecode	  zconsole	       zodbpack

I start my backend with ./ start command.

How can I run the zopectl.command in this case?

then it should be ./ yourscript right? In that case you should check whether docker-entrypoint supports arbitrary parameters or does specific things for start.

If you are using plone/plone-backend I can see here that handles start specially:

So you may execute the full command in some other way. I also see there that the script used to start the site is zconsole so you may need to execute something like:

./ zconsole yourscript or something like that.