James Kuszmaul | 6295a64 | 2022-03-22 15:23:59 -0700 | [diff] [blame] | 1 | include "aos/util/process_info.fbs"; |
| 2 | |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 3 | namespace aos.starter; |
| 4 | |
| 5 | enum State : short { |
| 6 | // Process has recently stopped and is waiting to restart. |
| 7 | WAITING, |
| 8 | |
| 9 | // Process has forked, waiting to move to RUNNING after verifying it started |
| 10 | // successfully. |
| 11 | STARTING, |
| 12 | |
| 13 | // Process is running. pid, id, and last_start_time represent the current |
| 14 | // running process. |
| 15 | RUNNING, |
| 16 | |
| 17 | // Process has been sent SIGTERM to nicely stop and starter is waiting for it |
| 18 | // to exit. |
| 19 | STOPPING, |
| 20 | |
| 21 | // Process is stopped and will not automatically restart unless sent a command |
| 22 | STOPPED |
| 23 | } |
| 24 | |
| 25 | enum LastStopReason : uint { |
| 26 | // Application received stop command message |
| 27 | STOP_REQUESTED, |
| 28 | |
| 29 | // Application received restart command message |
| 30 | RESTART_REQUESTED, |
| 31 | |
| 32 | // Application terminated - only occurs when starter is shutting down |
| 33 | TERMINATE, |
| 34 | |
| 35 | // System failed to fork and create a new process |
| 36 | FORK_ERR, |
| 37 | |
| 38 | // Failed to set parent death handler on child |
| 39 | SET_PRCTL_ERR, |
| 40 | |
| 41 | // Failed to change to the requested user |
| 42 | SET_USR_ERR, |
| 43 | |
| 44 | // Failed to execute application - likely due to a missing executable or |
| 45 | // invalid permissions. This is not reported if an application dies for |
| 46 | // another reason after it is already running. |
Austin Schuh | 529ac59 | 2021-10-14 16:11:13 -0700 | [diff] [blame] | 47 | EXECV_ERR, |
| 48 | |
| 49 | // Failed to change to the requested group |
James Kuszmaul | 6f10b38 | 2022-03-11 22:31:38 -0800 | [diff] [blame] | 50 | SET_GRP_ERR |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 51 | } |
| 52 | |
James Kuszmaul | 37a56af | 2023-07-29 15:15:16 -0700 | [diff] [blame] | 53 | // Used to indicate the current state of the file being executed, so that we |
| 54 | // can track which executables may need to be restarted. |
| 55 | enum FileState : short { |
| 56 | // We are not currently in the RUNNING state, so we don't have anything to |
| 57 | // say. This will be set when the process is STARTING and STOPPING as well, |
| 58 | // because it may be in a transient state and we don't want to accidentally |
| 59 | // send out false positives regarding file changes. |
| 60 | NOT_RUNNING, |
| 61 | |
| 62 | // The currently executing file is the one on disk. |
| 63 | NO_CHANGE, |
| 64 | |
| 65 | // The file changed at some point between the fork() call and when we |
| 66 | // entered the RUNNING state, and we aren't currently set up to determine |
| 67 | // if the executed file is the one currently on disk. |
| 68 | CHANGED_DURING_STARTUP, |
| 69 | |
| 70 | // The file has changed since it started RUNNING. |
| 71 | CHANGED, |
| 72 | } |
| 73 | |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 74 | table Status { |
Ravago Jones | fb6a7a5 | 2020-11-14 13:47:46 -0800 | [diff] [blame] | 75 | statuses: [ApplicationStatus] (id: 0); |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | table ApplicationStatus { |
Ravago Jones | fb6a7a5 | 2020-11-14 13:47:46 -0800 | [diff] [blame] | 79 | name: string (id: 0); |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 80 | |
Ravago Jones | fb6a7a5 | 2020-11-14 13:47:46 -0800 | [diff] [blame] | 81 | state: State (id: 1); |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 82 | |
| 83 | // Last exit code of the process. Has a value of 0 if not started. |
Ravago Jones | fb6a7a5 | 2020-11-14 13:47:46 -0800 | [diff] [blame] | 84 | last_exit_code: ubyte (id: 2); |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 85 | |
| 86 | // Last pid of the process. Could be associated with a different process |
| 87 | // unless status == RUNNING. Not present if the process has not started. |
Ravago Jones | fb6a7a5 | 2020-11-14 13:47:46 -0800 | [diff] [blame] | 88 | pid: uint (id: 3); |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 89 | |
| 90 | // Unique id of this application and process |
Ravago Jones | fb6a7a5 | 2020-11-14 13:47:46 -0800 | [diff] [blame] | 91 | id: uint64 (id: 4); |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 92 | |
| 93 | // Start time in nanoseconds relative to monotonic clock |
Ravago Jones | fb6a7a5 | 2020-11-14 13:47:46 -0800 | [diff] [blame] | 94 | last_start_time: int64 (id: 5); |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 95 | |
| 96 | // Indicates the reason the application is not running. Only valid if |
| 97 | // application is STOPPED. |
Ravago Jones | fb6a7a5 | 2020-11-14 13:47:46 -0800 | [diff] [blame] | 98 | last_stop_reason: LastStopReason (id: 6); |
James Kuszmaul | 6295a64 | 2022-03-22 15:23:59 -0700 | [diff] [blame] | 99 | |
| 100 | // Debug information providing the approximate CPU usage and memory footprint of the process. |
| 101 | // Populated whenever the process is running (i.e., state != STOPPED). While STOPPING could |
| 102 | // refer to another process if another process has somehow claimed the application's PID between |
| 103 | // actually stopping and the parent process receiving the signal indicating that the application |
| 104 | // finished stopping. |
| 105 | process_info: util.ProcessInfo (id: 7); |
James Kuszmaul | 8544c49 | 2023-07-31 15:00:38 -0700 | [diff] [blame] | 106 | |
| 107 | // Indicates whether we have observed a recent AOS timing report from |
| 108 | // the application. Staleness is calculated based on the timing report period |
| 109 | // specified for the starterd application (defaults to 1 Hz, can be overridden |
| 110 | // by --timing_report_ms). |
| 111 | has_active_timing_report: bool (id: 8); |
James Kuszmaul | 37a56af | 2023-07-29 15:15:16 -0700 | [diff] [blame] | 112 | |
| 113 | // Current state of the running executable. This can be used to detect if |
| 114 | // a process should be restarted because the file has changed on disk. |
| 115 | file_state: FileState (id: 9); |
Tyler Chatow | a79419d | 2020-08-12 20:12:11 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | root_type Status; |