service-constants.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef SERVICE_CONSTANTS_H
  2. #define SERVICE_CONSTANTS_H
  3. #include <mconfig.h>
  4. #include <control-datatypes.h>
  5. /* Service states */
  6. enum class service_state_t : dinit_cptypes::srvstate_t {
  7. STOPPED, // service is not running.
  8. STARTING, // service is starting, and will start (or fail to start) in time.
  9. STARTED, // service is running,
  10. STOPPING // service script is stopping and will stop.
  11. };
  12. /* Service types */
  13. enum class service_type_t {
  14. PLACEHOLDER, // Placeholder service, used for various reasons
  15. PROCESS, // Service runs as a process, and can be stopped by
  16. // sending the process a signal (usually SIGTERM)
  17. BGPROCESS, // Service runs as a process which "daemonizes" to run in the
  18. // "background".
  19. SCRIPTED, // Service requires an external command to start,
  20. // and a second command to stop
  21. INTERNAL, // Internal service, runs no external process
  22. TRIGGERED // Externally triggered service
  23. };
  24. /* Service events */
  25. enum class service_event_t {
  26. STARTED, // Service was started (reached STARTED state)
  27. STOPPED, // Service was stopped (reached STOPPED state)
  28. FAILEDSTART, // Service failed to start (possibly due to dependency failing)
  29. STARTCANCELLED, // Service was set to be started but a stop was requested
  30. STOPCANCELLED // Service was set to be stopped but a start was requested
  31. };
  32. /* Shutdown types */
  33. enum class shutdown_type_t {
  34. NONE, // No explicit shutdown
  35. REMAIN, // Continue running with no services
  36. HALT, // Halt system without powering down
  37. POWEROFF, // Power off system
  38. REBOOT // Reboot system
  39. };
  40. /* Reasons for why service stopped */
  41. enum class stopped_reason_t
  42. {
  43. NORMAL,
  44. DEPRESTART, // A hard dependency was restarted
  45. // Start failures:
  46. DEPFAILED, // A dependency failed to start
  47. FAILED, // failed to start (process terminated)
  48. EXECFAILED, // failed to start (couldn't launch process)
  49. TIMEDOUT, // timed out when starting
  50. // Failure(?) after starting:
  51. TERMINATED // process terminated
  52. };
  53. inline bool did_finish(stopped_reason_t reason)
  54. {
  55. return reason == stopped_reason_t::TERMINATED;
  56. }
  57. /* Execution stage */
  58. enum class exec_stage {
  59. ARRANGE_FDS, READ_ENV_FILE, SET_NOTIFYFD_VAR, SETUP_ACTIVATION_SOCKET, SETUP_CONTROL_SOCKET,
  60. CHDIR, SETUP_STDINOUTERR, ENTER_CGROUP, SET_RLIMITS, SET_UIDGID,
  61. OPEN_LOGFILE, // this is used instead of SETUP_STDINOUTERR if output is to logfile
  62. /* values for future expansion: */
  63. SPARE2, SPARE3, SPARE4, SPARE5, SPARE6, SPARE7, SPARE8,
  64. /* must be last: */ DO_EXEC
  65. };
  66. /* Strings describing the execution stages (failure points). */
  67. const char * const exec_stage_descriptions[/* static_cast<int>(exec_stage::DO_EXEC) + 1 */] = {
  68. "arranging file descriptors", // ARRANGE_FDS
  69. "reading environment file", // READ_ENV_FILE
  70. "setting environment variable", // SET_NOTIFYFD_VAR
  71. "setting up activation socket", // SETUP_ACTIVATION_SOCKET
  72. "setting up control socket", // SETUP_CONTROL_SOCKET
  73. "changing directory", // CHDIR
  74. "setting up standard input/output descriptors", // SETUP_STDINOUTERR
  75. #if SUPPORT_CGROUPS
  76. "entering cgroup", // ENTER_CGROUP
  77. #else
  78. "", // ENTER_CGROUP (placeholder)
  79. #endif
  80. "setting resource limits", // SET_RLIMITS
  81. "setting user/group ID", // SET_UIDGID
  82. "opening log file", // OPEN_LOGFILE
  83. // SPARE1 used
  84. nullptr, // SPARE2
  85. nullptr, // SPARE3
  86. nullptr, // SPARE4
  87. nullptr, // SPARE5
  88. nullptr, // SPARE6
  89. nullptr, // SPARE7
  90. nullptr, // SPARE8
  91. "executing command" // DO_EXEC
  92. };
  93. static_assert(sizeof(exec_stage_descriptions) == (sizeof(char *) * (static_cast<int>(exec_stage::DO_EXEC) + 1)),
  94. "exec_stage_descriptions missing a stage description");
  95. enum class dependency_type
  96. {
  97. REGULAR,
  98. SOFT, // dependency starts in parallel, failure/stop does not affect dependent
  99. WAITS_FOR, // as for SOFT, but dependent waits until dependency starts/fails before starting
  100. MILESTONE, // dependency must start successfully, but once started the dependency becomes soft
  101. BEFORE, // "before" ordering constraint (specified via the "to" service)
  102. AFTER // "after" ordering constraint (specified via the "from" service)
  103. };
  104. enum class log_type_id
  105. {
  106. NONE, // discard all output
  107. LOGFILE, // log to a file
  108. BUFFER, // log to a buffer in memory
  109. PIPE // pipe to another process (service)
  110. };
  111. // Service set type identifiers:
  112. constexpr int SSET_TYPE_NONE = 0;
  113. constexpr int SSET_TYPE_DIRLOAD = 1;
  114. #endif