service.h revision 8fe914ec81d9f57bcc083036f528b00119ed2e3b
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm/*-*- Mode: C; c-basic-offset: 8 -*-*/
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm#ifndef fooservicehfoo
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm#define fooservicehfoo
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm/***
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm This file is part of systemd.
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm Copyright 2010 Lennart Poettering
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm systemd is free software; you can redistribute it and/or modify it
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm under the terms of the GNU General Public License as published by
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm the Free Software Foundation; either version 2 of the License, or
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm (at your option) any later version.
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm systemd is distributed in the hope that it will be useful, but
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm WITHOUT ANY WARRANTY; without even the implied warranty of
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm General Public License for more details.
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm You should have received a copy of the GNU General Public License
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm along with systemd; If not, see <http://www.gnu.org/licenses/>.
f317a3a3712d9b82387b437ac621db3733d8c804krishna***/
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmtypedef struct Service Service;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm#include "unit.h"
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm#include "ratelimit.h"
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmtypedef enum ServiceState {
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_DEAD,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_START_PRE,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_START,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_START_POST,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_RUNNING,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_EXITED, /* Nothing is running anymore, but ValidNoProcess is true, ehnce this is OK */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_RELOAD,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_STOP, /* No STOP_PRE state, instead just register multiple STOP executables */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_STOP_SIGTERM,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_STOP_SIGKILL,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_STOP_POST,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_FINAL_SIGTERM, /* In case the STOP_POST executable hangs, we shoot that down, too */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_FINAL_SIGKILL,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_MAINTENANCE,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_AUTO_RESTART,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm _SERVICE_STATE_MAX,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm _SERVICE_STATE_INVALID = -1
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm} ServiceState;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmtypedef enum ServiceRestart {
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_ONCE,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_RESTART_ON_SUCCESS,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_RESTART_ALWAYS,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm _SERVICE_RESTART_MAX,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm _SERVICE_RESTART_INVALID = -1
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm} ServiceRestart;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmtypedef enum ServiceType {
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_SIMPLE, /* we fork and go on right-away (i.e. modern socket activated daemons) */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_FORKING, /* forks by itself (i.e. traditional daemons) */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_FINISH, /* we fork and wait until the program finishes (i.e. programs like fsck which run and need to finish before we continue) */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_DBUS, /* we fork and wait until a specific D-Bus name appears on the bus */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_NOTIFY, /* we fork and wait until a daemon sends us a ready message with sd_notify() */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm _SERVICE_TYPE_MAX,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm _SERVICE_TYPE_INVALID = -1
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm} ServiceType;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmtypedef enum ServiceExecCommand {
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_EXEC_START_PRE,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_EXEC_START,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_EXEC_START_POST,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_EXEC_RELOAD,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_EXEC_STOP,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm SERVICE_EXEC_STOP_POST,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm _SERVICE_EXEC_COMMAND_MAX,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm _SERVICE_EXEC_COMMAND_INVALID = -1
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm} ServiceExecCommand;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmtypedef enum NotifyAccess {
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm NOTIFY_NONE,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm NOTIFY_ALL,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm NOTIFY_MAIN,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm _NOTIFY_ACCESS_MAX,
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm _NOTIFY_ACCESS_INVALID = -1
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm} NotifyAccess;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmstruct Service {
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm Meta meta;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm ServiceType type;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm ServiceRestart restart;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm /* If set we'll read the main daemon PID from this file */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm char *pid_file;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm usec_t restart_usec;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm usec_t timeout_usec;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm ExecCommand* exec_command[_SERVICE_EXEC_COMMAND_MAX];
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm ExecContext exec_context;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm ServiceState state, deserialized_state;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm ExecStatus main_exec_status;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm ExecCommand *control_command;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm ServiceExecCommand control_command_id;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm pid_t main_pid, control_pid;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm bool permissions_start_only;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm bool root_directory_start_only;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm bool valid_no_process;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm bool main_pid_known:1;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm /* If we shut down, remember why */
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm bool failure:1;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm bool bus_name_good:1;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm bool allow_restart:1;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm bool got_socket_fd:1;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm bool sysv_has_lsb:1;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm int socket_fd;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm int sysv_start_priority;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm char *sysv_path;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm char *sysv_runlevels;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm char *bus_name;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm char *status_text;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm RateLimit ratelimit;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm struct Socket *socket;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm Watch timer_watch;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm NotifyAccess notify_access;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm};
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmextern const UnitVTable service_vtable;
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmint service_set_socket_fd(Service *s, int fd, struct Socket *socket);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmconst char* service_state_to_string(ServiceState i);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmServiceState service_state_from_string(const char *s);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmconst char* service_restart_to_string(ServiceRestart i);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmServiceRestart service_restart_from_string(const char *s);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmconst char* service_type_to_string(ServiceType i);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmServiceType service_type_from_string(const char *s);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmconst char* service_exec_command_to_string(ServiceExecCommand i);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmServiceExecCommand service_exec_command_from_string(const char *s);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmconst char* notify_access_to_string(NotifyAccess i);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gmNotifyAccess notify_access_from_string(const char *s);
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm#endif
88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98gm