is_running() method for services
See original GitHub issueWhile 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:
- Created 2 years ago
- Comments:11 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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?
Sounds good – will do today or tomorrow.