question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

is_running() method for services

See original GitHub issue

While developing Charms, we frequently have to check if the service is currently running, like so:

    def _is_running(self, container, service):
        """Helper method to determine if a given service is running in a given container"""
        try:
            service = container.get_service(service)
        except ModelError:
            return False
        return service.current == ServiceStatus.ACTIVE
        # Check we can get a list of services back from the Pebble API
        if self._is_running(container, "grafana"):
            logger.info("grafana already started")
            return

Could be useful if we have that method available as a part of the Operator Framework.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
niemeyercommented, Mar 26, 2021

Having a is_running() method in the service sounds nice, but the implementation above is a bit suspect. It hides an API error and pretends the service is just not running. That doesn’t look like a great API behavior that we’d want to support in the operator framework itself.

This conversation and the code review also made me think that these APIs are not so nice to use. Maybe we should have a single get_services() method that returns something like a ServicesInfo, the plural of ServiceInfo. That type could indeed support more helpful methods, such as services.grafana.is_running() or/and services.is_running(“grafana”, “logger”). With that API the error checking might be done only once at the get_services() level, and the follow up usage would be free from exceptions because the data would be local.

@benhoyt What do you think?

0reactions
benhoytcommented, Mar 30, 2021

Sounds good – will do today or tomorrow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

what is the use of test.isrunningtest() method in test class
The Test.isRunningTest() method is used to identify, if the piece of code being executed is invoked from a Test class execution or from ......
Read more >
The "proper" way to test if a service is running in a script
I'm writing a bash script and in it I'd like to check if a given service is running. I know how to do...
Read more >
c++ - How to check that the current process is running as ...
I have a program that can be run as a simple console application or can be registered as Windows Service. I want to...
Read more >
Services overview
A Service is an application component that can perform long-running operations in the background. It does not provide a user interface.
Read more >
NSInstance.IsRunning Property
true if the instance of Notification Services is running; otherwise, false. Remarks. This method returns the state of the NSInstance object. This is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found