beterraba

commit 1cf74e9a2a6d2cf65b76706a38289399cf5ce0e6

Author: Pedro Lucas Porcellis <porcellis@eletrotupi.com>

server: actually start services instead of spawning the dummy one

 cmd/beterrabad/executor.ha | 50 ++++++++++++++++++++--------------------
 cmd/beterrabad/socket.ha | 2 


diff --git a/cmd/beterrabad/executor.ha b/cmd/beterrabad/executor.ha
index 4d57a8d3891e74d9b14617ea886755c66cffe143..c801811639e0186ba9fbec02dfa97fb3a9a5d5bd 100644
--- a/cmd/beterrabad/executor.ha
+++ b/cmd/beterrabad/executor.ha
@@ -11,28 +11,26 @@ fn status_service(cmdargs: str) str = {
 	return "TODO";
 };
 
-fn start_service(cmdargs: str) str = {
-	let dummy_serv: beterraba::servdef = beterraba::servdef {
-		name = "Dummy",
-		desc = "Dummy",
-		cmd = "bash",
-		args = "-c ~/test.sh",
-		...
-	};
+fn start_service(svcname: str, serv: *server) str = {
+	let service: nullable *beterraba::service = null;
 
-	let service = beterraba::service {
-		name = "Dummy",
-		desc = "DUmmy",
-		definition = dummy_serv,
-		status = beterraba::status::STOPPED,
-		...
+	for (let i = 0z; i < len(serv.services); i += 1) {
+		if (serv.services[i].name == svcname) {
+			service = &serv.services[i];
+			break;
+		};
 	};
 
-	match (boot(&service)) {
-	case let err: booterror =>
-		return bootstrerror(err);
-	case void =>
-		return "Started successfully";
+	match (service) {
+	case null =>
+		return "Didn't find a service with that name";
+	case let svc: *beterraba::service =>
+		match (boot(svc)) {
+		case let err: booterror =>
+			return bootstrerror(err);
+		case void =>
+			return "Started successfully";
+		};
 	};
 };
 
@@ -80,6 +78,8 @@ // XXX: This method should yield a booterror which we should eventually
 // translate it back to a str, the same goes to other methods
 fn boot(service: *beterraba::service) (void | booterror) = {
 	log::printfln("Booting up {}", service.name);
+	log::printfln("Booting up with cmd {} and args {}",
+		service.definition.cmd, service.definition.args);
 
 	match (exec::fork()) {
 	case let childpid: int =>
@@ -89,23 +89,23 @@ 			log::printfln("Starting process {}", service.name);
 	case let err: exec::error =>
 		return err;
 	case void =>
-		let cmd = exec::cmd("bash", "-c", "~/test.sh");
+		let cmd = exec::cmd(service.definition.cmd,
+			service.definition.args);
 
 		match (cmd) {
 		case let cmddef: exec::command =>
 			exec::exec(&cmddef);
 		case exec::nocmd =>
-			fmt::printfln("Couldn't build cmd {}", service.definition.cmd)!;
+			fmt::printfln("Couldn't build cmd {}",
+				service.definition.cmd)!;
 		case exec::error =>
 			service.status = beterraba::status::CRASHED;
-			fmt::printfln("Couldn't execute cmd {}, error", service.definition.cmd)!;
+			fmt::printfln("Couldn't execute cmd {}, error",
+				service.definition.cmd)!;
 		case =>
 			fmt::println("Something went terrible wrong, good luck!")!;
 		};
 	};
-
-	//let cmd = exec::cmd(service.definition.cmd, service.definition.args);
-	let cmd = exec::cmd("bash", "-c", "~/test.sh");
 };
 
 fn bootstrerror(err: booterror) const str = {




diff --git a/cmd/beterrabad/socket.ha b/cmd/beterrabad/socket.ha
index 7b316991939b7fda7ce543cf523f8c0029d1e7a5..c53a715c5a9dbf9ba1de2c36408f14b45f04ba6c 100644
--- a/cmd/beterrabad/socket.ha
+++ b/cmd/beterrabad/socket.ha
@@ -191,7 +191,7 @@
 	// TODO: Flesh out command execution here
 	switch (cmd) {
 	case "start" =>
-		let status = start_service(args);
+		let status = start_service(args, server);
 		fmt::fprintf(&buf, status)?;
 	case "status" =>
 		let status = status_service(args);