Service Abstraction

This class implements a Service abstraction. As service we mean a process which runs in daemon mode.

An example of service declaration:

<entry>
    type = service
    name = httpd
    expected = stopped
    control = /sbin/service httpd
</entry>

another example for a standalone script:

<entry>
    type = service
    name = custom1
    start = /path/to/script --conf /path/to/conf --daemon
    # If you cannot provide a status or stop command you can specify a
    # pattern which will be used to look for the process in the process
    # table, however this is supported only on Linux.
    # If not specified start command is used as pattern.
    pattern = /path/to/script --conf /path/to/conf --daemon
</entry>

If one of the parameters contains one or more spaces you should quote them in url-like style, invoked commands are urllib.unquote() before being launched like in this example:

...
start = /path/to/script --conf /path/to/conf --space hello%20world start
...

The stdout and the stderr of the commands executed is logged as debug level within the configured log system.

The commands declared should provide return codes according to the default LSB Unix return codes, for more info visit LSB Core Specification:

0        program is running or service is OK
1        program is dead and /var/run pid file exists
2        program is dead and /var/lock lock file exists
3        program is not running
4        program or service status is unknown
5-99     reserved for future LSB use
100-149  reserved for distribution use
150-199  reserved for application use
200-254  reserved

Parameters

control
the control of the command to run. If specified it will be the prefix of start/stop/status commands.
daemon

if the service command runs in foreground and you wish to daemonize it you can declare this option with value the pidfile path that should be used for the daemonization.

If control is specified this option is ignored.

Given the start command:

start = /path/to/script --conf /path/to/conf

and declaring:

daemon = /path/to/script_pidfile.pid

it is like specifying the following pair of commands/values:

start = /usr/bin/simplevisor-loop -c 1 --pidfile /path/to/script_pidfile.pid --daemon /path/to/script --conf /path/to/conf

stop = /usr/bin/simplevisor-loop --pidfile /path/to/script_pidfile.pid --quit

status = /usr/bin/simplevisor-loop --pidfile /path/to/script_pidfile.pid --status

Hence, if daemon is specified stop and status command are overwritten.

expected
expected state of the service. Valid values are running and stopped.
name
unique name of the worker/service.
path
the path for executing the commands. Multiple values should be separated by colons.
pattern
used to look for the service in the process table for stop and status commands if they are not specified and control is also not specified. Accepted values are valid python regular expressions: re.
restart

specify a custom restart command.

If <control> is specified:

  • if <restart> is not specified “<control> restart” is executed
  • if <restart> = “stop+start” a “<control> stop” followed by a “<control> start” is executed
  • else “<restart>” is executed

If <control> is not specified:

  • if <restart> is not specified “<stop>” followed by “<start>” is executed
  • else “<restart>” is executed
start

specify a custom start command.

If <control> is specified:

  • if <start> is not specified “<control> start” is executed
  • else “<start>” is executed

If <control> is not specified:

  • “<start>” is executed
status

specify a custom status command.

If <control> is specified:

  • “<control> status” is executed

If <control> is not specified:

  • if <status> is specified “<status>” is executed
  • else it will look for it in the process table either looking for the start command or the provided pattern.

Status commands are expected to exit with return code according to the following following:

  • 0: the service is running fine
  • 3: the service is stopped
  • other: return code is interpreted as dirty/zombie/hang state
stop

specify a custom stop command.

If <control> is specified:

  • “<control> stop” is executed

If <control> is not specified:

  • if <stop> is specified “<stop>” is executed
  • else it will look for it in the process table either looking for the start command or the provided pattern and then kill it.
timeout
the maximum timeout for any service command, set to 60 seconds by default.

Required Parameters

- name
- one of: start, control

Default Parameters

- expected = running
- timeout = 60
- all the others are default to None

Copyright (C) 2013-2016 CERN