77
78
#define JOB_DEFAULT_UMASK 022
83
* @script: whether a shell will be required,
84
* @command: command or script to be run.
86
* This structure represents an individual process within the job that
87
* can be run. When @script is FALSE, @command is checked for shell
88
* characters; if there are none, it is split on whitespace and executed
89
* directly using exec(). If there are shell characters, or @script is
90
* TRUE, @command is executed using a shell.
92
typedef struct job_process {
86
101
* @description: description of the job; intended for humans,
87
102
* @author: author of the job; intended for humans,
88
103
* @version: version of the job; intended for humans,
104
* @instance_of: job this is an instance of,
105
* @delete: job should be deleted once stopped,
89
106
* @goal: whether the job is to be stopped or started,
90
107
* @state: actual state of the job,
108
* @pid: current process id,
109
* @aux_pid: additional process id (for post-start or pre-stop),
110
* @cause: cause of last goal change,
111
* @blocked: emitted event we're waiting to finish,
112
* @failed: whether the last process ran failed,
113
* @failed_state: state the job was in for the last failed process,
114
* @exit_status: exit status of the last failed process,
91
115
* @start_events: list of events that can start this job,
92
116
* @stop_events; list of events that can stop this job.
93
* @depends: list of dependency jobs,
94
* @process_state: what we're waiting for from the process,
95
* @pid: current process id,
117
* @emits: list of additional events that this job can emit,
96
118
* @kill_timeout: time to wait between sending TERM and KILL signals,
97
119
* @kill_timer: timer to kill process,
98
* @spawns_instance: job is always waiting and spawns instances,
99
* @is_instance: job should be cleaned up instead of waiting,
120
* @instance: job is always waiting and spawns instances,
121
* @service: job has reached its goal when running,
100
122
* @respawn: process should be restarted if it fails,
101
123
* @respawn_limit: number of respawns in @respawn_interval that we permit,
102
124
* @respawn_interval: barrier for @respawn_limit,
105
127
* @normalexit: array of exit codes that prevent a respawn,
106
128
* @normalexit_len: length of @normalexit array,
107
129
* @daemon: process forks into background; pid needs to be obtained,
108
* @pidfile: obtain pid by reading this file,
109
* @binary: obtain pid by locating this binary,
130
* @pid_file: obtain pid by reading this file,
131
* @pid_binary: obtain pid by locating this binary,
110
132
* @pid_timeout: time to wait before giving up obtaining pid,
111
133
* @pid_timer: timer for pid location,
112
* @command: command to be run as the primary process,
113
* @script: script to run instead of @command,
114
* @start_script: script to run before @command is started,
115
* @stop_script: script to run after @command is stopped,
134
* @process: primary process to be run,
135
* @pre_start: process to be run before job is started,
136
* @post_start: process to be run after job is started.
137
* @pre_stop: process to be run before job is stopped,
138
* @post_stop: process to be run after job is stopped,
116
139
* @respawn_script: script to run between @command respawns,
117
140
* @console: how to arrange the job's stdin/out/err file descriptors,
118
141
* @env: NULL-terminated list of environment strings to set,
179
213
struct rlimit *limits[RLIMIT_NLIMITS];
186
* @entry: list header,
187
* @name: name of job.
189
* This structure is used to form lists of job names, for example in the
190
* depends list of an ordinary Job.
192
typedef struct job_name {
200
NihList * job_list (void);
202
Job * job_new (const void *parent, const char *name);
204
Job * job_find_by_name (const char *name);
205
Job * job_find_by_pid (pid_t pid);
207
void job_change_state (Job *job, JobState state);
208
JobState job_next_state (Job *job);
210
void job_run_command (Job *job, const char *command);
211
void job_run_script (Job *job, const char *script);
213
void job_kill_process (Job *job);
215
void job_child_reaper (void *ptr, pid_t pid, int killed, int status);
217
void job_start (Job *job);
218
void job_stop (Job *job);
220
void job_release_depends (Job *job);
222
void job_start_event (Job *job, Event *event);
223
void job_stop_event (Job *job, Event *event);
224
void job_handle_event (Event *event);
226
void job_detect_idle (void);
227
void job_set_idle_event (const char *name);
229
Job * job_read_state (Job *job, char *buf);
230
void job_write_state (FILE *state);
224
void job_init (void);
226
Job * job_new (const void *parent, const char *name)
227
__attribute__ ((warn_unused_result, malloc));
228
Job * job_copy (const void *parent, const Job *old_job)
229
__attribute__ ((warn_unused_result, malloc));
231
Job * job_find_by_name (const char *name);
232
Job * job_find_by_pid (pid_t pid);
234
void job_change_goal (Job *job, JobGoal goal,
235
EventEmission *emission);
237
void job_change_state (Job *job, JobState state);
238
JobState job_next_state (Job *job);
240
void job_run_process (Job *job, JobProcess *process);
242
void job_kill_process (Job *job);
244
void job_child_reaper (void *ptr, pid_t pid, int
247
void job_handle_event (EventEmission *emission);
248
void job_handle_event_finished (EventEmission *emission);
250
void job_detect_stalled (void);
251
void job_free_deleted (void);