NCM::Component::Systemd::Service::Unit¶
NAME¶
NCM::Component::Systemd::Service::Unit is a class handling services with units
Public methods¶
new
Returns a new object, accepts the following options
log
A logger instance (compatible with
CAF::Object).
unit_text
Convert unit
detailhashref to human readable string.Generates errors for missing attributes.
current_units
Return hash reference with current units determined via
make_cache_alias.The array references
unitsandpossible_missingare passed tomake_cache_alias.
current_target
Return the current target.
TODO: implement this. systemctl list-units –type target lists all current targets (yes, with an s).
default_target
Return the default target.
Supported options:
force
Force is passed to the
fill_cachemethod.
configured_units
configured_unitsparses thetreehash reference and builds up the units to be configured. It returns a hash reference with key the unit name and values the details of the unit.Units with missing types are assumed to be TYPE_SERVICE; targets with missing type are assumed to be TYPE_TARGET.
(
treeis typcially obtained with the_getTreemethod).
get_aliases
Given an arrayref of
units, return a hashref with key the unit (from the list) that is an alias for another unit (not necessarily from the list); and the other unit’s name is the value.The
unit_aliascache is used for lookup.The
possible_missingarrayref is passed to thefill_cachemethodSupported options
force
The force flag is passed to the
fill_cachemethod
possible_missing
The
possible_missingarrayref is passed tomake_cache_alias.
possible_missing
Given the hashref
unitswith key unit and value the unit’s details, return a array ref with units that are “possible missing”. Such units will not cause an error to be logged if they are not found in the cache during certain methods (e.g.make_cache_alias).
Private methods¶
is_possible_missing
Determine if
unitispossible_missing(seemake_cache_alias). (Returns 0 or 1).A unit is possible_missing if
the unit is in state masked (i.e. unit that is not expected to be running anyway). Unit in state disabled is not “possible missing” (they can be dependency for other units).
init_cache
(Re)Initialise all unit caches.
Returns the caches (for unittestung mainly).
Affected caches are
unit_cache
unit_alias
dependency_cache
get_type_shortname
get_type_shortnamereturns the type and shortname based on theunitand optionaltype.If the
typeis not specified, it will be derived using the supported types.If the type can’t be determined based on the supported types, the
defaulttypewill be used. If in this case thedefaulttypeis undefined, DEFAULT_TYPE will be used and error will be logged. If thedefaulttypeis defined,
make_cache_alias
(Re)generate the
unit_cacheandunit_aliasmap based on current units and unitfiles from thesystemctl_list_unitsandsystemctl_list_unit_filesmethods.Details for each unit from arrayref
unitsare also added. Ifunitsis empty/undef, all found units and unitfiles are.If a unit is an alias of an other unit, it is added to the alias map. Each non-alias unit is also added as it’s own alias.
Units in the
possible_missingarrayref can be missing, and no error is logged if they are. For any other unit, an error is logged when neither thesystemctl_list_unitsandsystemctl_list_unit_filesmethods provide any information about it.Returns the generated cache and alias map for unittesting purposes.
fill_cache
Fill the
unit_cacheandunit_alias mapfor the arrayrefunitsprovided.The cache is updated via the
make_cache_aliasmethod if the unit is missing from the unit_alias map or ifforceis true.Supported options
force
Force cache refresh.
possible_missing
The
possible_missingarrayref is passed tomake_cache_alias.
get_unit_show
Return the show
propertyforunitfrom the unit_cache and unit_alias map.Supported options
force
Force cache refresh.
possible_missing
If true, this unit is “possible missing” (see
make_cache_alias)
get_wantedby
Return a hashref of all units that “want”
unit(hashref is used for easy lookup; the key is the unit, the value is a boolean).It uses the
dependency_cachefor reverse dependencies (missing cache entries are added).Supported options
force
Force cache update.
ignoreself
By default, the reverse dependency list contains the unit itself too. With
ignoreselftrue, the unit itself is not returned (but still stored in cache).
is_wantedby
Return if
unitis wanted bytarget.Any unit can be passed as
target(it does not have to be a unit of type ‘target’).It uses the
get_wantedbymethod for the dependency lookup.Supported options
force
Force cache update (passed to
get_wantedby).
is_active
is_activereturns true or false and reflects if a unit is “running” or not.The following options are supported
sleeptime =item max
Units that are ‘reloading’, ‘activating’ and ‘deactivating’ are refreshed with
sleep(default 1 sec) andmaxnumber of tries (default 3). Until
force
Force cache refresh (passed to
get_unit_show).
get_ufstate
Return the state of the
unitusing the UnitFileState and the derived state from the state of the $PROPERTY_WANTEDBY units.The returned state can be more then the usual supported states (e.g. static).
The following options are supported
force
Force cache refresh (passed to
get_unit_showandfill_cache)
is_ufstate
is_ufstatereturns true or false if the UnitFileState ofunitmatches the (simplified)state.An error is logged and undef returned if the unit can’t be queried.
The following options are supported
force
Refresh the cache
force(passed toget_ufstatemethod).
derived
Boolean (default true) to use derived information when UnitFileState itself is empty/undefined.
Private methods¶
_getTree
The
getTreemethod is similar to the regular EDG::WP4::CCM::CacheManager::Element::getTree, except that it keeps the unitfile configuration as an Element instance (as required by NCM::Component::Systemd::UnitFile).It takes as arguments a EDG::WP4::CCM::CacheManager::Configuration instance
$configand a$pathto the root of the whole unit tree.