fixes for server, added onefetch

main
Anton Franzluebbers 2022-02-28 04:29:34 +00:00
parent 961a688068
commit 82b0348feb
7 changed files with 34 additions and 15 deletions

View File

@ -19,4 +19,5 @@ You don't need to do both of these steps. The control panel runs the other serve
3. Install rust: `sudo apt install cargo` 3. Install rust: `sudo apt install cargo`
3. Switch to control panel: `cd control-panel` 3. Switch to control panel: `cd control-panel`
5. Build: `cargo build --release` 5. Build: `cargo build --release`
6. Run the web server in the background so that it doesn't quit when you leave ssh: `nohup sudo ./target/release/control-panel`. You'll have to install `nohup` with apt. 6. `touch ../nohup.out ../restarts.log`
6. Run the web server in the background so that it doesn't quit when you leave ssh: `nohup sudo ./target/release/control-panel`. You'll have to install `nohup` with apt.

View File

@ -1,5 +1,5 @@
{ {
"port":80, "port":5000,
"tcp_timeout":30, "tcp_timeout":30,
"tcp_send_buffer":100000 "tcp_send_buffer":100000
} }

View File

@ -4,3 +4,4 @@ main
main.exe main.exe
main.pdb main.pdb
.idea/ .idea/
onefetch.out

1
control-panel/onefetch_file.sh Executable file
View File

@ -0,0 +1 @@
sudo -u ubuntu bash -c "onefetch > onefetch.out"

View File

@ -31,7 +31,6 @@ fn lines_from_file(filename: impl AsRef<Path>) -> Vec<String> {
.collect() .collect()
} }
// Macro documentation can be found in the actix_web_codegen crate
#[get("/")] #[get("/")]
async fn index(hb: web::Data<Handlebars<'_>>) -> HttpResponse { async fn index(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
@ -47,11 +46,20 @@ async fn index(hb: web::Data<Handlebars<'_>>) -> HttpResponse {
.output() .output()
.expect("failed to execute process"); .expect("failed to execute process");
let _onefetch = Command::new("sh")
.arg("onefetch_file.sh")
.output()
.expect("failed");
let onefetch = fs::read_to_string("onefetch.out").unwrap();
let data = json!({ let data = json!({
"log_output": log_file, "log_output": log_file,
"restarts_output": restarts_log, "restarts_output": restarts_log,
"uptime": format!("{}", String::from_utf8_lossy(&uptime.stdout)), "uptime": format!("{}", String::from_utf8_lossy(&uptime.stdout)),
//"onefetch": format!("{}", String::from_utf8_lossy(&onefetch.stdout))
"onefetch": onefetch
}); });
let body = hb.render("index", &data).unwrap(); let body = hb.render("index", &data).unwrap();
@ -65,8 +73,8 @@ async fn restart_server() -> HttpResponse {
let _output = Command::new("sh") let _output = Command::new("sh")
.arg("../run.sh") .arg("../run.sh")
.stdin(Stdio::null()) .stdin(Stdio::null())
.stdout(Stdio::null()) //.stdout(Stdio::null())
.stderr(Stdio::null()) //.stderr(Stdio::null())
.spawn(); .spawn();
HttpResponse::Ok().body("DONE") HttpResponse::Ok().body("DONE")
@ -98,11 +106,15 @@ async fn compile() -> HttpResponse {
let root = Path::new(&config.server_dir); let root = Path::new(&config.server_dir);
let _new_dir = env::set_current_dir(&root); let _new_dir = env::set_current_dir(&root);
print!("before");
let output = Command::new("cargo") let output = Command::new("cargo")
.arg("build") .arg("build")
.arg("--release") .arg("--release")
.output() .output()
.expect("failed to execute process"); .expect("failed to execute process");
print!("after");
let _new_dir = env::set_current_dir(orig_dir); let _new_dir = env::set_current_dir(orig_dir);

View File

@ -24,6 +24,7 @@
<body> <body>
<section class="section"> <section class="section">
<div class="container"> <div class="container">
<img src="https://vel.engr.uga.edu/wp-content/uploads/elementor/thumbs/4dLogo-1-oaxk7d2mcrutzo0dhqah6qlgpp2c1tvihad1dchrc0.png" style="float: right;">
<h1 class="title"> <h1 class="title">
VelNet Control Panel VelNet Control Panel
</h1> </h1>
@ -42,6 +43,7 @@
<button class="button" id="compile-button">Compile</button> <button class="button" id="compile-button">Compile</button>
</div> </div>
<div class="block">Uptime: {{uptime}}</div> <div class="block">Uptime: {{uptime}}</div>
<pre>{{onefetch}}</pre>
</div> </div>
</section> </section>
@ -113,4 +115,4 @@
</script> </script>
</body> </body>
</html> </html>

18
run.sh
View File

@ -1,13 +1,15 @@
#!/bin/bash
BASEDIR=$(dirname "$0") BASEDIR=$(dirname "$0")
# pushd $BASEDIR
echo $(date +"%Y-%m-%dT%T.%3N%z") >> $BASEDIR/restarts.log echo $(date +"%Y-%m-%dT%T.%3N%z") >> $BASEDIR/restarts.log
echo "Before: " echo "Before: " >> $BASEDIR/restarts.log
pgrep VelNetServer pgrep -f "VelNetServerRust -v2" >> $BASEDIR/restarts.log
pkill VelNetServer #pgrep -f "VelNetServerRust -v2" | xargs sudo kill >> $BASEDIRE/restarts.log
echo "\nAfter: " #kill $(pgrep -f "VelNetServerRust -v2")
pgrep VelNetServer pkill -f "VelNetServerRust -v2"
echo "\nAfter: " >> $BASEDIR/restarts.log
pgrep -f "VelNetServerRust -v2" >> $BASEDIR/restarts.log
echo "\n" echo "\n"
(cd $BASEDIR && nohup "./target/release/VelNetServerRust" &) (cd $BASEDIR && nohup ./target/release/VelNetServerRust -v2 >> nohup.out &)
# nohup "$BASEDIR/target/release/VelNetServerRust" & # nohup "$BASEDIR/target/release/VelNetServerRust" &
echo "Starting..." >> $BASEDIR/restarts.log echo "Starting..." >> $BASEDIR/restarts.log
# popd $BASEDIR