Compare commits
13 Commits
using-alpi
...
ignore-sig
| Author | SHA1 | Date | |
|---|---|---|---|
| 4cfee4c454 | |||
| 03c0c0401e | |||
| d1c78f7b71 | |||
| da71569517 | |||
| 4195eadc9a | |||
| 190479d796 | |||
| 171c799a31 | |||
| 11dbe7d4f0 | |||
| b4f81ccf30 | |||
| 64fa76d39b | |||
| 342ac49bea | |||
| d26cc87713 | |||
| 212ae4847a |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
/target
|
||||
/coba.txt
|
||||
124
Cargo.lock
generated
124
Cargo.lock
generated
@@ -107,6 +107,17 @@ version = "0.3.29"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e36d3378ee38c2a36ad710c5d30c2911d752cb941c00c72dbabfb786a7970817"
|
||||
|
||||
[[package]]
|
||||
name = "getrandom"
|
||||
version = "0.2.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"libc",
|
||||
"wasi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gimli"
|
||||
version = "0.28.0"
|
||||
@@ -119,6 +130,12 @@ version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38"
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.4.0"
|
||||
@@ -141,6 +158,12 @@ dependencies = [
|
||||
"scopeguard",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.6.4"
|
||||
@@ -241,6 +264,12 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.69"
|
||||
@@ -259,6 +288,36 @@ dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"rand_chacha",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_chacha"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
||||
dependencies = [
|
||||
"ppv-lite86",
|
||||
"rand_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand_core"
|
||||
version = "0.6.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "redox_syscall"
|
||||
version = "0.4.1"
|
||||
@@ -338,6 +397,17 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "simplelog"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "acee08041c5de3d5048c8b3f6f13fafb3026b24ba43c6a695a0c76179b844369"
|
||||
dependencies = [
|
||||
"log",
|
||||
"termcolor",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smallvec"
|
||||
version = "1.11.2"
|
||||
@@ -365,6 +435,15 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termcolor"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
|
||||
dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.50"
|
||||
@@ -392,11 +471,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
"libc",
|
||||
"num_threads",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -405,6 +486,15 @@ version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ad70d68dba9e1f8aceda7aa6711965dfec1cac869f311a51bd08b3a2ccbce20"
|
||||
dependencies = [
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tokio"
|
||||
version = "1.34.0"
|
||||
@@ -460,6 +550,37 @@ version = "0.11.0+wasi-snapshot-preview1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.3.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
|
||||
dependencies = [
|
||||
"winapi-i686-pc-windows-gnu",
|
||||
"winapi-x86_64-pc-windows-gnu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-i686-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||
|
||||
[[package]]
|
||||
name = "winapi-util"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596"
|
||||
dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "winapi-x86_64-pc-windows-gnu"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.48.0"
|
||||
@@ -532,8 +653,11 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"nix",
|
||||
"rand",
|
||||
"regex",
|
||||
"simplelog",
|
||||
"thiserror",
|
||||
"time",
|
||||
"tokio",
|
||||
|
||||
18
Cargo.toml
18
Cargo.toml
@@ -5,11 +5,27 @@ edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[[bin]]
|
||||
name = "wmtest-helper-dummy"
|
||||
path = "src/bin/test-helper/dummy.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "wmtest-helper-spawner"
|
||||
path = "src/bin/test-helper/spawner.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "wmtest-helper-log"
|
||||
path = "src/bin/test-helper/log.rs"
|
||||
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.75"
|
||||
lazy_static = "1.4.0"
|
||||
nix = {version = "0.27.1", features = ["process", "signal", "fs"]}
|
||||
log = { version = "0.4.20", features = ["std"]}
|
||||
nix = { version = "0.27.1", features = ["process", "signal", "fs"]}
|
||||
rand = "0.8.5"
|
||||
regex = "1.10.2"
|
||||
simplelog = "0.12.1"
|
||||
thiserror = "1.0.50"
|
||||
time = { version = "0.3.30", features = ["local-offset"]}
|
||||
tokio = { version = "1.34.0", features = ["full"] }
|
||||
|
||||
25
docker/alpine/Dockerfile
Normal file
25
docker/alpine/Dockerfile
Normal file
@@ -0,0 +1,25 @@
|
||||
FROM rust:alpine as builder
|
||||
|
||||
ADD . /root/wingmate
|
||||
|
||||
WORKDIR /root/wingmate
|
||||
|
||||
RUN apk add musl-dev && cargo clean && \
|
||||
cargo build --release
|
||||
|
||||
FROM alpine
|
||||
|
||||
COPY --from=builder /root/wingmate/target/release/wingmate-rs /usr/local/bin/wingmate
|
||||
COPY --from=builder /root/wingmate/target/release/wmtest-helper-dummy /usr/local/bin/wmtest-helper-dummy
|
||||
COPY --from=builder /root/wingmate/target/release/wmtest-helper-spawner /usr/local/bin/wmtest-helper-spawner
|
||||
COPY --from=builder /root/wingmate/target/release/wmtest-helper-log /usr/local/bin/wmtest-helper-log
|
||||
|
||||
ADD docker/alpine/etc/ /etc/
|
||||
ADD docker/alpine/entry.sh /usr/local/bin/entry.sh
|
||||
|
||||
RUN chmod -R ugo+x /etc/wingmate && chmod +x /usr/local/bin/entry.sh && apk add tzdata && \
|
||||
ln -sv /usr/share/zoneinfo/Australia/Sydney /etc/localtime
|
||||
|
||||
ENTRYPOINT [ "/usr/local/bin/entry.sh" ]
|
||||
|
||||
CMD [ "/usr/local/bin/wingmate" ]
|
||||
7
docker/alpine/entry.sh
Normal file
7
docker/alpine/entry.sh
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ $# -gt 0 ];then
|
||||
exec "$@"
|
||||
else
|
||||
exec /usr/local/bin/wingmate
|
||||
fi
|
||||
3
docker/alpine/etc/wingmate/crontab
Normal file
3
docker/alpine/etc/wingmate/crontab
Normal file
@@ -0,0 +1,3 @@
|
||||
17 * * * * /etc/wingmate/crontab.d/cron1.sh
|
||||
*/5 * * * * /etc/wingmate/crontab.d/cron2.sh
|
||||
21,41 3,6,14,17,20,22 * * * /etc/wingmate/crontab.d/cron3.sh
|
||||
3
docker/alpine/etc/wingmate/crontab.d/cron1.sh
Normal file
3
docker/alpine/etc/wingmate/crontab.d/cron1.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
exec wmtest-helper-log /var/log/cron1.log "this cron runs every hour on minute 17"
|
||||
3
docker/alpine/etc/wingmate/crontab.d/cron2.sh
Normal file
3
docker/alpine/etc/wingmate/crontab.d/cron2.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
exec wmtest-helper-log /var/log/cron2.log "this cron runs every hour on minute 5,10,15,20,25,30,35,40,45,50,55"
|
||||
3
docker/alpine/etc/wingmate/crontab.d/cron3.sh
Normal file
3
docker/alpine/etc/wingmate/crontab.d/cron3.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
exec wmtest-helper-log /var/log/cron3.log "this cron runs based on this specification: 21,41 3,6,14,17,20,22 * * *"
|
||||
4
docker/alpine/etc/wingmate/services/one
Normal file
4
docker/alpine/etc/wingmate/services/one
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
export LOG_PATH=/var/log/one.log
|
||||
exec /usr/local/bin/wmtest-helper-spawner 10
|
||||
4
docker/alpine/etc/wingmate/services/three.sh
Normal file
4
docker/alpine/etc/wingmate/services/three.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
export LOG_PATH=/var/log/three.log
|
||||
exec /usr/local/bin/wmtest-helper-spawner 13
|
||||
4
docker/alpine/etc/wingmate/services/two.sh
Normal file
4
docker/alpine/etc/wingmate/services/two.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/bin/sh
|
||||
|
||||
export LOG_PATH=/var/log/two.log
|
||||
exec /usr/local/bin/wmtest-helper-spawner 4
|
||||
9
docker/dev/Dockerfile
Normal file
9
docker/dev/Dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ADD target/debug/init /usr/local/bin/init
|
||||
ADD docker/etc/ /etc/
|
||||
|
||||
RUN chmod ugo+x /etc/wingmate/services/one && chmod ugo+x /etc/wingmate/services/two.sh && \
|
||||
chmod ugo-x /etc/wingmate/services/three.sh
|
||||
|
||||
CMD [ "/usr/local/bin/init" ]
|
||||
3
docker/dev/etc/wingmate/crontab
Normal file
3
docker/dev/etc/wingmate/crontab
Normal file
@@ -0,0 +1,3 @@
|
||||
17 * * * * sleep 1
|
||||
*/12 * * * * sleep 1
|
||||
12,17,27 * * * * sleep 1
|
||||
1
docker/dev/etc/wingmate/services/one
Normal file
1
docker/dev/etc/wingmate/services/one
Normal file
@@ -0,0 +1 @@
|
||||
you cannot run this file
|
||||
3
docker/dev/etc/wingmate/services/three.sh
Normal file
3
docker/dev/etc/wingmate/services/three.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
exec sleep 1
|
||||
3
docker/dev/etc/wingmate/services/two.sh
Normal file
3
docker/dev/etc/wingmate/services/two.sh
Normal file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
exec sleep 1
|
||||
15
src/bin/test-helper/dummy.rs
Normal file
15
src/bin/test-helper/dummy.rs
Normal file
@@ -0,0 +1,15 @@
|
||||
use std::{env, thread, time};
|
||||
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let myi: u64;
|
||||
let args: Vec<String> = env::args().collect();
|
||||
if args.len() > 1 {
|
||||
myi = args[1].parse().unwrap();
|
||||
thread::sleep(time::Duration::from_secs(myi));
|
||||
} else {
|
||||
return Err(anyhow::anyhow!("invalid arguments").into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
19
src/bin/test-helper/log.rs
Normal file
19
src/bin/test-helper/log.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::io::Write;
|
||||
use time::OffsetDateTime;
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
if args.len() == 3 {
|
||||
let file = fs::OpenOptions::new().create(true).append(true).open(&args[1])?;
|
||||
let mut buf = io::BufWriter::new(file);
|
||||
let local_time = OffsetDateTime::now_local()?;
|
||||
buf.write_all(format!("{} {}\n", local_time, &args[2]).as_bytes())?;
|
||||
} else {
|
||||
return Err(anyhow::anyhow!("invalid argument").into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
46
src/bin/test-helper/spawner.rs
Normal file
46
src/bin/test-helper/spawner.rs
Normal file
@@ -0,0 +1,46 @@
|
||||
#[macro_use] extern crate log;
|
||||
extern crate simplelog;
|
||||
|
||||
use simplelog::*;
|
||||
|
||||
use std::error::Error;
|
||||
use std::fs::OpenOptions;
|
||||
use std::process::Command;
|
||||
use std::env;
|
||||
use rand::Rng;
|
||||
use nix::sys::signal;
|
||||
|
||||
fn main() -> Result<(), Box<dyn Error>> {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
unsafe {
|
||||
signal::signal(signal::Signal::SIGCHLD, signal::SigHandler::SigIgn)
|
||||
}.unwrap();
|
||||
|
||||
let mut rng = rand::thread_rng();
|
||||
|
||||
let log_path = env::var("LOG_PATH")?;
|
||||
let file = OpenOptions::new().append(true).create(true).open(log_path)?;
|
||||
WriteLogger::init(LevelFilter::Debug, Config::default(), file)?;
|
||||
|
||||
if args.len() > 1 {
|
||||
let x: u64 = args[1].parse()?;
|
||||
loop {
|
||||
for _i in 0..x {
|
||||
let sleep_time = rng.gen_range(10..20);
|
||||
info!("starting wmtest-helper-dummy {}", &sleep_time);
|
||||
let child = Command::new("/usr/local/bin/wmtest-helper-dummy").arg(format!("{}", sleep_time)).spawn();
|
||||
if let Err(e) = child {
|
||||
error!("error spawning child: {e}");
|
||||
}
|
||||
}
|
||||
|
||||
let pause_time = rng.gen_range(10..20);
|
||||
info!("going to sleep for {}", &pause_time);
|
||||
std::thread::sleep(std::time::Duration::from_secs(pause_time));
|
||||
info!("waking up")
|
||||
}
|
||||
} else {
|
||||
return Err(anyhow::anyhow!("invalid arguments").into());
|
||||
}
|
||||
}
|
||||
@@ -75,14 +75,11 @@ pub enum CronConfigError {
|
||||
#[error("setting day of week and day of month at the same time will lead to unexpected behavior")]
|
||||
ClashingConfig,
|
||||
|
||||
#[error("when setting time for higher order, the smallest (minute) muste be set")]
|
||||
MissingMinute,
|
||||
|
||||
#[error("something went wrong")]
|
||||
Other {
|
||||
#[source]
|
||||
source: anyhow::Error,
|
||||
}
|
||||
// #[error("something went wrong")]
|
||||
// Other {
|
||||
// #[source]
|
||||
// source: anyhow::Error,
|
||||
// }
|
||||
}
|
||||
|
||||
#[derive(Error,Debug)]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
mod init;
|
||||
|
||||
use std::error;
|
||||
use wingmate_rs::init;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn error::Error>> {
|
||||
Reference in New Issue
Block a user