ebash

enhanced bash

Home Table of Contents GitHub

Module daemon

The daemon module is used for launching long-running processes asynchronously in the background much like daemon. All of these daemon functions in this module operate on a common settings object to make it easier to pass around the details of how to interact with the daemon and the various options that affect how it is started, stopped, etc.

The underlying data structure for this settings object is a pack. The pack is initialized in daemon_init and must be passed by name to all the other daemon functions. This makes it easy to specify global settings for all of these daemon functions without having to worry about consistent argument parsing and argument conflicts between the various daemon_* functions. All of the values set into this pack are available in the caller’s various hooks if desired. If a chroot is provided it is only used inside the body that calls ${cmdline}. If you need to be in the chroot to execute a given hook you’re responsible for doing that yourself.

The following are the keys used to control daemon functionality:

func daemon_disable

daemon_disable is used to disable a daemon. Do not confuse disabling a daemon with stopping a daemon. These are orthogonal concepts. Disabling a daemon exists for compatibility with our systemd wrappers inside of docker where we have a thin init daemon which auto starts all enabled daemons. If you want to prevent a daemon from being auto started by the init daemon then you would disable it.

ARGUMENTS

   optpack
        optpack

func daemon_enable

daemon_enable is used to enable a daemon. Do not confuse enabling a daemon with starting a daemon. These are orthogonal concepts. Enabling a daemon exists for compatibility with our systemd wrappers inside of docker where we have a thin init daemon which auto starts all enabled daemons. If you want to prevent a daemon from being auto started by the init daemon then you would disable it.

ARGUMENTS

   optpack
        optpack

func daemon_enabled

daemon_enabled is used to check if a daemon is enabled or not. Do not confuse enabling a daemon with starting a daemon. These are orthogonal concepts. Enabling a daemon exists for compatibility with our systemd wrappers inside of docker where we have a thin init daemon which auto starts all enabled daemons. If you want to prevent a daemon from being auto started by the init daemon then you would disable it.

ARGUMENTS

   optpack
        optpack

func daemon_init

daemon_init is used to initialize the options pack that all of the various daemon_* functions will use. This makes it easy to specify global settings for all of these daemon functions without having to worry about consistent argument parsing and argument conflicts between the various daemon_* functions. All of the values set into this pack are available in the caller’s various hooks if desired. If a chroot is provided it is only used inside the body that calls ${cmdline}. If you need to be in the chroot to execute a given hook you’re responsible for doing that yourself.

ARGUMENTS

   optpack
        optpack

func daemon_not_running

Check if the daemon is not running

func daemon_pack_save

daemon_pack_save is used to save the optional pack for a daemon to an on-disk configuration file which is stored in the cfgfile field of the option pack. This allows the pack to be reused by many different ebash daemon functions more implicitly as each function can load the configuration from disk.

ARGUMENTS

   optpack
        optpack

func daemon_restart

daemon_restart is a wrapper around daemon_stop followed by daemon_start. It is not a failure for the deamon to not be running and then call daemon_restart.

OPTIONS
(*) Denotes required options
(&) Denotes options which can be given multiple times

   --cgroup-timeout, -c <value>
         Seconds after SIGKILL to wait for processes to actually disappear. Requires cgroup
         support. If you specify a c=<some number of seconds>, we'll give up (and return an error)
         after that many seconds have elapsed. By default, this is 300 seconds. If you specify 0,
         this will wait forever.

   --signal, -s <value>
         Signal to use when gracefully stopping the daemon.

   --timeout, -t <value>
         Number of seconds to wait after initial signal before sending SIGKILL.


ARGUMENTS

   optpack
         Name of options pack that was returned by daemon_init.

func daemon_running

Check if the daemon is running. This is just a convenience wrapper around “daemon_status –quiet”. This is a little more convenient to use in scripts where you only care if it’s running and don’t want to have to suppress all the output from daemon_status.

func daemon_start

daemon_start will daemonize the provided command and its arguments as a pseudo-daemon and automatically respawn it on failure. We don’t use the core operating system’s default daemon system, as that is platform dependent and lacks the portability we need to daemonize things on any arbitrary system.

For options which control daemon_start functionality please see daemon_init.

ARGUMENTS

   optpack
        optpack

func daemon_status

Retrieve the status of a daemon.

For options which control daemon_start functionality please see daemon_init.

OPTIONS
(*) Denotes required options
(&) Denotes options which can be given multiple times

   --quiet, -q
         Make the status function produce no output.


ARGUMENTS

   optpack
         Name of options pack that was returned by daemon_init.

func daemon_stop

daemon_stop will find a command currently being run as a pseudo-daemon, terminate it with the provided signal, and clean up afterwards.

For options which control daemon_start functionality please see daemon_init.

OPTIONS
(*) Denotes required options
(&) Denotes options which can be given multiple times

   --cgroup-timeout, -c <value>
         Seconds after SIGKILL to wait for processes to actually disappear. Requires cgroup
         support. If you specify a c=<some number of seconds>, we'll give up (and return an error)
         after that many seconds have elapsed. By default, this is 300 seconds. If you specify 0,
         this will wait forever.

   --signal, -s <value>
         Signal to use when gracefully stopping the daemon.

   --timeout, -t <value>
         Number of seconds to wait after initial signal before sending SIGKILL.


ARGUMENTS

   optpack
         Name of options pack that was returned by daemon_init.