systemd.generator(7) - Linux manual page http://man7.org/linux/man-pages/man7/systemd.generator.7.html

  1. SYSTEMD.GENERATOR(7) systemd.generator SYSTEMD.GENERATOR(7)

NAME         top

  1. systemd.generator - Systemd unit generators

SYNOPSIS         top

  1. /path/to/generator normal-dir early-dir late-dir
  2.  
  3. /run/systemd/system-generators/*
  4. /etc/systemd/system-generators/*
  5. /usr/local/lib/systemd/system-generators/*
  6. /usr/lib/systemd/system-generators/*
  7.  
  8. /run/systemd/user-generators/*
  9. /etc/systemd/user-generators/*
  10. /usr/local/lib/systemd/user-generators/*
  11. /usr/lib/systemd/user-generators/*

DESCRIPTION         top

  1. Generators are small binaries that live in
  2. /usr/lib/systemd/user-generators/ and other directories listed above.
  3. systemd(1) will execute those binaries very early at bootup and at
  4. configuration reload time before unit files are loaded. Generators
  5. can dynamically generate unit files or create symbolic links to unit
  6. files to add additional dependencies, thus extending or overriding
  7. existing definitions. Their main purpose is to convert configuration
  8. files that are not native unit files dynamically into native unit
  9. files.
  10.  
  11. Generators are loaded from a set of paths determined during
  12. compilation, as listed above. System and user generators are loaded
  13. from directories with names ending in system-generators/ and
  14. user-generators/, respectively. Generators found in directories
  15. listed earlier override the ones with the same name in directories
  16. lower in the list. A symlink to /dev/null or an empty file can be
  17. used to mask a generator, thereby preventing it from running. Please
  18. note that the order of the two directories with the highest priority
  19. is reversed with respect to the unit load path, and generators in
  20. /run overwrite those in /etc.
  21.  
  22. After installing new generators or updating the configuration,
  23. systemctl daemon-reload may be executed. This will delete the
  24. previous configuration created by generators, re-run all generators,
  25. and cause systemd to reload units from disk. See systemctl(1) for
  26. more information.

WRITING GENERATORS         top

  1. Generators are invoked with three arguments: paths to runtime
  2. directories where generators can place their generated unit files or
  3. symlinks.
  4.  
  5. 1. normal-dir
  6.  
  7. argv[1] may be used to override unit files in /usr, but not those
  8. in /etc. This means that unit files placed in this directory take
  9. precedence over vendor unit configuration but not over native
  10. user/administrator unit configuration.
  11.  
  12. 2. early-dir
  13.  
  14. argv[2] may be used to override unit files in /usr and in /etc.
  15. This means that unit files placed in this directory take
  16. precedence over all configuration, both vendor and
  17. user/administrator.
  18.  
  19. 3. late-dir
  20.  
  21. argv[3] may be used to extend the unit file tree without
  22. overriding any other unit files. Any native configuration files
  23. supplied by the vendor or user/administrator take precedence over
  24. the generated ones placed in this directory.
  25.  
  26. Notes
  27. · All generators are executed in parallel. That means all
  28. executables are started at the very same time and need to be able
  29. to cope with this parallelism.
  30.  
  31. · Generators are run very early at boot and cannot rely on any
  32. external services. They may not talk to any other process. That
  33. includes simple things such as logging to syslog(3), or systemd
  34. itself (this means: no systemctl(1))! Non-essential file systems
  35. like /var and /home are mounted after generators have run.
  36. Generators can however rely on the most basic kernel
  37. functionality to be available, including a mounted /sys, /proc,
  38. /dev, /usr.
  39.  
  40. · Units written by generators are removed when the configuration is
  41. reloaded. That means the lifetime of the generated units is
  42. closely bound to the reload cycles of systemd itself.
  43.  
  44. · Generators should only be used to generate unit files, not any
  45. other kind of configuration. Due to the lifecycle logic mentioned
  46. above, generators are not a good fit to generate dynamic
  47. configuration for other services. If you need to generate dynamic
  48. configuration for other services, do so in normal services you
  49. order before the service in question.
  50.  
  51. · Since syslog(3) is not available (see above), log messages have
  52. to be written to /dev/kmsg instead.
  53.  
  54. · It is a good idea to use the SourcePath= directive in generated
  55. unit files to specify the source configuration file you are
  56. generating the unit from. This makes things more easily
  57. understood by the user and also has the benefit that systemd can
  58. warn the user about configuration files that changed on disk but
  59. have not been read yet by systemd.
  60.  
  61. · Generators may write out dynamic unit files or just hook unit
  62. files into other units with the usual .wants/ or .requires/
  63. symlinks. Often, it is nicer to simply instantiate a template
  64. unit file from /usr with a generator instead of writing out
  65. entirely dynamic unit files. Of course, this works only if a
  66. single parameter is to be used.
  67.  
  68. · If you are careful, you can implement generators in shell
  69. scripts. We do recommend C code however, since generators are
  70. executed synchronously and hence delay the entire boot if they
  71. are slow.
  72.  
  73. · Regarding overriding semantics: there are two rules we try to
  74. follow when thinking about the overriding semantics:
  75.  
  76. 1. User configuration should override vendor configuration. This
  77. (mostly) means that stuff from /etc should override stuff
  78. from /usr.
  79.  
  80. 2. Native configuration should override non-native
  81. configuration. This (mostly) means that stuff you generate
  82. should never override native unit files for the same purpose.
  83.  
  84. Of these two rules the first rule is probably the more important
  85. one and breaks the second one sometimes. Hence, when deciding
  86. whether to user argv[1], argv[2], or argv[3], your default choice
  87. should probably be argv[1].
  88.  
  89. · Instead of heading off now and writing all kind of generators for
  90. legacy configuration file formats, please think twice! It is
  91. often a better idea to just deprecate old stuff instead of
  92. keeping it artificially alive.

EXAMPLES         top

  1. Example 1. systemd-fstab-generator
  2.  
  3. systemd-fstab-generator(8) converts /etc/fstab into native mount
  4. units. It uses argv[1] as location to place the generated unit files
  5. in order to allow the user to override /etc/fstab with her own native
  6. unit files, but also to ensure that /etc/fstab overrides any vendor
  7. default from /usr.
  8.  
  9. After editing /etc/fstab, the user should invoke systemctl
  10. daemon-reload. This will re-run all generators and cause systemd to
  11. reload units from disk. To actually mount new directories added to
  12. fstab, systemctl start /path/to/mountpoint or systemctl start
  13. local-fs.target may be used.
  14.  
  15. Example 2. systemd-system-update-generator
  16.  
  17. systemd-system-update-generator(8) temporarily redirects
  18. default.target to system-update.target, if a system update is
  19. scheduled. Since this needs to override the default user
  20. configuration for default.target, it uses argv[2]. For details about
  21. this logic, see systemd.offline-updates(7).
  22.  
  23. Example 3. Debugging a generator
  24.  
  25. dir=$(mktemp -d)
  26. SYSTEMD_LOG_LEVEL=debug /usr/lib/systemd/system-generators/systemd-fstab-generator \
  27. "$dir" "$dir" "$dir"
  28. find $dir

SEE ALSO         top

  1. systemd(1), systemd-cryptsetup-generator(8),
  2. systemd-debug-generator(8), systemd-fstab-generator(8), fstab(5),
  3. systemd-getty-generator(8), systemd-gpt-auto-generator(8),
  4. systemd-hibernate-resume-generator(8),
  5. systemd-system-update-generator(8), systemd-sysv-generator(8),
  6. systemd.unit(5), systemctl(1), systemd.environment-generator(7)

COLOPHON         top

  1. This page is part of the systemd (systemd system and service manager)
  2. project. Information about the project can be found at
  3. http://www.freedesktop.org/wiki/Software/systemd⟩. If you have a bug
  4. report for this manual page, see
  5. http://www.freedesktop.org/wiki/Software/systemd/#bugreports⟩. This
  6. page was obtained from the project's upstream Git repository
  7. https://github.com/systemd/systemd.git⟩ on 2018-10-29. (At that
  8. time, the date of the most recent commit that was found in the repos‐
  9. itory was 2018-10-29.) If you discover any rendering problems in
  10. this HTML version of the page, or you believe there is a better or
  11. more up-to-date source for the page, or you have corrections or
  12. improvements to the information in this COLOPHON (which is not part
  13. of the original manual page), send a mail to man-pages@man7.org
  14.  
  15. systemd 234 SYSTEMD.GENERATOR(7)
  16.  
  17. unit

[root@d ~]# service mysqd start
Redirecting to /bin/systemctl start mysqd.service
Failed to start mysqd.service: Unit not found.
[root@d ~]# service mysqld start
Redirecting to /bin/systemctl start mysqld.service
[root@d ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2018-12-21 16:54:24 CST; 15s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 7433 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 7453 (mysqld)
Status: "SERVER_OPERATING"
CGroup: /system.slice/mysqld.service
└─7453 /usr/sbin/mysqld

Dec 21 16:54:22 d systemd[1]: Starting MySQL Server...
Dec 21 16:54:24 d systemd[1]: Started MySQL Server.
[root@d ~]#

Systemd unit generators unit的更多相关文章

  1. Linux Systemd 详细介绍: Unit、Unit File、Systemctl、Target

    Systemd 简介 CentOS 7 使用 Systemd 替换了SysV Ubuntu 从 15.04 开始使用 Systemd Systemd 是 Linux 系统工具,用来启动守护进程,已成为 ...

  2. [Unit Test] Unit Test Brief Introduction

    Levels of Testing- Acceptance- Performance- Functional- Integration- Unit Why Unit Testing- Feedback ...

  3. linux cron计划任务、chkconfig 命令、systemd命令、unit 相关、target 相关

    1.设置说明位置 : cat /etc/crontab # Example of job definition:# .---------------- minute (0 - 59)# | .---- ...

  4. linux任务计划 chkconfig工具 systemd管理服务 unit介绍 target介绍

    linux任务计划 任务计划:特定时间备份数据,重启服务,shell脚本,单独的命令等等. 任务计划配置文件:cat /etc/crontab [root@centos7 ~]# cat /etc/c ...

  5. [转载]SystemD strikes again : Unit X.mount is bound to inactive unit

    http://mamchenkov.net/wordpress/2017/11/09/systemd-strikes-again-unit-var-whatever-mount-is-bound-to ...

  6. Scala中 => Unit 与 () =>Unit的区别

    () => Unit ---> 是一个函数:=> Unit --> 是一个执行结果为Unit的表达式 code: => Unit是 by name 传递参数.参数是一个返 ...

  7. [Unit Testing] Unit Test a Function that Invokes a Callback with a Sinon Spy

    Unit testing functions that invoke callbacks can require a lot of setup code. Using sinon.spy to cre ...

  8. [Angular + Unit] AngularJS Unit testing using Karma

    http://social.technet.microsoft.com/wiki/contents/articles/32300.angularjs-unit-testing-using-karma- ...

  9. systemd的新特性及常见的systemd unit类型分析

    systemd概述 )systemd是一种新的linux系统服务管理器,用于替换init系统,能够管理系统启动过程和系统服务,一旦启动起来,就将监管整个系统.在centos7系统中,PID1被syst ...

随机推荐

  1. 一个牛人给Java初学者的建议

    学习Java的同学注意了!!! 学习过程中遇到什么问题或者想获取学习资源的话,欢迎加入Java学习交流群,群号码:618528494  我们一起学Java! 给初学者之一:浅谈Java及应用学java ...

  2. 【SJSB】 android-javascript开发框架

    这是一个本人开发的android壳,作用就是为html5开发提供各种接口以调用native. 只是第一个版本,随笔以纪念.详细的说明和api都在 项目的readme中. 项目地址: https://g ...

  3. [深入理解Android卷一全文-第四章]深入理解zygote

    由于<深入理解Android 卷一>和<深入理解Android卷二>不再出版,而知识的传播不应该由于纸质媒介的问题而中断,所以我将在CSDN博客中全文转发这两本书的所有内容. ...

  4. ios开发之--从相机或相册选取图片,并带删除操作的demo

    多选图片的一个效果,如下图:

  5. Dubbo(二) -- Simple Monitor

    一.简介 dubbo-monitor-simple是dubbo提供的简单监控中心,可以用来显示接口暴露,注册情况,也可以看接口的调用明细,调用时间等. Simple Monitor挂掉不会影响到Con ...

  6. WebSphere和IHS的安装

    环境:CentOS6.5, IP :192.168.0.91 hostname: IHS 1.下载Installation Manage安装包 URL:http://www.ibm.com/devel ...

  7. Android的读写文件及权限设置

    drwx read write excute openFileOutput(name,drwx); 用系统api读取文件 设置文件生成的权限:    public static boolean sav ...

  8. vuejs开发环境搭建

    前言:现在前端最火的是3个框架:react,vue,angular.可以说着是哪个框架大大改变了前端的地位.相对于angular来说.vue同样拥有丰富的指令,并且都是典型的MVC框架,但是vue比较 ...

  9. ubuntu安装TexturePicker

    TexturePacker网页:https://www.codeandweb.com/texturepackerTexturePacker下载页面:https://www.codeandweb.com ...

  10. iOS 自动布局 Autolayout 优先级的使用

    一.约束的优先级 0.屏幕适配 发展历程 代码计算frame -> autoreszing(父控件和子控件的关系) -> autolayout(任何控件都可以产生关系) -> siz ...