Compare commits
10 commits
Author | SHA1 | Date | |
---|---|---|---|
bc090fa9b2 | |||
86cf230f21 | |||
fefcbe4373 | |||
f7c9605f26 | |||
f4374459dd | |||
89be5b3542 | |||
8209da3b21 | |||
28ffb56665 | |||
9bfe63b1a9 | |||
78cd7279ba |
3 changed files with 21 additions and 6 deletions
|
@ -35,4 +35,10 @@ jobs:
|
|||
with:
|
||||
direction: upload
|
||||
release-dir: /tmp/release
|
||||
token: ${{ secrets.FORGEJO_TOKEN }}
|
||||
token: ${{ secrets.FORGEJO_TOKEN }}
|
||||
- name: Upload debian package
|
||||
run: |
|
||||
cp /tmp/release/*.deb /tmp/phenix.deb
|
||||
curl --user ${{ vars.DOCKER_PUSH_USERNAME }}:${{ secrets.DOCKER_PUSH_PASSWORD }} \
|
||||
--upload-file /tmp/phenix.deb \
|
||||
https://code.edgarpierre.fr/api/packages/${{ github.repository_owner }}/debian/pool/bookworm/main/upload
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
[package]
|
||||
name = "phenix"
|
||||
version = "0.1.3"
|
||||
description = "Utility to restart PCIe devices when link is lost."
|
||||
version = "0.2.1"
|
||||
edition = "2024"
|
||||
license = "GPL-3.0-or-later"
|
||||
repository="https://code.edgarpierre.fr/edpibu/phenix"
|
||||
|
|
16
src/main.rs
16
src/main.rs
|
@ -1,13 +1,20 @@
|
|||
#![feature(file_buffered)]
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::BufRead;
|
||||
use std::io::Write;
|
||||
use std::io::Seek;
|
||||
use std::io::SeekFrom;
|
||||
|
||||
fn main() {
|
||||
println!("Reading kernel messages...");
|
||||
|
||||
let kmsg_file = File::open_buffered("/dev/kmsg").expect("Failed to open /dev/kmsg");
|
||||
let mut kmsg_file =
|
||||
File::open_buffered(env::var("PHENIX_KMSG").unwrap_or(String::from("/dev/kmsg")))
|
||||
.expect("Failed to open /dev/kmsg");
|
||||
|
||||
|
||||
kmsg_file.seek(SeekFrom::End(0)).expect("Failed to seek to end");
|
||||
let lines = kmsg_file.lines();
|
||||
for line in lines {
|
||||
match line {
|
||||
|
@ -23,8 +30,9 @@ fn manage_line(line: String) {
|
|||
println!("PCIe link lost {prefix}");
|
||||
|
||||
let id = line.splitn(3, " ").nth(1);
|
||||
if let Some(id) = id {
|
||||
reset_device(id);
|
||||
match id {
|
||||
Some(id) => reset_device(id),
|
||||
None => println!("No device id found in message {line}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +41,7 @@ fn manage_line(line: String) {
|
|||
fn reset_device(id: &str) {
|
||||
println!("Resetting {id}");
|
||||
echo1(rm_file_path(&id));
|
||||
println!("Removed device {id}");
|
||||
echo1(String::from("/sys/bus/pci/rescan"));
|
||||
println!("Rescanned PCI bus");
|
||||
}
|
||||
|
@ -44,7 +53,6 @@ fn echo1(path: String) {
|
|||
Ok(mut file) => {
|
||||
file.write_all(b"1")
|
||||
.expect("Failed to write to remove file");
|
||||
println!("Removed device {path}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue