service-constants.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef SERVICE_CONSTANTS_H
  2. #define SERVICE_CONSTANTS_H
  3. /* Service states */
  4. enum class service_state_t {
  5. STOPPED, // service is not running.
  6. STARTING, // service is starting, and will start (or fail to start) in time.
  7. STARTED, // service is running,
  8. STOPPING // service script is stopping and will stop.
  9. };
  10. /* Service types */
  11. enum class service_type_t {
  12. DUMMY, // Dummy service, used to detect cyclice dependencies
  13. PROCESS, // Service runs as a process, and can be stopped by
  14. // sending the process a signal (usually SIGTERM)
  15. BGPROCESS, // Service runs as a process which "daemonizes" to run in the
  16. // "background".
  17. SCRIPTED, // Service requires an external command to start,
  18. // and a second command to stop
  19. INTERNAL // Internal service, runs no external process
  20. };
  21. /* Service events */
  22. enum class service_event_t {
  23. STARTED, // Service was started (reached STARTED state)
  24. STOPPED, // Service was stopped (reached STOPPED state)
  25. FAILEDSTART, // Service failed to start (possibly due to dependency failing)
  26. STARTCANCELLED, // Service was set to be started but a stop was requested
  27. STOPCANCELLED // Service was set to be stopped but a start was requested
  28. };
  29. /* Shutdown types */
  30. enum class shutdown_type_t {
  31. NONE, // No explicit shutdown
  32. REMAIN, // Continue running with no services
  33. HALT, // Halt system without powering down
  34. POWEROFF, // Power off system
  35. REBOOT // Reboot system
  36. };
  37. /* Reasons for why service stopped */
  38. enum class stopped_reason_t
  39. {
  40. NORMAL,
  41. // Start failures:
  42. DEPFAILED, // A dependency failed to start
  43. FAILED, // failed to start (process terminated)
  44. EXECFAILED, // failed to start (couldn't launch process)
  45. TIMEDOUT, // timed out when starting
  46. // Failure(?) after starting:
  47. TERMINATED // process terminated
  48. };
  49. inline bool did_finish(stopped_reason_t reason)
  50. {
  51. return reason == stopped_reason_t::TERMINATED;
  52. }
  53. enum class dependency_type
  54. {
  55. REGULAR,
  56. SOFT, // dependency starts in parallel, failure/stop does not affect dependent
  57. WAITS_FOR, // as for SOFT, but dependent waits until dependency starts/fails before starting
  58. MILESTONE // dependency must start successfully, but once started the dependency becomes soft
  59. };
  60. // Service set type identifiers:
  61. constexpr int SSET_TYPE_NONE = 0;
  62. constexpr int SSET_TYPE_DIRLOAD = 1;
  63. #endif