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.

add "is_running(service)" to Container

See original GitHub issue

To check if a service is running we need to:

self.container.get_service("service_name").is_running()

Recently Container.restart(services) was added and Container.is_running(service) would be a great companion.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
rbarry82commented, Aug 26, 2021

ops.pebble is explicitly part of the operator framework.

ops.model and ops.framework wrap a fair amount of things. It isn’t necessarily about talking to pebble directly (which container.get_service("service_name").is_running() is not doing either, by the way), and more about encapsulation.

ops.pebble.Service is the representation get_service returns, and whether or not it’s running depends checks against ops.pebble.ServiceStatus.

Logically, a Container may have many services. is_running("service_name") reads akin to “each service has its own container”. If anything, Container.get_service_status("service") would make more sense, but then we’re simply re-exporting an enum from ops.pebble and re-implementing the same logic (either punting it to charm authors or moving it up a level and duplicating it in ops.model) unless it calls exactly the same code in your original comment, or self.get_service("service_name").is_running(), really.

0reactions
sed-icommented, Aug 26, 2021

I do not recall encountering charm code that talks to pebble directly. To my understanding, ops.model servers as a wrapper around anything pebble (cf. container.pull).

It is true though that start, stop, restart all have the same “directionality” to them (OF -> Pebble).

A Container can have more than one service in a Pebble layer.

The container.is_running() interface could deal with that, e.g. if all/any(container.is_running(lst)) etc.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to automatically start a service when running a docker ...
First, there is a problem in your Dockerfile : RUN service mysql restart && /tmp/setup.sh. Docker images do not save running processes.
Read more >
Check is container/service running with docker-compose
This doesn't tell you if the container is running or not, just if it exists or not. Try doing docker-compose up then Ctrl-C....
Read more >
docker service create - Docker Documentation
Create a service with a config. The config will be mounted into redis-config , be owned by the user who runs the command...
Read more >
Chapter 4. Running Containers as systemd Services with ...
When you set up a container to start as a systemd service, you can define the order in which the containerized service runs,...
Read more >
Attach to a running container - Visual Studio Code
To attach to a Docker container, either select Dev Containers: Attach to Running Container... from the Command Palette (F1) or use the Remote...
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