0xGA: Check-in [d7742daa82]

Yet another PHP framework, but made for org-mode and geeks.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Try to fix a long bug involving deadlock when trying to shutdown the server. Must better understand python there...
Timelines: family | ancestors | narv
Files: files | file ages | folders
SHA1:d7742daa82269af33b6b357b859e4b94a44d2cc9
User & Date: milouse 2015-02-08 00:15:18
Context
2015-02-08
00:15
Try to fix a long bug involving deadlock when trying to shutdown the server. Must better understand python there... Leaf check-in: d7742daa82 user: milouse tags: narv
2015-01-22
10:02
Fix bug in README.md, which causes dead links to tickets check-in: f5d2be2673 user: milouse tags: narv
Changes

Changes to example/narvblog.py.

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

        if 'blog_folder' in self.config:
            blog_folder = self.config['blog_folder']

        else:
            blog_folder = 'blog'

        blog_folder = os.path.join('srv', self.appname, blog_folder)
        total = 0

        if os.path.isdir(blog_folder):

            for article_permalink in os.listdir(blog_folder):
                article_local_path = os.path.join(blog_folder, article_permalink)
                meta_file = os.path.join(article_local_path, 'meta.conf')
................................................................................

                    output += art_format.format(**data)

        else:
            output = "Pas encore d'articles..."

        if 'blog_template' in self.config:
            blog_template = os.path.join('srv', self.appname, self.config['blog_template'])

            if os.path.isfile(blog_template):
                temp_content = ''
                with open(blog_template) as f:
                    temp_content = f.read()

                output = re.sub(







|







 







|







96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
...
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207

        if 'blog_folder' in self.config:
            blog_folder = self.config['blog_folder']

        else:
            blog_folder = 'blog'

        blog_folder = os.path.join('home', self.appname, blog_folder)
        total = 0

        if os.path.isdir(blog_folder):

            for article_permalink in os.listdir(blog_folder):
                article_local_path = os.path.join(blog_folder, article_permalink)
                meta_file = os.path.join(article_local_path, 'meta.conf')
................................................................................

                    output += art_format.format(**data)

        else:
            output = "Pas encore d'articles..."

        if 'blog_template' in self.config:
            blog_template = os.path.join('home', self.appname, self.config['blog_template'])

            if os.path.isfile(blog_template):
                temp_content = ''
                with open(blog_template) as f:
                    temp_content = f.read()

                output = re.sub(

Changes to src/narv.py.

380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
...
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
...
635
636
637
638
639
640
641


642
643
644
645
646
647
648
649
                        self.routes[potential_path].format(*tokens.groups()))

        return interesting_routes


    def find_route(self):

        loc_path_test = 'srv/{0}{1}'.format(self.appname, self.request_path)
        if self.test_local_file_exists(loc_path_test):
            return True

        logging.debug("[{0}] Try to find a candidate in the user defined routes".format(self.request_path))

        for route in self.extract_interesting_routes():
            if self.test_method_exists(route):
                return True

            route = 'srv/{0}/{1}'.format(self.appname, route)
            if self.test_local_file_exists(route):
                return True

        return False


    def preprocess_content(self):
................................................................................

        self.server = NarvThreadedServer(server_infos, request_handler)
        server_thread = threading.Thread(target=self.server.serve_forever)
        server_thread.daemon = True
        server_thread.start()

        os.chdir(narv_root_path)
        return

        # No more chroot... USE LXC or other containers Stuff !
        if os.getuid() == 0:
            os.chroot(narv_root_path)
            os.chdir("/")
            logging.debug("Dropping priviledges to UID {0} GID {1}".format('nobody', 'nobody'))

            # Remove group privileges
            os.setgroups([])

            # Try setting the new uid/gid
            os.setgid(grp.getgrnam('nobody').gr_gid)
            os.setuid(pwd.getpwnam('nobody').pw_uid)

            # Ensure a very conservative umask
            os.umask(int('077', 8))
        else:
            os.chdir(narv_root_path)


    def interrupt(self, signal, frame):
        logging.info('SIGUSR1 caught. Waiting for next request...')
        self.server.should_interrupt = True


................................................................................
    def start(self):
        logging.info("Serving {0} at port {1}".format(self.server.server_name, self.server.server_port))
        self.server.serve_forever()


    def shutdown(self, signal, frame):
        logging.info("Kthxbye")


        self.server.shutdown()
        sys.exit(0)



if __name__ == "__main__":
    app = Narv()
    app.start()







|









|







 







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







 







>
>
|







380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
...
602
603
604
605
606
607
608



















609
610
611
612
613
614
615
...
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
                        self.routes[potential_path].format(*tokens.groups()))

        return interesting_routes


    def find_route(self):

        loc_path_test = 'home/{0}{1}'.format(self.appname, self.request_path)
        if self.test_local_file_exists(loc_path_test):
            return True

        logging.debug("[{0}] Try to find a candidate in the user defined routes".format(self.request_path))

        for route in self.extract_interesting_routes():
            if self.test_method_exists(route):
                return True

            route = 'home/{0}/{1}'.format(self.appname, route)
            if self.test_local_file_exists(route):
                return True

        return False


    def preprocess_content(self):
................................................................................

        self.server = NarvThreadedServer(server_infos, request_handler)
        server_thread = threading.Thread(target=self.server.serve_forever)
        server_thread.daemon = True
        server_thread.start()

        os.chdir(narv_root_path)





















    def interrupt(self, signal, frame):
        logging.info('SIGUSR1 caught. Waiting for next request...')
        self.server.should_interrupt = True


................................................................................
    def start(self):
        logging.info("Serving {0} at port {1}".format(self.server.server_name, self.server.server_port))
        self.server.serve_forever()


    def shutdown(self, signal, frame):
        logging.info("Kthxbye")
        # Don't understand why, but it seems the following is cause more
        # deadlock than is really usefull.
        # self.server.shutdown()
        sys.exit(0)



if __name__ == "__main__":
    app = Narv()
    app.start()