{
    "content": [
        {
            "type": "text",
            "text": "# systemd.generator(7) (man)\n\n**Summary:** systemd.generator - systemd unit generators\n\n**Synopsis:** /path/to/generator normal-dir early-dir late-dir\n/run/systemd/system-generators/*\n/etc/systemd/system-generators/*\n/usr/local/lib/systemd/system-generators/*\n/lib/systemd/system-generators/*\n/run/systemd/user-generators/*\n/etc/systemd/user-generators/*\n/usr/local/lib/systemd/user-generators/*\n/usr/lib/systemd/user-generators/*\n\n## Examples\n\n- `systemd-fstab-generator(8) converts /etc/fstab into native mount units. It uses argv[1] as`\n- `location to place the generated unit files in order to allow the user to override /etc/fstab`\n- `with their own native unit files, but also to ensure that /etc/fstab overrides any vendor`\n- `default from /usr/.`\n- `After editing /etc/fstab, the user should invoke systemctl daemon-reload. This will re-run`\n- `all generators and cause systemd to reload units from disk. To actually mount new directories`\n- `added to fstab, systemctl start /path/to/mountpoint or systemctl start local-fs.target may be`\n- `used.`\n- `systemd-system-update-generator(8) temporarily redirects default.target to`\n- `system-update.target, if a system update is scheduled. Since this needs to override the`\n- `default user configuration for default.target, it uses argv[2]. For details about this logic,`\n- `see systemd.offline-updates(7).`\n- `dir=$(mktemp -d)`\n- `SYSTEMDLOGLEVEL=debug /lib/systemd/system-generators/systemd-fstab-generator \\`\n- `\"$dir\" \"$dir\" \"$dir\"`\n- `find $dir`\n\n## See Also\n\n- systemd(1)\n- systemd-cryptsetup-generator(8)\n- systemd-debug-generator(8)\n- generator(8)\n- fstab(5)\n- systemd-getty-generator(8)\n- systemd-gpt-auto-generator(8)\n- hibernate-resume-generator(8)\n- systemd-rc-local-generator(8)\n- generator(8)\n- systemd-sysv-generator(8)\n- systemd-xdg-autostart-generator(8)\n- systemd.unit(5)\n- systemctl(1)\n- systemd.environment-generator(7)\n- SYSTEMD.GENERATOR(7)\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **SYNOPSIS** (13 lines)\n- **DESCRIPTION** (34 lines)\n- **OUTPUT DIRECTORIES** (27 lines)\n- **NOTES ABOUT WRITING GENERATORS** (67 lines)\n- **EXAMPLES** (1 lines) — 3 subsections\n  - Example 1. systemd-fstab-generator (10 lines)\n  - Example 2. systemd-system-update-generator (5 lines)\n  - Example 3. Debugging a generator (5 lines)\n- **SEE ALSO** (9 lines)\n\n## Full Content\n\n### NAME\n\nsystemd.generator - systemd unit generators\n\n### SYNOPSIS\n\n/path/to/generator normal-dir early-dir late-dir\n\n/run/systemd/system-generators/*\n/etc/systemd/system-generators/*\n/usr/local/lib/systemd/system-generators/*\n/lib/systemd/system-generators/*\n\n/run/systemd/user-generators/*\n/etc/systemd/user-generators/*\n/usr/local/lib/systemd/user-generators/*\n/usr/lib/systemd/user-generators/*\n\n### DESCRIPTION\n\nGenerators are small executables placed in /lib/systemd/system-generators/ and other\ndirectories listed above.  systemd(1) will execute these binaries very early at bootup and at\nconfiguration reload time — before unit files are loaded. Their main purpose is to convert\nconfiguration that is not native to the service manager into dynamically generated unit\nfiles, symlinks or unit file drop-ins, so that they can extend the unit file hierarchy the\nservice manager subsequently loads and operates on.\n\nEach generator is called with three directory paths that are to be used for generator output.\nIn these three directories, generators may dynamically generate unit files (regular ones,\ninstances, as well as templates), unit file .d/ drop-ins, and create symbolic links to unit\nfiles to add additional dependencies, create aliases, or instantiate existing templates.\nThose directories are included in the unit load path of systemd(1), allowing generated\nconfiguration to extend or override existing definitions.\n\nDirectory paths for generator output differ by priority: .../generator.early has priority\nhigher than the admin configuration in /etc/, while .../generator has lower priority than\n/etc/ but higher than vendor configuration in /usr/, and .../generator.late has priority\nlower than all other configuration. See the next section and the discussion of unit load\npaths and unit overriding in systemd.unit(5).\n\nGenerators are loaded from a set of paths determined during compilation, as listed above.\nSystem and user generators are loaded from directories with names ending in\nsystem-generators/ and user-generators/, respectively. Generators found in directories listed\nearlier override the ones with the same name in directories lower in the list. A symlink to\n/dev/null or an empty file can be used to mask a generator, thereby preventing it from\nrunning. Please note that the order of the two directories with the highest priority is\nreversed with respect to the unit load path, and generators in /run/ overwrite those in\n/etc/.\n\nAfter installing new generators or updating the configuration, systemctl daemon-reload may be\nexecuted. This will delete the previous configuration created by generators, re-run all\ngenerators, and cause systemd to reload units from disk. See systemctl(1) for more\ninformation.\n\n### OUTPUT DIRECTORIES\n\nGenerators are invoked with three arguments: paths to directories where generators can place\ntheir generated unit files or symlinks. By default those paths are runtime directories that\nare included in the search path of systemd, but a generator may be called with different\npaths for debugging purposes.\n\n1. normal-dir\n\nIn normal use this is /run/systemd/generator in case of the system generators and\n$XDGRUNTIMEDIR/generator in case of the user generators. Unit files placed in this\ndirectory take precedence over vendor unit configuration but not over native\nuser/administrator unit configuration.\n\n2. early-dir\n\nIn normal use this is /run/systemd/generator.early in case of the system generators and\n$XDGRUNTIMEDIR/generator.early in case of the user generators. Unit files placed in\nthis directory override unit files in /usr/, /run/ and /etc/. This means that unit files\nplaced in this directory take precedence over all normal configuration, both vendor and\nuser/administrator.\n\n3. late-dir\n\nIn normal use this is /run/systemd/generator.late in case of the system generators and\n$XDGRUNTIMEDIR/generator.late in case of the user generators. This directory may be\nused to extend the unit file tree without overriding any other unit files. Any native\nconfiguration files supplied by the vendor or user/administrator take precedence.\n\n### NOTES ABOUT WRITING GENERATORS\n\n•   All generators are executed in parallel. That means all executables are started at the\nvery same time and need to be able to cope with this parallelism.\n\n•   Generators are run very early at boot and cannot rely on any external services. They may\nnot talk to any other process. That includes simple things such as logging to syslog(3),\nor systemd itself (this means: no systemctl(1))! Non-essential file systems like /var/\nand /home/ are mounted after generators have run. Generators can however rely on the most\nbasic kernel functionality to be available, as well as mounted /sys/, /proc/, /dev/,\n/usr/ and /run/ file systems.\n\n•   Units written by generators are removed when the configuration is reloaded. That means\nthe lifetime of the generated units is closely bound to the reload cycles of systemd\nitself.\n\n•   Generators should only be used to generate unit files, .d/*.conf drop-ins for them and\nsymlinks to them, not any other kind of non-unit related configuration. Due to the\nlifecycle logic mentioned above, generators are not a good fit to generate dynamic\nconfiguration for other services. If you need to generate dynamic configuration for other\nservices, do so in normal services you order before the service in question.\n\nNote that using the StandardInputData=/StandardInputText= settings of service unit files\n(see systemd.exec(5)), it is possible to make arbitrary input data (including\ndaemon-specific configuration) part of the unit definitions, which often might be\nsufficient to embed data or configuration for other programs into unit files in a native\nfashion.\n\n•   Since syslog(3) is not available (see above), log messages have to be written to\n/dev/kmsg instead.\n\n•   The generator should always include its own name in a comment at the top of the generated\nfile, so that the user can easily figure out which component created or amended a\nparticular unit.\n\nThe SourcePath= directive should be used in generated files to specify the source\nconfiguration file they are generated from. This makes things more easily understood by\nthe user and also has the benefit that systemd can warn the user about configuration\nfiles that changed on disk but have not been read yet by systemd. The SourcePath= value\ndoes not have to be a file in a physical filesystem. For example, in the common case of\nthe generator looking at the kernel command line, SourcePath=/proc/cmdline should be\nused.\n\n•   Generators may write out dynamic unit files or just hook unit files into other units with\nthe usual .wants/ or .requires/ symlinks. Often, it is nicer to simply instantiate a\ntemplate unit file from /usr/ with a generator instead of writing out entirely dynamic\nunit files. Of course, this works only if a single parameter is to be used.\n\n•   If you are careful, you can implement generators in shell scripts. We do recommend C code\nhowever, since generators are executed synchronously and hence delay the entire boot if\nthey are slow.\n\n•   Regarding overriding semantics: there are two rules we try to follow when thinking about\nthe overriding semantics:\n\n1. User configuration should override vendor configuration. This (mostly) means that\nstuff from /etc/ should override stuff from /usr/.\n\n2. Native configuration should override non-native configuration. This (mostly) means\nthat stuff you generate should never override native unit files for the same purpose.\n\nOf these two rules the first rule is probably the more important one and breaks the\nsecond one sometimes. Hence, when deciding whether to use argv[1], argv[2], or argv[3],\nyour default choice should probably be argv[1].\n\n•   Instead of heading off now and writing all kind of generators for legacy configuration\nfile formats, please think twice! It is often a better idea to just deprecate old stuff\ninstead of keeping it artificially alive.\n\n### EXAMPLES\n\n#### Example 1. systemd-fstab-generator\n\nsystemd-fstab-generator(8) converts /etc/fstab into native mount units. It uses argv[1] as\nlocation to place the generated unit files in order to allow the user to override /etc/fstab\nwith their own native unit files, but also to ensure that /etc/fstab overrides any vendor\ndefault from /usr/.\n\nAfter editing /etc/fstab, the user should invoke systemctl daemon-reload. This will re-run\nall generators and cause systemd to reload units from disk. To actually mount new directories\nadded to fstab, systemctl start /path/to/mountpoint or systemctl start local-fs.target may be\nused.\n\n#### Example 2. systemd-system-update-generator\n\nsystemd-system-update-generator(8) temporarily redirects default.target to\nsystem-update.target, if a system update is scheduled. Since this needs to override the\ndefault user configuration for default.target, it uses argv[2]. For details about this logic,\nsee systemd.offline-updates(7).\n\n#### Example 3. Debugging a generator\n\ndir=$(mktemp -d)\nSYSTEMDLOGLEVEL=debug /lib/systemd/system-generators/systemd-fstab-generator \\\n\"$dir\" \"$dir\" \"$dir\"\nfind $dir\n\n### SEE ALSO\n\nsystemd(1), systemd-cryptsetup-generator(8), systemd-debug-generator(8), systemd-fstab-\ngenerator(8), fstab(5), systemd-getty-generator(8), systemd-gpt-auto-generator(8), systemd-\nhibernate-resume-generator(8), systemd-rc-local-generator(8), systemd-system-update-\ngenerator(8), systemd-sysv-generator(8), systemd-xdg-autostart-generator(8), systemd.unit(5),\nsystemctl(1), systemd.environment-generator(7)\n\n\n\nsystemd 249                                                                     SYSTEMD.GENERATOR(7)\n\n"
        }
    ],
    "structuredContent": {
        "command": "systemd.generator",
        "section": "7",
        "mode": "man",
        "summary": "systemd.generator - systemd unit generators",
        "synopsis": "/path/to/generator normal-dir early-dir late-dir\n/run/systemd/system-generators/*\n/etc/systemd/system-generators/*\n/usr/local/lib/systemd/system-generators/*\n/lib/systemd/system-generators/*\n/run/systemd/user-generators/*\n/etc/systemd/user-generators/*\n/usr/local/lib/systemd/user-generators/*\n/usr/lib/systemd/user-generators/*",
        "flags": [],
        "examples": [
            "systemd-fstab-generator(8) converts /etc/fstab into native mount units. It uses argv[1] as",
            "location to place the generated unit files in order to allow the user to override /etc/fstab",
            "with their own native unit files, but also to ensure that /etc/fstab overrides any vendor",
            "default from /usr/.",
            "After editing /etc/fstab, the user should invoke systemctl daemon-reload. This will re-run",
            "all generators and cause systemd to reload units from disk. To actually mount new directories",
            "added to fstab, systemctl start /path/to/mountpoint or systemctl start local-fs.target may be",
            "used.",
            "systemd-system-update-generator(8) temporarily redirects default.target to",
            "system-update.target, if a system update is scheduled. Since this needs to override the",
            "default user configuration for default.target, it uses argv[2]. For details about this logic,",
            "see systemd.offline-updates(7).",
            "dir=$(mktemp -d)",
            "SYSTEMDLOGLEVEL=debug /lib/systemd/system-generators/systemd-fstab-generator \\",
            "\"$dir\" \"$dir\" \"$dir\"",
            "find $dir"
        ],
        "see_also": [
            {
                "name": "systemd",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/systemd/1/json"
            },
            {
                "name": "systemd-cryptsetup-generator",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/systemd-cryptsetup-generator/8/json"
            },
            {
                "name": "systemd-debug-generator",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/systemd-debug-generator/8/json"
            },
            {
                "name": "generator",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/generator/8/json"
            },
            {
                "name": "fstab",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/fstab/5/json"
            },
            {
                "name": "systemd-getty-generator",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/systemd-getty-generator/8/json"
            },
            {
                "name": "systemd-gpt-auto-generator",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/systemd-gpt-auto-generator/8/json"
            },
            {
                "name": "hibernate-resume-generator",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/hibernate-resume-generator/8/json"
            },
            {
                "name": "systemd-rc-local-generator",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/systemd-rc-local-generator/8/json"
            },
            {
                "name": "generator",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/generator/8/json"
            },
            {
                "name": "systemd-sysv-generator",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/systemd-sysv-generator/8/json"
            },
            {
                "name": "systemd-xdg-autostart-generator",
                "section": "8",
                "url": "https://www.chedong.com/phpMan.php/man/systemd-xdg-autostart-generator/8/json"
            },
            {
                "name": "systemd.unit",
                "section": "5",
                "url": "https://www.chedong.com/phpMan.php/man/systemd.unit/5/json"
            },
            {
                "name": "systemctl",
                "section": "1",
                "url": "https://www.chedong.com/phpMan.php/man/systemctl/1/json"
            },
            {
                "name": "systemd.environment-generator",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/systemd.environment-generator/7/json"
            },
            {
                "name": "SYSTEMD.GENERATOR",
                "section": "7",
                "url": "https://www.chedong.com/phpMan.php/man/SYSTEMD.GENERATOR/7/json"
            }
        ],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 34,
                "subsections": []
            },
            {
                "name": "OUTPUT DIRECTORIES",
                "lines": 27,
                "subsections": []
            },
            {
                "name": "NOTES ABOUT WRITING GENERATORS",
                "lines": 67,
                "subsections": []
            },
            {
                "name": "EXAMPLES",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Example 1. systemd-fstab-generator",
                        "lines": 10
                    },
                    {
                        "name": "Example 2. systemd-system-update-generator",
                        "lines": 5
                    },
                    {
                        "name": "Example 3. Debugging a generator",
                        "lines": 5
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 9,
                "subsections": []
            }
        ]
    }
}