Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y \
nginx \
&& rm -rf /var/lib/apt/lists/*

RUN groupadd taskmaster
RUN rustup component add rustfmt clippy

RUN echo 'export PS1="\W> "' >> ~/.bashrc
18 changes: 18 additions & 0 deletions config/autorestart.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[processes.no]
workingdir = "."
cmd = "/usr/bin/ls"
autorestart = "no"
autostart = true

[processes.always]
workingdir = "."
cmd = "/usr/bin/ls"
autorestart = "always"
autostart = true

[processes.on-failure]
workingdir = "."
cmd = "/usr/bin/ls"
autorestart = "on-failure[:5]"
exitcodes = [1]
autostart = true
9 changes: 9 additions & 0 deletions config/autostart.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[processes.autostart]
cmd = "/usr/bin/ls"
workingdir = "."
autostart = true

[processes.notautostart]
cmd = "/usr/bin/ls"
workingdir = "."
autostart = false
5 changes: 5 additions & 0 deletions config/command.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[processes.command]

cmd = "/usr/bin/echo"
args = ["Hello, World!"]
workingdir = "."
11 changes: 11 additions & 0 deletions config/duplicatestdout.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[processes.no]
workingdir = "."
cmd = "/usr/bin/ls"
stdout = "asd"
autostart = true

[processes.always]
workingdir = "."
cmd = "/usr/bin/ls"
stdout = "asd"
autostart = true
7 changes: 7 additions & 0 deletions config/env.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[processes.env]

cmd = "/bin/bash"
args = ["executables/env.sh"]
env = [["HELLO", "WORLD"]]
workingdir = "."
stdout = "/tmp/env.stdout"
3 changes: 0 additions & 3 deletions config/example.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
socketpath = "/tmp/.taskmaster.sock"
authgroup = "winstonallo"

[processes.sleep]
cmd = "/usr/bin/sleep"
args = ["1"]
Expand Down
13 changes: 13 additions & 0 deletions config/exitcode.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[processes.success]
cmd = "/bin/bash"
args = ["-c", "exit 0"]
workingdir = "."
exitcodes = [0]
autostart = true

[processes.failure]
cmd = "/bin/bash"
args = ["-c", "exit 1"]
workingdir = "."
exitcodes = [0]
autostart = true
3 changes: 0 additions & 3 deletions config/felix.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
socketpath = "/tmp/taskmaster.sock"
authgroup = "root"

[processes.sleep]
cmd = "/bin/sleep"
args = ["3"]
Expand Down
5 changes: 1 addition & 4 deletions config/healthcheck.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
socketpath = "/tmp/.taskmaster.sock"


[processes.sleep]

cmd = "/usr/bin/sleep"
Expand All @@ -20,5 +17,5 @@ env = [["STARTED_BY", "abied-ch"], ["ANSWER", "42"]]
cmd = "/usr/bin/sleep"
args = ["2"]
backoff = 1
timeout = 1
timeout = 5
retries = 1
2 changes: 0 additions & 2 deletions config/privilege_deescalation.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
authgroup = "root"

[processes.root]

cmd = "/usr/bin/id"
Expand Down
8 changes: 8 additions & 0 deletions config/processes.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[processes.processes]

cmd = "/usr/bin/sleep"
args = ["1"]
workingdir = "."
autorestart = "no"
autostart = true
processes = 10
9 changes: 3 additions & 6 deletions config/attach.toml → config/redirect.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
socketpath = "/tmp/taskmaster.sock"
authgroup = "winstonallo"

[processes.sleepwrite]
cmd = "/usr/bin/python3"
args = ["/home/winstonallo/mastery/taskmaster/executables/sleepwrite.py"]
args = ["executables/sleepwrite.py"]
processes = 1
umask = "022"
workingdir = "/tmp"
workingdir = "."
autostart = true
autorestart = "always"
exitcodes = [0, 2]
exitcodes = [0]
stopsignals = ["USR1"]
stoptime = 5
stdout = "/tmp/sleepwrite.stdout"
Expand Down
21 changes: 21 additions & 0 deletions config/retries.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[processes.retries_1]
cmd = "/usr/bin/sleep"
args = ["1"]
workingdir = "."
autostart = true
exitcodes = [1]
[processes.retries_1.healthcheck]
starttime = 2
retries = 1
backoff = 2

[processes.retries_5]
cmd = "/usr/bin/sleep"
args = ["1"]
workingdir = "."
autostart = true
exitcodes = [1]
[processes.retries_5.healthcheck]
starttime = 2
retries = 5
backoff = 2
4 changes: 2 additions & 2 deletions config/signal.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
authgroup = "winstonallo"

[processes.signal]

cmd = "/usr/bin/python3"
args = ["executables/signals.py"]
workingdir = "."
autostart = true
stopsignals = ["TERM", "USR1", "ILL"]
stdout = "/tmp/signal.stdout"
9 changes: 9 additions & 0 deletions config/stoptime.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[processes.signal]

cmd = "/usr/bin/python3"
args = ["executables/signals.py"]
workingdir = "."
autostart = true
stopsignals = ["TERM", "USR1", "ILL"]
stoptime = 5
stdout = "/tmp/signal.stdout"
15 changes: 15 additions & 0 deletions config/umask.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[processes.000]

cmd = "/usr/bin/touch"
args = ["000"]
workingdir = "."
autostart = true
umask = "000"

[processes.022]

cmd = "/usr/bin/touch"
args = ["022"]
workingdir = "."
autostart = true
umask = "022"
1 change: 0 additions & 1 deletion config/unexisting_group.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
authgroup = "asdpihgasbldkjalshdbliasjdlkasbdasd"

[processes.sleep]
cmd = "/usr/bin/sleep"
Expand Down
17 changes: 17 additions & 0 deletions config/uptime.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[processes.uptime_success]
cmd = "/usr/bin/sleep"
args = ["10"]
workingdir = "."
autostart = true
[processes.uptime_success.healthcheck]
starttime = 2

[processes.uptime_failure]
cmd = "/usr/bin/sleep"
args = ["1"]
workingdir = "."
autostart = true
exitcodes = [1]
[processes.uptime_failure.healthcheck]
starttime = 2
retries = 1
13 changes: 13 additions & 0 deletions config/workingdir.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[processes.workingdir_dot]

cmd = "/usr/bin/pwd"
workingdir = "."
stdout = "/tmp/workingdir_dot.stdout"
autostart = true

[processes.workingdir_tmp]

cmd = "/usr/bin/pwd"
workingdir = "/tmp"
stdout = "/tmp/workingdir_tmp.stdout"
autostart = true
1 change: 1 addition & 0 deletions executables/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
echo $HELLO
12 changes: 1 addition & 11 deletions src/bin/taskmaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@ use std::{
env::{self},
error::Error,
fs::remove_file,
io::Write,
};

use tasklib::{conf::Config, log, log_info, run::daemon::Daemon};

const PID_FILE_PATH: &str = "/tmp/taskmaster.pid";

fn write_pid_file() -> Result<(), Box<dyn Error>> {
let pid = unsafe { libc::getpid() };
let mut pid_file = std::fs::File::create(PID_FILE_PATH)?;
pid_file.write_all(pid.to_string().as_bytes())?;
Ok(())
}
pub const PID_FILE_PATH: &str = "/tmp/taskmaster.pid";

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
Expand All @@ -40,8 +32,6 @@ async fn main() -> Result<(), Box<dyn Error>> {
}
};

write_pid_file()?;

log::init(conf.logfile())?;

let mut daemon = Daemon::from_config(conf, arg);
Expand Down
2 changes: 1 addition & 1 deletion src/bin/taskshell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ async fn attach(name: &str, socket_path: &str, to: &str, mut orig: Option<&mut l
let stream = match UnixStream::connect(socket_path).await {
Ok(stream) => stream,
Err(e) => {
eprintln!("could not establish connection on attach socket at path {socket_path}: {e}");
eprintln!("Could not establish connection on attach socket at path {socket_path}: {e}.\nIs the process running?");
return "".to_string();
}
};
Expand Down
Loading