OpenVZ Forum


Home » Mailing lists » Devel » [WISH] exec early script at start
Re: [vzctl] exec early script at start [message #29708 is a reply to message #26152] Tue, 22 April 2008 13:35 Go to previous message
Yoann Moulin is currently offline  Yoann Moulin
Messages: 16
Registered: December 2007
Junior Member
> PS the best way to do patches is to use git.

in attachment, the patch generate with git

Regards

Yoann

diff --git a/include/vzerror.h b/include/vzerror.h
index 00d1c47..9d665d2 100644
--- a/include/vzerror.h
+++ b/include/vzerror.h
@@ -63,7 +63,7 @@
 #define VZ_CANT_ADDIP			34
 #define VZ_VALIDATE_ERROR		35
 #define VZ_OVERCOMMIT_ERROR		36
-
+#define VZ_EARLY_SCRIPT_ERROR		37
 /****************************
     Filesystem errros
  ****************************/
diff --git a/src/lib/env.c b/src/lib/env.c
index 7411504..e1beac4 100644
--- a/src/lib/env.c
+++ b/src/lib/env.c
@@ -547,12 +547,15 @@ int vps_start_custom(vps_handler *h, envid_t veid, vps_param *param,
 {
 	int wait_p[2];
 	int err_p[2];
-	int ret, err;
+	int ret, err,early_p;
 	char buf[64];
 	char *dist_name;
 	struct sigaction act;
+	char *command;
+	char *early_script;
 	vps_res *res = &param->res;
 	dist_actions actions;
+        early_script = strdup("/etc/vz/early_script.sh");
 
 	memset(&actions, 0, sizeof(actions));
 	if (check_var(res->fs.root, "VE_ROOT is not set"))
@@ -561,6 +564,28 @@ int vps_start_custom(vps_handler *h, envid_t veid, vps_param *param,
 		logger(-1, 0, "Container is already running");
 		return VZ_VE_RUNNING;
 	}
+
+	if (early_script == NULL) {
+		logger(-1,0,"memory allocation error for early_script");
+		return VZ_EARLY_SCRIPT_ERROR;
+	}	
+
+	early_p = open(early_script,O_RDONLY);	
+	if ( early_p != -1 ) {
+		logger(0, 0, "early_script.sh started");
+		command = (char*)malloc(3+strlen(early_script)+1+10);
+		sprintf(command,"sh %s %d",early_script,veid);
+		if ( system(command) == 0 ) {
+			logger(0, 0, "early_script.sh finished");
+		} else {
+			logger(-1, 0, "early_script.sh failed");
+			return VZ_EARLY_SCRIPT_ERROR;
+		}
+		free(command);
+	} else {
+		logger(0, 0, "early_script.sh does not exist or is not readable ");
+	}
+	
 	if ((ret = check_ub(&res->ub)))
 		return ret;
 	dist_name = get_dist_name(&res->tmpl);
@@ -663,6 +688,7 @@ err:
 	close(wait_p[1]);
 	close(err_p[0]);
 	close(err_p[1]);
+	close(early_p);
 
 	return ret;
 }
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [RFC][-mm] Memory controller hierarchy support (v1)
Next Topic: To install OpenVZ in an Oracle installed system
Goto Forum:
  


Current Time: Tue Oct 15 19:05:55 GMT 2024

Total time taken to generate the page: 0.05138 seconds