You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by jm...@apache.org on 2022/10/26 01:50:12 UTC

[skywalking-php] branch master updated: Kill worker on shutdown. (#28)

This is an automated email from the ASF dual-hosted git repository.

jmjoy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-php.git


The following commit(s) were added to refs/heads/master by this push:
     new db61440  Kill worker on shutdown. (#28)
db61440 is described below

commit db6144059ac14c60451d48e4bdd6866ad8f226d9
Author: phanalpha <ph...@hotmail.com>
AuthorDate: Wed Oct 26 09:50:06 2022 +0800

    Kill worker on shutdown. (#28)
---
 src/module.rs |  4 +++-
 src/worker.rs | 15 ++++++++++++++-
 2 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/src/module.rs b/src/module.rs
index 3a1343c..5acc733 100644
--- a/src/module.rs
+++ b/src/module.rs
@@ -17,7 +17,7 @@ use crate::{
     channel::Reporter,
     execute::register_execute_functions,
     util::{get_sapi_module_name, IPS},
-    worker::init_worker,
+    worker::{init_worker, shutdown_worker},
     SKYWALKING_AGENT_ENABLE, SKYWALKING_AGENT_LOG_FILE, SKYWALKING_AGENT_LOG_LEVEL,
     SKYWALKING_AGENT_SERVICE_NAME, SKYWALKING_AGENT_SKYWALKING_VERSION,
 };
@@ -86,6 +86,8 @@ pub fn init(_module: ModuleContext) -> bool {
 }
 
 pub fn shutdown(_module: ModuleContext) -> bool {
+    shutdown_worker();
+
     true
 }
 
diff --git a/src/worker.rs b/src/worker.rs
index a4256b2..077a30b 100644
--- a/src/worker.rs
+++ b/src/worker.rs
@@ -18,6 +18,7 @@ use std::{
     thread::available_parallelism, time::Duration,
 };
 
+use once_cell::sync::OnceCell;
 use phper::ini::Ini;
 use skywalking::reporter::{
     grpc::{ColletcItemConsume, GrpcReporter},
@@ -39,6 +40,8 @@ use tracing::{debug, error, info, warn};
 
 use crate::{channel, SKYWALKING_AGENT_SERVER_ADDR, SKYWALKING_AGENT_WORKER_THREADS};
 
+static WORKER_PID: OnceCell<libc::pid_t> = OnceCell::new();
+
 pub fn init_worker<P>(worker_addr: P)
 where
     P: AsRef<Path> + tracing::Value,
@@ -61,7 +64,17 @@ where
                 rt.block_on(start_worker(worker_addr, server_addr));
                 exit(0);
             }
-            Ordering::Greater => {}
+            Ordering::Greater => {
+                WORKER_PID.set(pid).unwrap();
+            }
+        }
+    }
+}
+
+pub fn shutdown_worker() {
+    if let Some(pid) = WORKER_PID.get() {
+        unsafe {
+            libc::kill(*pid, libc::SIGTERM);
         }
     }
 }