2010-08-17 05:33:07 +04:00
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2010-01-23 03:52:57 +03:00
2012-07-18 21:07:51 +04:00
# pragma once
2010-01-23 03:52:57 +03:00
2010-02-03 15:03:47 +03:00
/***
This file is part of systemd .
Copyright 2010 Lennart Poettering
systemd is free software ; you can redistribute it and / or modify it
2012-04-12 02:20:58 +04:00
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation ; either version 2.1 of the License , or
2010-02-03 15:03:47 +03:00
( at your option ) any later version .
systemd is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
2012-04-12 02:20:58 +04:00
Lesser General Public License for more details .
2010-02-03 15:03:47 +03:00
2012-04-12 02:20:58 +04:00
You should have received a copy of the GNU Lesser General Public License
2010-02-03 15:03:47 +03:00
along with systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
2010-01-23 03:52:57 +03:00
typedef struct Service Service ;
2010-01-26 23:39:06 +03:00
# include "unit.h"
2012-01-05 03:56:21 +04:00
# include "path.h"
2010-01-29 06:42:57 +03:00
# include "ratelimit.h"
2012-01-07 02:08:54 +04:00
# include "service.h"
2012-07-20 01:47:10 +04:00
# include "kill.h"
2012-08-13 15:58:01 +04:00
# include "exit-status.h"
2010-01-23 03:52:57 +03:00
typedef enum ServiceState {
SERVICE_DEAD ,
SERVICE_START_PRE ,
SERVICE_START ,
SERVICE_START_POST ,
SERVICE_RUNNING ,
2011-01-19 00:55:54 +03:00
SERVICE_EXITED , /* Nothing is running anymore, but RemainAfterExit is true hence this is OK */
2010-01-23 03:52:57 +03:00
SERVICE_RELOAD ,
2010-01-26 06:18:44 +03:00
SERVICE_STOP , /* No STOP_PRE state, instead just register multiple STOP executables */
SERVICE_STOP_SIGTERM ,
SERVICE_STOP_SIGKILL ,
2010-01-23 03:52:57 +03:00
SERVICE_STOP_POST ,
2010-01-26 06:18:44 +03:00
SERVICE_FINAL_SIGTERM , /* In case the STOP_POST executable hangs, we shoot that down, too */
SERVICE_FINAL_SIGKILL ,
2010-08-31 02:23:34 +04:00
SERVICE_FAILED ,
2010-01-26 06:18:44 +03:00
SERVICE_AUTO_RESTART ,
2010-01-23 03:52:57 +03:00
_SERVICE_STATE_MAX ,
2010-01-30 03:55:42 +03:00
_SERVICE_STATE_INVALID = - 1
2010-01-23 03:52:57 +03:00
} ServiceState ;
2010-01-26 06:18:44 +03:00
typedef enum ServiceRestart {
2010-10-05 22:30:44 +04:00
SERVICE_RESTART_NO ,
2010-01-26 06:18:44 +03:00
SERVICE_RESTART_ON_SUCCESS ,
2010-10-08 20:34:54 +04:00
SERVICE_RESTART_ON_FAILURE ,
SERVICE_RESTART_ON_ABORT ,
2010-01-30 03:55:42 +03:00
SERVICE_RESTART_ALWAYS ,
_SERVICE_RESTART_MAX ,
_SERVICE_RESTART_INVALID = - 1
2010-01-26 06:18:44 +03:00
} ServiceRestart ;
typedef enum ServiceType {
2010-04-16 01:16:16 +04:00
SERVICE_SIMPLE , /* we fork and go on right-away (i.e. modern socket activated daemons) */
2010-06-02 21:15:42 +04:00
SERVICE_FORKING , /* forks by itself (i.e. traditional daemons) */
2010-08-13 20:23:01 +04:00
SERVICE_ONESHOT , /* we fork and wait until the program finishes (i.e. programs like fsck which run and need to finish before we continue) */
2010-04-16 01:16:16 +04:00
SERVICE_DBUS , /* we fork and wait until a specific D-Bus name appears on the bus */
2010-06-16 07:10:31 +04:00
SERVICE_NOTIFY , /* we fork and wait until a daemon sends us a ready message with sd_notify() */
2012-04-24 16:28:00 +04:00
SERVICE_IDLE , /* much like simple, but delay exec() until all jobs are dispatched. */
2010-01-30 03:55:42 +03:00
_SERVICE_TYPE_MAX ,
_SERVICE_TYPE_INVALID = - 1
2010-01-26 06:18:44 +03:00
} ServiceType ;
2010-01-23 03:52:57 +03:00
typedef enum ServiceExecCommand {
SERVICE_EXEC_START_PRE ,
SERVICE_EXEC_START ,
SERVICE_EXEC_START_POST ,
SERVICE_EXEC_RELOAD ,
SERVICE_EXEC_STOP ,
SERVICE_EXEC_STOP_POST ,
2010-04-10 19:53:17 +04:00
_SERVICE_EXEC_COMMAND_MAX ,
_SERVICE_EXEC_COMMAND_INVALID = - 1
2010-01-23 03:52:57 +03:00
} ServiceExecCommand ;
2010-06-19 01:12:48 +04:00
typedef enum NotifyAccess {
NOTIFY_NONE ,
NOTIFY_ALL ,
NOTIFY_MAIN ,
_NOTIFY_ACCESS_MAX ,
_NOTIFY_ACCESS_INVALID = - 1
} NotifyAccess ;
2012-02-03 05:01:35 +04:00
typedef enum ServiceResult {
SERVICE_SUCCESS ,
SERVICE_FAILURE_RESOURCES ,
SERVICE_FAILURE_TIMEOUT ,
SERVICE_FAILURE_EXIT_CODE ,
SERVICE_FAILURE_SIGNAL ,
SERVICE_FAILURE_CORE_DUMP ,
2012-02-08 13:10:34 +04:00
SERVICE_FAILURE_WATCHDOG ,
2012-02-03 05:01:35 +04:00
_SERVICE_RESULT_MAX ,
_SERVICE_RESULT_INVALID = - 1
} ServiceResult ;
2012-02-09 16:05:23 +04:00
typedef enum StartLimitAction {
SERVICE_START_LIMIT_NONE ,
SERVICE_START_LIMIT_REBOOT ,
SERVICE_START_LIMIT_REBOOT_FORCE ,
SERVICE_START_LIMIT_REBOOT_IMMEDIATE ,
_SERVICE_START_LIMIT_MAX ,
_SERVICE_START_LIMIT_INVALID = - 1
} StartLimitAction ;
2010-01-23 03:52:57 +03:00
struct Service {
2012-01-15 15:04:08 +04:00
Unit meta ;
2010-01-23 03:52:57 +03:00
2010-01-26 06:18:44 +03:00
ServiceType type ;
ServiceRestart restart ;
2012-08-13 15:58:01 +04:00
ExitStatusSet restart_ignore_status ;
ExitStatusSet success_status ;
2010-01-26 06:18:44 +03:00
/* If set we'll read the main daemon PID from this file */
char * pid_file ;
usec_t restart_usec ;
2012-08-07 16:41:48 +04:00
usec_t timeout_start_usec ;
usec_t timeout_stop_usec ;
2010-01-23 03:52:57 +03:00
2012-02-01 20:17:12 +04:00
dual_timestamp watchdog_timestamp ;
2012-02-08 13:10:34 +04:00
usec_t watchdog_usec ;
Watch watchdog_watch ;
2012-02-01 20:17:12 +04:00
2010-04-10 19:53:17 +04:00
ExecCommand * exec_command [ _SERVICE_EXEC_COMMAND_MAX ] ;
2012-07-20 01:47:10 +04:00
2010-01-23 03:52:57 +03:00
ExecContext exec_context ;
2012-07-20 01:47:10 +04:00
KillContext kill_context ;
2010-01-23 03:52:57 +03:00
2010-04-21 05:27:44 +04:00
ServiceState state , deserialized_state ;
2010-01-26 06:18:44 +03:00
2011-01-20 20:46:38 +03:00
/* The exit status of the real main process */
2010-01-26 06:18:44 +03:00
ExecStatus main_exec_status ;
2011-01-20 20:46:38 +03:00
/* The currently executed control process */
2010-01-26 06:18:44 +03:00
ExecCommand * control_command ;
2011-01-20 20:46:38 +03:00
/* The currently executed main process, which may be NULL if
* the main process got started via forking mode and not by
* us */
ExecCommand * main_command ;
/* The ID of the control command currently being executed */
2010-04-21 05:27:44 +04:00
ServiceExecCommand control_command_id ;
2011-01-20 20:46:38 +03:00
2010-01-26 06:18:44 +03:00
pid_t main_pid , control_pid ;
2010-09-21 07:23:12 +04:00
int socket_fd ;
2010-07-20 22:33:19 +04:00
2010-10-13 05:57:04 +04:00
int fsck_passno ;
2010-07-20 22:33:19 +04:00
bool permissions_start_only ;
bool root_directory_start_only ;
2010-08-17 21:37:36 +04:00
bool remain_after_exit ;
2011-02-13 20:51:30 +03:00
bool guess_main_pid ;
2010-07-20 22:33:19 +04:00
2010-04-16 01:16:16 +04:00
/* If we shut down, remember why */
2012-02-03 05:01:35 +04:00
ServiceResult result ;
ServiceResult reload_result ;
2011-01-20 15:17:22 +03:00
2010-08-09 19:12:25 +04:00
bool main_pid_known : 1 ;
2011-04-28 06:56:53 +04:00
bool main_pid_alien : 1 ;
2010-04-16 01:16:16 +04:00
bool bus_name_good : 1 ;
2010-08-10 01:33:48 +04:00
bool forbid_restart : 1 ;
2010-04-21 08:01:13 +04:00
bool got_socket_fd : 1 ;
2012-08-07 16:41:48 +04:00
bool start_timeout_defined : 1 ;
2010-09-21 07:23:12 +04:00
# ifdef HAVE_SYSV_COMPAT
2012-05-23 01:08:24 +04:00
bool is_sysv : 1 ;
2010-04-10 19:53:17 +04:00
bool sysv_has_lsb : 1 ;
2010-08-09 19:12:25 +04:00
bool sysv_enabled : 1 ;
2011-03-30 02:43:16 +04:00
int sysv_start_priority_from_rcnd ;
2010-02-14 03:09:01 +03:00
int sysv_start_priority ;
2010-07-20 22:33:19 +04:00
2010-04-07 22:27:52 +04:00
char * sysv_runlevels ;
2010-09-21 07:23:12 +04:00
# endif
2010-02-14 03:09:01 +03:00
2010-04-16 01:16:16 +04:00
char * bus_name ;
2010-06-16 07:10:31 +04:00
char * status_text ;
2012-02-09 16:05:23 +04:00
RateLimit start_limit ;
StartLimitAction start_limit_action ;
2012-01-07 02:08:54 +04:00
UnitRef accept_socket ;
2010-04-15 08:19:54 +04:00
2010-04-10 19:53:17 +04:00
Watch timer_watch ;
2011-12-03 05:13:30 +04:00
PathSpec * pid_file_pathspec ;
2010-07-20 22:33:19 +04:00
NotifyAccess notify_access ;
2010-01-23 03:52:57 +03:00
} ;
2010-02-03 16:21:48 +03:00
extern const UnitVTable service_vtable ;
2010-01-23 03:52:57 +03:00
2012-01-07 02:08:54 +04:00
struct Socket ;
2010-06-19 06:25:28 +04:00
int service_set_socket_fd ( Service * s , int fd , struct Socket * socket ) ;
2010-04-15 08:19:54 +04:00
2010-01-30 03:55:42 +03:00
const char * service_state_to_string ( ServiceState i ) ;
ServiceState service_state_from_string ( const char * s ) ;
const char * service_restart_to_string ( ServiceRestart i ) ;
ServiceRestart service_restart_from_string ( const char * s ) ;
const char * service_type_to_string ( ServiceType i ) ;
ServiceType service_type_from_string ( const char * s ) ;
const char * service_exec_command_to_string ( ServiceExecCommand i ) ;
ServiceExecCommand service_exec_command_from_string ( const char * s ) ;
2010-06-19 01:12:48 +04:00
const char * notify_access_to_string ( NotifyAccess i ) ;
NotifyAccess notify_access_from_string ( const char * s ) ;
2012-02-03 05:01:35 +04:00
const char * service_result_to_string ( ServiceResult i ) ;
ServiceResult service_result_from_string ( const char * s ) ;
2012-02-09 16:05:23 +04:00
const char * start_limit_action_to_string ( StartLimitAction i ) ;
StartLimitAction start_limit_action_from_string ( const char * s ) ;