Dnia środa, 2 maja 2012 00:43:06 Łukasz Mierzwa pisze:
> Dnia wtorek, 1 maja 2012 08:14:05 Roberto De Ioris pisze:
> > Sorry, exec-in-jail run before fs-rebuilt so whatever you do will be
> > overwritten.
> > Use --exec-as-root, it will be triggered before privileges drop in the
> > jail.
> > 
> > Remember that you have no stdin, and stdout/stderr are mapped to uWSGI
> > log.
> 
> It works with exec-in-jail = mfsmount <mount options>.
> The only issue remaining is that mfsmount is a client daemon for MooseFS
> mount and it runs all the time in the background. During vassal
> shutdown/reload uWSGI hangs waiting for mfsmount to die (if I kill mfsmount
> than it reloads, but only then). uWSGI doesn't seem to send any signal to
> it, I guess that it doesn't expect exec-as-root command to be long living
> process and all it does is to run it and wait untill it is terminated.
> Is there a way to execute something also at exit time so that I can umount
> my MooseFs (mfsmount would die)?

I've managed to get around that by:

# add fuse perms for www-data user
chgrp www-data /chroot/dev/fuse

# allow non-root users to mount fuse filesystems
echo user_allow_other > /chroot/etc/fuse.conf

# create MooseFS mount dir
mkdir /chroot/mfs
chown www-data:www-data /chroot/mfs

in my vassal config I have now:

exec-as-user = mfsmount /mfs -o <mfs options>
exec-as-user-atexit = fusermount -u /mfs

Since there is now uWSGI option to run any command at worker exit, I had to 
write very simple patch that adds this. There is no way to run that command as 
root since this is done after privileges drop so the command is being run as 
user (unless someone runs workers as root user).

Does this patch qualifies for merging into uWSGI?

Łukasz Mierzwa
diff -r c3cdecbf2bac uwsgi.c
--- a/uwsgi.c	Mon Apr 30 11:05:08 2012 +0200
+++ b/uwsgi.c	Wed May 02 11:19:42 2012 +0200
@@ -218,6 +218,7 @@
 	{"exec-in-jail", required_argument,0, "run the specified command in jail after initialization", uwsgi_opt_add_string_list, &uwsgi.exec_in_jail,0},
 	{"exec-as-root", required_argument,0, "run the specified command before privileges drop", uwsgi_opt_add_string_list, &uwsgi.exec_as_root,0},
 	{"exec-as-user", required_argument,0, "run the specified command after privileges drop", uwsgi_opt_add_string_list, &uwsgi.exec_as_user,0},
+	{"exec-as-user-atexit", required_argument,0, "run the specified command before worker exit", uwsgi_opt_add_string_list, &uwsgi.exec_as_user_atexit,0},
 	{"exec-pre-app", required_argument,0, "run the specified command before app loading", uwsgi_opt_add_string_list, &uwsgi.exec_pre_app,0},
 #ifdef UWSGI_INI
 	{"ini", required_argument, 0, "load config from ini file", uwsgi_opt_load_ini, NULL, UWSGI_OPT_IMMEDIATE},
@@ -961,6 +962,23 @@
 	.after_request = unconfigured_after_hook,
 };
 
+static void exec_atexit(void) {
+
+	if (uwsgi.exec_as_user_atexit) {
+		// now run the scripts needed by the user
+		struct uwsgi_string_list *usl = uwsgi.exec_as_user_atexit;
+		while(usl) {
+			uwsgi_log("running \"%s\" (as uid: %d gid: %d) ...\n", usl->value, (int) getuid(), (int) getgid());
+			int ret = uwsgi_run_command_and_wait(NULL, usl->value);
+			if (ret != 0) {
+				uwsgi_log("command \"%s\" exited with non-zero code: %d\n", usl->value, ret);
+			}
+			usl = usl->next;
+		}
+	}
+
+}
+
 static void vacuum(void) {
 
 	struct uwsgi_socket *uwsgi_sock = uwsgi.sockets;
@@ -1272,6 +1290,7 @@
 
 	init_magic_table(uwsgi.magic_table);
 
+	atexit(exec_atexit);
 	atexit(uwsgi_flush_logs);
 	atexit(vacuum);
 	atexit(uwsgi_plugins_atexit);
diff -r c3cdecbf2bac uwsgi.h
--- a/uwsgi.h	Mon Apr 30 11:05:08 2012 +0200
+++ b/uwsgi.h	Wed May 02 11:19:42 2012 +0200
@@ -1264,6 +1264,7 @@
 	struct uwsgi_string_list *exec_in_jail;
 	struct uwsgi_string_list *exec_as_root;
 	struct uwsgi_string_list *exec_as_user;
+	struct uwsgi_string_list *exec_as_user_atexit;
 	struct uwsgi_string_list *exec_pre_app;
 
 	struct uwsgi_logger *loggers;
@@ -1486,6 +1487,7 @@
 	char *chdir2;
 
 	int vacuum;
+	int exec_atexit;
 	int no_server;
 	int command_mode;
 
_______________________________________________
uWSGI mailing list
[email protected]
http://lists.unbit.it/cgi-bin/mailman/listinfo/uwsgi

Reply via email to