mirror of
https://github.com/clearlinux/uwsgi.git
synced 2026-09-04 20:51:29 +00:00
Merge pull request #800 from janos/master
Write pidfile and pidfile2 only after successful start
This commit is contained in:
+2
-2
@@ -40,8 +40,8 @@ class Command(BaseCommand):
|
||||
elif self.socket_addr:
|
||||
os.environ['UWSGI_SOCKET'] = self.socket_addr
|
||||
|
||||
# map admin static files
|
||||
os.environ['UWSGI_STATIC_MAP'] = '%s=%s' % (settings.ADMIN_MEDIA_PREFIX, os.path.join(django.__path__[0], 'contrib', 'admin', 'media'))
|
||||
# map admin static files
|
||||
os.environ['UWSGI_STATIC_MAP'] = '%s=%s' % (settings.ADMIN_MEDIA_PREFIX, os.path.join(django.__path__[0], 'contrib', 'admin', 'media'))
|
||||
# remove sockets/pidfile at exit
|
||||
os.environ['UWSGI_VACUUM'] = '1'
|
||||
# retrieve/set the PythonHome
|
||||
|
||||
+33
-33
@@ -12,7 +12,7 @@ class uWSGIClientResource(resource.LeafResource):
|
||||
resource.LeafResource.__init__(self)
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.app = app
|
||||
self.app = app
|
||||
|
||||
def renderHTTP(self, request):
|
||||
return uWSGI(request, self.app, self.host, self.port)
|
||||
@@ -33,52 +33,52 @@ class uWSGIClientProtocol(basic.LineReceiver):
|
||||
self.deferred = deferred
|
||||
self.stream = stream.ProducerStream()
|
||||
self.response = http.Response(stream=self.stream)
|
||||
self.status_parsed = None
|
||||
self.status_parsed = None
|
||||
|
||||
def build_uwsgi_var(self,key,value):
|
||||
return struct.pack('<H',len(key)) + key + struct.pack('<H',len(value)) + value
|
||||
return struct.pack('<H',len(key)) + key + struct.pack('<H',len(value)) + value
|
||||
|
||||
def connectionMade(self):
|
||||
print self.request.__dict__
|
||||
# reset response parser
|
||||
self.status_parsed = None
|
||||
# build header and vars
|
||||
vars = ''
|
||||
print(self.request.__dict__)
|
||||
# reset response parser
|
||||
self.status_parsed = None
|
||||
# build header and vars
|
||||
vars = ''
|
||||
|
||||
if self.request.stream.length:
|
||||
vars += self.build_uwsgi_var('CONTENT_LENGTH',str(self.request.stream.length))
|
||||
if self.request.stream.length:
|
||||
vars += self.build_uwsgi_var('CONTENT_LENGTH',str(self.request.stream.length))
|
||||
|
||||
for hkey, hval in self.request.headers.getAllRawHeaders():
|
||||
# use a list, probably it will be extended
|
||||
if hkey.lower() not in ('content-type'):
|
||||
vars += self.build_uwsgi_var('HTTP_'+hkey.upper().replace('-','_'),','.join(hval))
|
||||
else:
|
||||
vars += self.build_uwsgi_var(hkey.upper().replace('-','_'),','.join(hval))
|
||||
|
||||
for hkey, hval in self.request.headers.getAllRawHeaders():
|
||||
# use a list, probably it will be extended
|
||||
if hkey.lower() not in ('content-type'):
|
||||
vars += self.build_uwsgi_var('HTTP_'+hkey.upper().replace('-','_'),','.join(hval))
|
||||
else:
|
||||
vars += self.build_uwsgi_var(hkey.upper().replace('-','_'),','.join(hval))
|
||||
|
||||
|
||||
vars += self.build_uwsgi_var('REQUEST_METHOD', self.request.method)
|
||||
vars += self.build_uwsgi_var('SCRIPT_NAME', self.request.uwsgi_app)
|
||||
vars += self.build_uwsgi_var('PATH_INFO', self.request.path[len(self.request.uwsgi_app):])
|
||||
vars += self.build_uwsgi_var('QUERY_STRING', self.request.querystring)
|
||||
vars += self.build_uwsgi_var('SERVER_NAME', self.request.host)
|
||||
vars += self.build_uwsgi_var('SERVER_PORT', str(self.request.port))
|
||||
vars += self.build_uwsgi_var('SERVER_PROTOCOL', self.request.scheme.upper()+'/'+str(self.request.clientproto[0]) +'.'+str(self.request.clientproto[1]))
|
||||
vars += self.build_uwsgi_var('REQUEST_METHOD', self.request.method)
|
||||
vars += self.build_uwsgi_var('SCRIPT_NAME', self.request.uwsgi_app)
|
||||
vars += self.build_uwsgi_var('PATH_INFO', self.request.path[len(self.request.uwsgi_app):])
|
||||
vars += self.build_uwsgi_var('QUERY_STRING', self.request.querystring)
|
||||
vars += self.build_uwsgi_var('SERVER_NAME', self.request.host)
|
||||
vars += self.build_uwsgi_var('SERVER_PORT', str(self.request.port))
|
||||
vars += self.build_uwsgi_var('SERVER_PROTOCOL', self.request.scheme.upper()+'/'+str(self.request.clientproto[0]) +'.'+str(self.request.clientproto[1]))
|
||||
|
||||
vars += self.build_uwsgi_var('REQUEST_URI', self.request.uri)
|
||||
vars += self.build_uwsgi_var('REMOTE_ADDR', self.request.remoteAddr.host)
|
||||
vars += self.build_uwsgi_var('REQUEST_URI', self.request.uri)
|
||||
vars += self.build_uwsgi_var('REMOTE_ADDR', self.request.remoteAddr.host)
|
||||
|
||||
|
||||
self.transport.write(struct.pack('<BHB',0, len(vars),0))
|
||||
self.transport.write(vars)
|
||||
self.transport.write(struct.pack('<BHB',0, len(vars),0))
|
||||
self.transport.write(vars)
|
||||
|
||||
# send request data
|
||||
# send request data
|
||||
stream.StreamProducer(self.request.stream).beginProducing(self.transport)
|
||||
|
||||
def lineReceived(self, line):
|
||||
if self.status_parsed is None:
|
||||
self.response.code = line.split(' ',2)[1]
|
||||
self.status_parsed = True
|
||||
return
|
||||
if self.status_parsed is None:
|
||||
self.response.code = line.split(' ',2)[1]
|
||||
self.status_parsed = True
|
||||
return
|
||||
|
||||
# end of headers
|
||||
if line == '':
|
||||
|
||||
@@ -85,20 +85,20 @@ class Cache:
|
||||
|
||||
def show_dump(self):
|
||||
d = self.dump()
|
||||
print
|
||||
print "Recorded %d samples (%d second(s) sleep between samples)" % \
|
||||
(d['samples'], d['sample_sleep'])
|
||||
print "Cache empty %d times, full %d times, %.2f items on average" % \
|
||||
(d['cache_empty'], d['cache_full'], d['cache_items'] / d['samples'])
|
||||
print "Block size average size: %d bytes" % \
|
||||
(d['block_sizes'] / d['cache_items'] * 8)
|
||||
print "Data in cache average: %d bytes" % \
|
||||
(d['block_sizes'] / d['samples'] * 8)
|
||||
print()
|
||||
print("Recorded %d samples (%d second(s) sleep between samples)" % \
|
||||
(d['samples'], d['sample_sleep']))
|
||||
print("Cache empty %d times, full %d times, %.2f items on average" % \
|
||||
(d['cache_empty'], d['cache_full'], d['cache_items'] / d['samples']))
|
||||
print("Block size average size: %d bytes" % \
|
||||
(d['block_sizes'] / d['cache_items'] * 8))
|
||||
print("Data in cache average: %d bytes" % \
|
||||
(d['block_sizes'] / d['samples'] * 8))
|
||||
|
||||
def main(options):
|
||||
cache = Cache(options.cache_store, options.cache_slots, options.block_size,
|
||||
options.sleep_time)
|
||||
print "Recording..."
|
||||
print("Recording...")
|
||||
while True:
|
||||
try:
|
||||
data = cache.read()
|
||||
|
||||
@@ -3587,6 +3587,13 @@ void uwsgi_write_pidfile(char *pidfile_name) {
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_write_pidfile_explicit(char *pidfile_name, pid_t pid) {
|
||||
uwsgi_log("writing pidfile to %s\n", pidfile_name);
|
||||
if (uwsgi_write_intfile(pidfile_name, (int) pid)) {
|
||||
uwsgi_log("could not write pidfile.\n");
|
||||
}
|
||||
}
|
||||
|
||||
char *uwsgi_expand_path(char *dir, int dir_len, char *ptr) {
|
||||
char src[PATH_MAX + 1];
|
||||
memcpy(src, dir, dir_len);
|
||||
|
||||
@@ -354,6 +354,8 @@ static struct uwsgi_option uwsgi_base_options[] = {
|
||||
|
||||
{"pidfile", required_argument, 0, "create pidfile (before privileges drop)", uwsgi_opt_set_str, &uwsgi.pidfile, 0},
|
||||
{"pidfile2", required_argument, 0, "create pidfile (after privileges drop)", uwsgi_opt_set_str, &uwsgi.pidfile2, 0},
|
||||
{"safe-pidfile", required_argument, 0, "create safe pidfile (before privileges drop)", uwsgi_opt_set_str, &uwsgi.safe_pidfile, 0},
|
||||
{"safe-pidfile2", required_argument, 0, "create safe pidfile (after privileges drop)", uwsgi_opt_set_str, &uwsgi.safe_pidfile2, 0},
|
||||
{"chroot", required_argument, 0, "chroot() to the specified directory", uwsgi_opt_set_str, &uwsgi.chroot, 0},
|
||||
#ifdef __linux__
|
||||
{"pivot-root", required_argument, 0, "pivot_root() to the specified directories (new_root and put_old must be separated with a space)", uwsgi_opt_set_str, &uwsgi.pivot_root, 0},
|
||||
@@ -1604,6 +1606,22 @@ static void vacuum(void) {
|
||||
uwsgi_log("VACUUM: pidfile2 removed.\n");
|
||||
}
|
||||
}
|
||||
if (uwsgi.safe_pidfile && !uwsgi.uid) {
|
||||
if (unlink(uwsgi.safe_pidfile)) {
|
||||
uwsgi_error("unlink()");
|
||||
}
|
||||
else {
|
||||
uwsgi_log("VACUUM: safe pidfile removed.\n");
|
||||
}
|
||||
}
|
||||
if (uwsgi.safe_pidfile2) {
|
||||
if (unlink(uwsgi.safe_pidfile2)) {
|
||||
uwsgi_error("unlink()");
|
||||
}
|
||||
else {
|
||||
uwsgi_log("VACUUM: safe pidfile2 removed.\n");
|
||||
}
|
||||
}
|
||||
if (uwsgi.chdir) {
|
||||
if (chdir(uwsgi.chdir)) {
|
||||
uwsgi_error("chdir()");
|
||||
@@ -2523,6 +2541,10 @@ configure:
|
||||
#if defined(__linux__) && !defined(__ia64__)
|
||||
}
|
||||
#endif
|
||||
|
||||
if (uwsgi.safe_pidfile && !uwsgi.is_a_reload) {
|
||||
uwsgi_write_pidfile_explicit(uwsgi.safe_pidfile, masterpid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3258,6 +3280,9 @@ next2:
|
||||
}
|
||||
}
|
||||
|
||||
if (uwsgi.safe_pidfile2 && !uwsgi.is_a_reload) {
|
||||
uwsgi_write_pidfile_explicit(uwsgi.safe_pidfile2, masterpid);
|
||||
}
|
||||
|
||||
// END OF INITIALIZATION
|
||||
return 0;
|
||||
@@ -4893,6 +4918,12 @@ void uwsgi_update_pidfiles() {
|
||||
if (uwsgi.pidfile2) {
|
||||
uwsgi_write_pidfile(uwsgi.pidfile2);
|
||||
}
|
||||
if (uwsgi.safe_pidfile) {
|
||||
uwsgi_write_pidfile(uwsgi.safe_pidfile);
|
||||
}
|
||||
if (uwsgi.safe_pidfile2) {
|
||||
uwsgi_write_pidfile(uwsgi.safe_pidfile2);
|
||||
}
|
||||
}
|
||||
|
||||
void uwsgi_opt_binary_append_data(char *opt, char *value, void *none) {
|
||||
|
||||
@@ -2786,6 +2786,8 @@ struct uwsgi_server {
|
||||
char *zeus;
|
||||
uint64_t buffer_size;
|
||||
int emperor_tyrant_initgroups;
|
||||
char *safe_pidfile;
|
||||
char *safe_pidfile2;
|
||||
};
|
||||
|
||||
struct uwsgi_rpc {
|
||||
@@ -3958,6 +3960,7 @@ void uwsgi_setup_post_buffering(void);
|
||||
struct uwsgi_lock_item *uwsgi_lock_ipcsem_init(char *);
|
||||
|
||||
void uwsgi_write_pidfile(char *);
|
||||
void uwsgi_write_pidfile_explicit(char *, pid_t);
|
||||
int uwsgi_write_intfile(char *, int);
|
||||
|
||||
void uwsgi_protected_close(int);
|
||||
|
||||
Reference in New Issue
Block a user