Closed christiankozalla closed 1 year ago
Acknowledged. The problem is that ser create
runs in sudo but deno
does not show up in the path. I need sudo
to write a service file in /etc/systemd/system
.
which deno # works
sudo su
which deno # nothing
# This works- need to implement this in rust
sudo -u hp bash -i -c "which deno"
Fix on the way.
For complex commands like deno run -A --unstable main.ts
, it'll be better to have something like ser create "deno run -A --unstable main.ts"
. Currently can pass flags using sudo ser create main.js --interpreter deno -- -A --unstable
but compound paths deno run
are not supported yet.
`Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', src/handlers/handle_show_status.rs:144:48
Strange, it's unable to read the proc
file of an active service. Did your service start after running that command? Does cat /proc/1/stat
print a set of numbers?
pub async fn get_cpu_times(service_statuses: Vec<ServiceStatus>) -> Vec<u64> {
futures::future::try_join_all(service_statuses.into_iter().map(|status| {
tokio::spawn(async move {
if status.active == "active" {
get_cpu_time(status.pid).await.unwrap()
} else {
0
}
})
}))
.await
.unwrap()
}
pub async fn get_cpu_time(pid: u32) -> Result<u64, Box<dyn std::error::Error>> {
let stat_path = format!("/proc/{}/stat", pid);
let stat_content = tokio::fs::read_to_string(stat_path).await?;
let stat_fields: Vec<&str> = stat_content.split_whitespace().collect();
// The 14th field in /proc/<pid>/stat represents utime (user mode CPU time) in clock ticks
// The 15th field represents stime (kernel mode CPU time) in clock ticks
let utime: u64 = stat_fields[13].parse()?;
let stime: u64 = stat_fields[14].parse()?;
Ok(utime + stime)
}
I retried the second issue "ExecStart command fails with subcommand and flags" This time on my local machine (Ubuntu 22.04), before was on a VPS (also Ubuntu 22.04).. Now I go through the steps again.
ExecStart=/home/christian/.deno/bin/deno run -A --unstable main.ts
And it works! It prints the table that lists the service as active.
cat /proc/1/stat
prints a set of number.
@christiankozalla deno
should now get automatically detected with https://github.com/servicer-labs/servicer/commit/0a60956c447e64b2824a7a48e59be87715f95c55. No need to pass which deno
from the CLI.
I wanted to try servicer on a Deno app and faced mainly two issues.
Steps to reproduce
First issue: Could not find Deno
main.ts
)sudo ser create main.ts --name deno-backend --interpreter deno
As a workarount I used
ExecStart command fails with subcommand and flags
Unfortunately the command to start the Deno app is not
deno main.ts
(as innode index.js
)The correct command to start the app would be
deno run -A --unstable main.ts
So I used
sudo ser edit deno-backend
and changed theExecStart
commandExecStart=/path/to/deno run -A --unstable main.ts
But this gave the following error after running
sudo ser start deno-backend
Happy to provide more information if needed!