Skip to content

Recommended Way to Shutdown Varlink Server? #25

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
zicklag opened this issue Nov 14, 2019 · 5 comments
Closed

Recommended Way to Shutdown Varlink Server? #25

zicklag opened this issue Nov 14, 2019 · 5 comments

Comments

@zicklag
Copy link

zicklag commented Nov 14, 2019

Is there a recommended way to shutdown the Varlink server when it is started with varlink::listen()?

I'm sure I could find a way to do it if I implemented the server myself, I was just making sure that there wasn't already a good way to do it.

Specifically I am looking to be able to shutdown the server in response to an RPC call, if that changes anything.

@zicklag
Copy link
Author

zicklag commented Nov 14, 2019

I was thinking about passing in an Arc<Atomicbool> to the listen() function that when set to false would shutdown the server. Pretty much like the ctrlc crate example.

Would you be open to a PR for that?

@haraldh
Copy link
Collaborator

haraldh commented Nov 15, 2019

just return Err(varlink::ErrorKind::ConnectionClosed.into()) from an API method

@haraldh
Copy link
Collaborator

haraldh commented Nov 15, 2019

fn stop_serving(&self, call: &mut dyn Call_StopServing) -> varlink::Result<()> {
call.reply()?;
Err(varlink::ErrorKind::ConnectionClosed.into())
}

haraldh added a commit to haraldh/varlink-rust that referenced this issue Nov 15, 2019
Factor out the `varlink::listen` parameters into a `varlink::ListenConfig` struct,
so we can use ..Default::default().

Add an `stop_listening: Option<Arc<AtomicBool>>` to the `varlink::ListenConfig` struct,
which can be set remotely to break the `varlink::listen` loop.

Stop the running server after 10 seconds

```rust
      use std::{thread, time};
      use std::sync::atomic::Ordering;
      let stop_listening = Arc::new(std::sync::atomic::AtomicBool::new(false));

      let child = {
          let stop_running = stop_listening.clone();
          thread::spawn(move || {
              thread::sleep(time::Duration::from_secs(10));
              // Stop the running server after 10 seconds
              stop_listening.store(true, Ordering::Relaxed);
          })
      };

      varlink::listen(
          service,
          &address,
          &varlink::ListenConfig {
              idle_timeout: timeout,
              stop_listening: Some(stop_listening),
              ..Default::default()
          },
      )?;

      child.join().expect("Error joining thread");
```

Obsoletes varlink#26
Addresses varlink#25
@haraldh
Copy link
Collaborator

haraldh commented Nov 15, 2019

What do you think about PR #27 ??

haraldh added a commit to haraldh/varlink-rust that referenced this issue Nov 18, 2019
Factor out the `varlink::listen` parameters into a `varlink::ListenConfig` struct,
so we can use ..Default::default().

Add an `stop_listening: Option<Arc<AtomicBool>>` to the `varlink::ListenConfig` struct,
which can be set remotely to break the `varlink::listen` loop.

Stop the running server after 10 seconds

```rust
      use std::{thread, time};
      use std::sync::atomic::Ordering;
      let stop_listening = Arc::new(std::sync::atomic::AtomicBool::new(false));

      let child = {
          let stop_running = stop_listening.clone();
          thread::spawn(move || {
              thread::sleep(time::Duration::from_secs(10));
              // Stop the running server after 10 seconds
              stop_listening.store(true, Ordering::Relaxed);
          })
      };

      varlink::listen(
          service,
          &address,
          &varlink::ListenConfig {
              idle_timeout: timeout,
              stop_listening: Some(stop_listening),
              ..Default::default()
          },
      )?;

      child.join().expect("Error joining thread");
```

Obsoletes varlink#26
Addresses varlink#25
haraldh added a commit to haraldh/varlink-rust that referenced this issue Nov 18, 2019
Factor out the `varlink::listen` parameters into a `varlink::ListenConfig` struct,
so we can use ..Default::default().

Add an `stop_listening: Option<Arc<AtomicBool>>` to the `varlink::ListenConfig` struct,
which can be set remotely to break the `varlink::listen` loop.

Stop the running server after 10 seconds

```rust
      use std::{thread, time};
      use std::sync::atomic::Ordering;
      let stop_listening = Arc::new(std::sync::atomic::AtomicBool::new(false));

      let child = {
          let stop_running = stop_listening.clone();
          thread::spawn(move || {
              thread::sleep(time::Duration::from_secs(10));
              // Stop the running server after 10 seconds
              stop_listening.store(true, Ordering::Relaxed);
          })
      };

      varlink::listen(
          service,
          &address,
          &varlink::ListenConfig {
              idle_timeout: timeout,
              stop_listening: Some(stop_listening),
              ..Default::default()
          },
      )?;

      child.join().expect("Error joining thread");
```

Obsoletes varlink#26
Addresses varlink#25
haraldh added a commit to haraldh/varlink-rust that referenced this issue Nov 18, 2019
Factor out the `varlink::listen` parameters into a `varlink::ListenConfig` struct,
so we can use ..Default::default().

Add an `stop_listening: Option<Arc<AtomicBool>>` to the `varlink::ListenConfig` struct,
which can be set remotely to break the `varlink::listen` loop.

Stop the running server after 10 seconds

```rust
      use std::{thread, time};
      use std::sync::atomic::Ordering;
      let stop_listening = Arc::new(std::sync::atomic::AtomicBool::new(false));

      let child = {
          let stop_running = stop_listening.clone();
          thread::spawn(move || {
              thread::sleep(time::Duration::from_secs(10));
              // Stop the running server after 10 seconds
              stop_listening.store(true, Ordering::Relaxed);
          })
      };

      varlink::listen(
          service,
          &address,
          &varlink::ListenConfig {
              idle_timeout: timeout,
              stop_listening: Some(stop_listening),
              ..Default::default()
          },
      )?;

      child.join().expect("Error joining thread");
```

Obsoletes varlink#26
Addresses varlink#25
haraldh added a commit that referenced this issue Nov 18, 2019
Factor out the `varlink::listen` parameters into a `varlink::ListenConfig` struct,
so we can use ..Default::default().

Add an `stop_listening: Option<Arc<AtomicBool>>` to the `varlink::ListenConfig` struct,
which can be set remotely to break the `varlink::listen` loop.

Stop the running server after 10 seconds

```rust
      use std::{thread, time};
      use std::sync::atomic::Ordering;
      let stop_listening = Arc::new(std::sync::atomic::AtomicBool::new(false));

      let child = {
          let stop_running = stop_listening.clone();
          thread::spawn(move || {
              thread::sleep(time::Duration::from_secs(10));
              // Stop the running server after 10 seconds
              stop_listening.store(true, Ordering::Relaxed);
          })
      };

      varlink::listen(
          service,
          &address,
          &varlink::ListenConfig {
              idle_timeout: timeout,
              stop_listening: Some(stop_listening),
              ..Default::default()
          },
      )?;

      child.join().expect("Error joining thread");
```

Obsoletes #26
Addresses #25
@Gunni
Copy link

Gunni commented Jan 26, 2024

The above PR was merged 4 years ago, why is this issue still open?

@haraldh haraldh closed this as completed Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants