about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authoryuzu <yuzu@b9215c17-b818-4693-b096-d1e41a411fef>2025-07-08 07:12:59 +0000
committeryuzu <yuzu@b9215c17-b818-4693-b096-d1e41a411fef>2025-07-08 07:12:59 +0000
commit141e546e1d7a8385817b3edb46bd91b502563cd9 (patch)
treee215d8e4d4c79fee4b94e527cef8522b27ba5cec
parent8f05a437d80a243e504b4fb5d26b53bbd7de9c47 (diff)
downloadsalaryman-141e546e1d7a8385817b3edb46bd91b502563cd9.tar.gz
salaryman-141e546e1d7a8385817b3edb46bd91b502563cd9.tar.bz2
salaryman-141e546e1d7a8385817b3edb46bd91b502563cd9.zip
working proof of concept -- minecraft
git-svn-id: svn+ssh://diminuette.aengel.lesbianunix.dev/salaryman/trunk@9 b9215c17-b818-4693-b096-d1e41a411fef
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml10
-rw-r--r--salaryman.toml8
-rw-r--r--src/bin/smd.rs (renamed from src/main.rs)17
-rw-r--r--src/model.rs31
5 files changed, 33 insertions, 35 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d96f142..d12320b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -313,7 +313,7 @@ checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
 
 [[package]]
 name = "salaryman"
-version = "0.1.0"
+version = "0.0.1"
 dependencies = [
  "clap",
  "serde",
diff --git a/Cargo.toml b/Cargo.toml
index be9af33..7518b99 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,10 +1,18 @@
 [package]
 name = "salaryman"
-version = "0.1.0"
+version = "0.0.1"
 edition = "2024"
+authors = ["Ren Kararou <[email protected]>"]
+description = "A very simple service management framework"
 
 [dependencies]
 clap = { version = "4.5.39", features = ["derive"] }
 serde = { version = "1.0.219", features = ["derive"] }
 tokio = { version = "1.45.1", features = ["full"] }
 toml = "0.8.22"
+
+[[bin]]
+name = "smd"
+path = "src/bin/smd.rs"
+test = false
+bench = false
diff --git a/salaryman.toml b/salaryman.toml
index 91cfe9b..0e0e8fc 100644
--- a/salaryman.toml
+++ b/salaryman.toml
@@ -2,9 +2,9 @@ address = "0.0.0.0"
 port = 8080
 
 [[service]]
-name = "cattest"
-command = "cat"
-args = "/var/log/messages"
-directory = "/"
+name = "minecraft"
+command = "java"
+args = "-jar server.jar nogui"
+directory = "/minecraft/data"
 autostart = true
 
diff --git a/src/main.rs b/src/bin/smd.rs
index 09a9376..5a8401a 100644
--- a/src/main.rs
+++ b/src/bin/smd.rs
@@ -72,21 +72,16 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
         services.push(Service::from_conf(&conf.service[i]));
         if conf.service[i].autostart {
             services[i].start().await?;
+            services[i].scan_stdout().await?;
+            services[i].scan_stderr().await?;
         }
     }
-    let mut outs: Vec<(String, tokio::sync::mpsc::Receiver<String>)> = Vec::new();
+    tokio::time::sleep(std::time::Duration::from_secs(60)).await;
+    println!("trying to write to stdin!");
     for i in 0..services.len() {
-        if services[i].started().await {
-            outs.push((services[i].name().await, services[i].scan_stdout().await?));
-        }
-    }
-    for _i in 0..100 {
-        for out in 0..outs.len() {
-            if let Some(s) = outs[out].1.recv().await {
-                println!("got line from {} :: {}", outs[out].0, s);
-            }
-        }
+        services[i].write_stdin("stop\n".into()).await?;
     }
+    tokio::time::sleep(std::time::Duration::from_secs(30)).await;
     for mut service in services {
         match service.stop().await {
             Ok(_) => println!("lol it was killed"),
diff --git a/src/model.rs b/src/model.rs
index 8f4416b..60960e3 100644
--- a/src/model.rs
+++ b/src/model.rs
@@ -61,8 +61,8 @@ impl ServiceConf {
 pub struct Service {
     conf: ServiceConf,
     proc: Option<Arc<Mutex<Child>>>,
-    stdout: Option<Arc<Mutex<Receiver<String>>>>,
-    stderr: Option<Arc<Mutex<Receiver<String>>>>,
+    pub stdout: Option<Arc<Mutex<Receiver<String>>>>,
+    pub stderr: Option<Arc<Mutex<Receiver<String>>>>,
 }
 impl Default for Service {
     fn default() -> Self {
@@ -109,23 +109,17 @@ impl Service {
             )));
         }
         let cmd = &self.conf.command;
-        let args = if let Some(a) = &self.conf.args {
-            a.split_whitespace()
-        } else {
-            "".split_whitespace()
+        let mut proc = Command::new(cmd);
+        proc.stdin(Stdio::piped());
+        proc.stdout(Stdio::piped());
+        proc.stderr(Stdio::piped());
+        if let Some(a) = &self.conf.args {
+            proc.args(a.split_whitespace());
         };
-        let cwd = if let Some(c) = &self.conf.directory {
-            c
-        } else {
-            &PathBuf::from("/")
+        if let Some(c) = &self.conf.directory {
+            proc.current_dir(c);
         };
-        let child = Command::new(cmd)
-            .args(args)
-            .current_dir(cwd)
-            .stdin(Stdio::piped())
-            .stdout(Stdio::piped())
-            .stderr(Stdio::piped())
-            .spawn()?;
+        let child = proc.spawn()?;
         self.proc = Some(Arc::new(Mutex::new(child)));
         Ok(())
     }
@@ -217,7 +211,7 @@ impl Service {
             spawn(async move {
                 let mut br = BufReader::new(stderr).lines();
                 while let Ok(Some(line)) = br.next_line().await {
-                    println!("ERR :: {} :: {}", &sname, &line);
+                    eprintln!("{} :: {}", &sname, &line);
                     if let Err(_) = tx.send(line).await {
                         return;
                     };
@@ -247,6 +241,7 @@ impl Service {
                 )));
             };
             stdin.write(&buf.as_bytes()).await?;
+            stdin.flush().await?;
             Ok(())
         } else {
             Err(Box::new(std::io::Error::new(