Created
May 24, 2012 11:16
-
-
Save FeepingCreature/2780868 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module restarter; | |
import std.string, std.file, std.thread, std.time, std.fun; | |
extern(C) { | |
alias pid_t = int; | |
pid_t fork(); | |
int execv(char* path, char** argv); | |
pid_t waitpid(pid_t, int* status, int options); | |
} | |
void main() { | |
auto serverlist = string: readAll "serverlist.txt" | |
#.split("\n") | |
#.select(\(string s) -> !s.startsWith("#")) | |
#.map \(string s) -> s.split(" ") | |
#.eval[]; | |
auto tp = new ThreadPool serverlist.length; | |
for auto entry <- serverlist { | |
tp.addTask new \{ | |
while (true) { | |
auto pid = fork(); | |
if (!pid) { | |
char*[auto~] argv; | |
argv ~= char*:"idc"; | |
for auto arg <- entry argv ~= toStringz arg; | |
argv ~= null; | |
execv("idc", argv.ptr); | |
} | |
waitpid(pid, null, 0); | |
writeln "idc $entry terminated. Restarting in 5 .. "; | |
for (int i = 4; i > 0; --i) { sleep 1; writeln "$i .. "; } | |
} | |
} | |
} | |
tp.waitComplete; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment