service-constants.h 4.8 KB

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