Skip to content

Commit

Permalink
feat(bootstrap): add bootstrap commands to allow Meproc to automatica…
Browse files Browse the repository at this point in the history
…lly run given shell command on startup
  • Loading branch information
Water-Melon committed Nov 14, 2023
1 parent 3d9cc25 commit 4d123ca
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ Conf = [
'ip': '127.0.0.1',
'port': '8606',
],
'bootstrap_cmd': '',
];
```

Expand Down
9 changes: 9 additions & 0 deletions bootstrap.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "@/log.m"

sys = Import('sys');

if (Conf['bootstrap_cmd']) {
Log('info', 'running command [' + Conf['bootstrap_cmd'] + '] ...');
sys.msleep(1000);
sys.exec(Conf['bootstrap_cmd'], -1, pid, nil, nil, 'bootstrap');
} fi
1 change: 1 addition & 0 deletions conf/conf.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'ip': '127.0.0.1',
'port': '8606',
],
'bootstrap_cmd': '',
];

/*
Expand Down
3 changes: 2 additions & 1 deletion meproc.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
return;
} fi

Log('info', "Meproc v1.0.0. Listen on: " + Conf['ip'] + ':' + Conf['port']);
Log('info', "Meproc v1.0.1. Listen on: " + Conf['ip'] + ':' + Conf['port']);

Eval('@/http.m');
Eval('@/bootstrap.m', nil, false, 'bootstrap');

while (1) {
fd = net.tcp_accept(listenfd);
Expand Down
7 changes: 7 additions & 0 deletions proc.m
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@
n = S.size(list);
for (i = 0; i < n; ++i) {
name = Str.slice(list[i]['alias'], ':')[0];
if (name == 'bootstrap')
continue;
fi
if (!S.has(Tasks, name) || !Tasks[name]) {
Log('error', "Task [" + name + "] is running but not in Tasks");
continue;
Expand Down Expand Up @@ -358,5 +361,9 @@
} fi
}
}
data = Mq.recv('bootstrap', 1);
if (data) {
TaskLog('bootstrap', data);
} fi
}

0 comments on commit 4d123ca

Please sign in to comment.