如何使用uWSGI Emperor指定多层级的多个目录?
Got it, let's break this down. You've got vassal configs nested in subdirectories under /etc/uwsgi/vassals—like uwsgi_a.ini in a/ and uwsgi_b.ini in b/hoge/—and you want the uWSGI Emperor to pick all of them up, right? By default, the Emperor only checks the direct children of the specified directory, so we need to adjust the config to make it scan recursively.
Here are two reliable ways to do this:
1. Use the emperor-recursive Flag (Simplest Approach)
This is the most straightforward method—uWSGI has a built-in option to enable recursive directory scanning. Just add this to your Emperor config:
[uwsgi] emperor = /etc/uwsgi/vassals emperor-recursive = true
When you start the Emperor with this config, it will automatically traverse every subdirectory under /etc/uwsgi/vassals and load any valid vassal .ini files it finds. No regex fuss needed.
2. Use a Regular Expression to Match Nested Files
If you prefer to use regex (like the partial example you mentioned), you can specify a pattern that matches files in all subdirectories. The correct syntax for your case is:
[uwsgi] emperor = /etc/uwsgi/vassals/.*\.ini$
The regex .*\.ini$ tells the Emperor to match any file ending with .ini that lives anywhere under the /etc/uwsgi/vassals path (including nested subdirectories). Just make sure your regex is correctly formatted—uWSGI uses POSIX-style regex here.
Quick Notes to Avoid Headaches
- Permissions: The Emperor process needs read access to all the nested directories and config files. If it can't read a directory, it'll skip any configs inside it.
- Reloading: When you add new subdirectories or config files, send a
SIGHUPsignal to the Emperor to trigger a rescan. You can do this with:
(Adjust the PID file path to match your setup.)kill -HUP $(cat /var/run/uwsgi/emperor.pid) - Verify Logs: Check the Emperor's logs after starting it—you should see lines like
added vassal /etc/uwsgi/vassals/a/uwsgi_a.iniconfirming it found your configs.
内容的提问来源于stack exchange,提问作者re1

