OpenVZ Forum


Home » Mailing lists » Devel » [WISH] exec early script at start
Re: [vzctl] exec early script at start [message #25762 is a reply to message #25031] Tue, 08 January 2008 16:32 Go to previous messageGo to previous message
Yoann Moulin is currently offline  Yoann Moulin
Messages: 16
Registered: December 2007
Junior Member
Yoann Moulin a écrit :
> Hi all,
> 
> I'm working on a xen to openvz migration, and I still have some issue to 
> fix. but some seem to be not possible yet.
> 
> actually, on our diskless servers (xen and others), we are using 
> nfsroot. And at start, in the initrd, we are using a script that make a 
> connexion on the nfs boot server and remove the old root, create a new 
> one, take the last system image build, and re apply configuration with 
> cfengine tools.
> 
> I'd like to do the same with openvz, but I didn't see in the source this 
> possibility.
> 
> it could be someting like in src/lib/env.c in the vps_start_custom 
> function (in pseudo code) :

> I didn't do C for a while, so I'm not sure I'll be able to do something 
> simple and safe.
> 
> I'm available to compile and test this until the openvz server should be 
> production at the end of next week... but I'll take the time to do all 
> the test we need before.
> 
> If some can help me on this issue.

I have patched env.c to be able to execute a script before starting a VE

I don't know if it is the best way to do that, but it work for what I need

regards,

Yoann

diff -r -u a/vzctl-3.0.22/include/vzerror.h b/vzctl-3.0.22/include/vzerror.h
--- a/vzctl-3.0.22/include/vzerror.h	2007-12-17 14:44:21.000000000 +0100
+++ b/vzctl-3.0.22/include/vzerror.h	2008-01-08 12:53:25.000000000 +0100
@@ -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 -r -u a/vzctl-3.0.22/src/lib/env.c b/vzctl-3.0.22/src/lib/env.c
--- a/vzctl-3.0.22/src/lib/env.c	2007-12-17 14:44:21.000000000 +0100
+++ b/vzctl-3.0.22/src/lib/env.c	2008-01-08 17:18:14.786271752 +0100
@@ -545,12 +545,15 @@
 {
 	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"))
@@ -559,6 +562,28 @@
 		logger(-1, 0, "VE 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);
@@ -661,6 +686,7 @@
 	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:03:37 GMT 2024

Total time taken to generate the page: 0.04976 seconds