service-constants.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. DUMMY, // Dummy service, used to detect cyclice dependencies
  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. };
  22. /* Service events */
  23. enum class service_event_t {
  24. STARTED, // Service was started (reached STARTED state)
  25. STOPPED, // Service was stopped (reached STOPPED state)
  26. FAILEDSTART, // Service failed to start (possibly due to dependency failing)
  27. STARTCANCELLED, // Service was set to be started but a stop was requested
  28. STOPCANCELLED // Service was set to be stopped but a start was requested
  29. };
  30. /* Shutdown types */
  31. enum class shutdown_type_t {
  32. NONE, // No explicit shutdown
  33. REMAIN, // Continue running with no services
  34. HALT, // Halt system without powering down
  35. POWEROFF, // Power off system
  36. REBOOT // Reboot system
  37. };
  38. /* Reasons for why service stopped */
  39. enum class stopped_reason_t
  40. {
  41. NORMAL,
  42. // Start failures:
  43. DEPFAILED, // A dependency failed to start
  44. FAILED, // failed to start (process terminated)
  45. EXECFAILED, // failed to start (couldn't launch process)
  46. TIMEDOUT, // timed out when starting
  47. // Failure(?) after starting:
  48. TERMINATED // process terminated
  49. };
  50. inline bool did_finish(stopped_reason_t reason)
  51. {
  52. return reason == stopped_reason_t::TERMINATED;
  53. }
  54. /* Execution stage */
  55. enum class exec_stage {
  56. ARRANGE_FDS, READ_ENV_FILE, SET_NOTIFYFD_VAR, SETUP_ACTIVATION_SOCKET, SETUP_CONTROL_SOCKET,
  57. CHDIR, SETUP_STDINOUTERR, ENTER_CGROUP, SET_RLIMITS, SET_UIDGID,
  58. /* values for future expansion: */
  59. SPARE1, SPARE2, SPARE3, SPARE4, SPARE5, SPARE6, SPARE7, SPARE8,
  60. /* must be last: */ DO_EXEC
  61. };
  62. /* Strings describing the execution stages (failure points). */
  63. const char * const exec_stage_descriptions[/* static_cast<int>(exec_stage::DO_EXEC) + 1 */] = {
  64. "arranging file descriptors", // ARRANGE_FDS
  65. "reading environment file", // READ_ENV_FILE
  66. "setting environment variable", // SET_NOTIFYFD_VAR
  67. "setting up activation socket", // SETUP_ACTIVATION_SOCKET
  68. "setting up control socket", // SETUP_CONTROL_SOCKET
  69. "changing directory", // CHDIR
  70. "setting up standard input/output descriptors", // SETUP_STDINOUTERR
  71. #if SUPPORT_CGROUPS
  72. "entering cgroup", // ENTER_CGROUP
  73. #else
  74. "", // ENTER_CGROUP (placeholder)
  75. #endif
  76. "setting resource limits", // SET_RLIMITS
  77. "setting user/group ID", // SET_UIDGID
  78. nullptr, // SPARE1
  79. nullptr, // SPARE2
  80. nullptr, // SPARE3
  81. nullptr, // SPARE4
  82. nullptr, // SPARE5
  83. nullptr, // SPARE6
  84. nullptr, // SPARE7
  85. nullptr, // SPARE8
  86. "executing command" // DO_EXEC
  87. };
  88. static_assert(sizeof(exec_stage_descriptions) == (sizeof(char *) * (static_cast<int>(exec_stage::DO_EXEC) + 1)),
  89. "exec_stage_descriptions missing a stage description");
  90. enum class dependency_type
  91. {
  92. REGULAR,
  93. SOFT, // dependency starts in parallel, failure/stop does not affect dependent
  94. WAITS_FOR, // as for SOFT, but dependent waits until dependency starts/fails before starting
  95. MILESTONE, // dependency must start successfully, but once started the dependency becomes soft
  96. BEFORE, // "before" ordering constraint (specified via the "to" service)
  97. AFTER // "after" ordering constraint (specified via the "from" service)
  98. };
  99. // Service set type identifiers:
  100. constexpr int SSET_TYPE_NONE = 0;
  101. constexpr int SSET_TYPE_DIRLOAD = 1;
  102. #endif