@@ -111,11 +111,13 @@ bundle agent standard_services(service,state)
111111#
112112# Else, if chkconfig is present, it will be used.
113113#
114- # Else, if the service command is available, if will be used.
114+ # Else, if the service command is available, it will be used.
115115#
116- # Else, if the svcadm command is available, if will be used. Note you
116+ # Else, if the svcadm command is available, it will be used. Note you
117117# have to supply the full SMF service identifier.
118118#
119+ # Else, if lssrc command is available (AIX), it will be used.
120+ #
119121# Else, control is passed to `classic_services`.
120122#
121123# Note you do **not** have to call this bundle from `services`
@@ -170,7 +172,9 @@ bundle agent standard_services(service,state)
170172 "chkconfig" expression => "!systemd._stdlib_path_exists_chkconfig";
171173 "sysvservice" expression => "!systemd.!chkconfig._stdlib_path_exists_service";
172174 "smf" expression => "!systemd.!chkconfig.!sysvservice._stdlib_path_exists_svcadm";
173- "fallback" expression => "!systemd.!chkconfig.!sysvservice.!smf";
175+ # AIX System Resource Controller https://www.ibm.com/docs/en/aix/7.2?topic=concepts-system-resource-controller
176+ "aix_src" expression => "_stdlib_path_exists_lssrc";
177+ "fallback" expression => "!systemd.!chkconfig.!sysvservice.!smf.!aix_src";
174178
175179 "have_init" expression => fileexists($(init));
176180
@@ -268,6 +272,8 @@ bundle agent standard_services(service,state)
268272 classes => kept_successful_command;
269273
270274 methods:
275+ aix_src::
276+ "aix_service" usebundle => aix_services($(service), $(state));
271277 fallback::
272278 "classic" usebundle => classic_services($(service), $(state));
273279
@@ -1098,3 +1104,74 @@ bundle agent classic_services(service,state)
10981104 "DEBUG $(this.bundle): The baseinit is NOT provided, using default"
10991105 if => not(isvariable("baseinit[$(service)]"));
11001106}
1107+
1108+ body service_method aix_service_method
1109+ {
1110+ service_bundle => aix_services("$(this.promiser)","$(this.service_policy)");
1111+ }
1112+
1113+ # example of querying state of a service on AIX
1114+ #
1115+ # bash-5.1# /usr/bin/lssrc -s sendmail
1116+ # Subsystem Group PID Status
1117+ # sendmail mail 5308762 active
1118+ #
1119+ # according to https://docs.cfengine.com/docs/3.24/reference-promise-types-services.html#service_policy
1120+ # state can be one of start, stop, enable, disable, restart and reload.
1121+ # disable/enable might be available for services in /etc/inetd.conf
1122+ # e.g. https://www.ibm.com/support/pages/ibm-aix-how-disable-rsh-and-rlogin-services
1123+ # /usr/bin/lssrc -t login, comment out lines in /etc/inetd.conf
1124+ #
1125+ # Note: This service method bundle does NOT handle inetd services like rsh/rlogin
1126+ # only subsystems aka those services listed with /usr/bin/lssrc -a
1127+ # https://www.ibm.com/docs/en/aix/7.3?topic=daemons-subsystems-subservers
1128+ #
1129+ # Also note this from the lssrc man page:
1130+ # The lssrc command output can sometimes show two entries for a particular daemon. One instance will be active and another instance will be
1131+ # inoperative. This can happen if the subsystem is modified (using the mkssys command or chssys command) without stopping the subsystem. The
1132+ # original subsystem will remain active and the modified instance will be inoperative until the subsystem is stopped and started again.
1133+ #
1134+ # Additional output may appear prefixed with Q: for example if it takes some time to change the service state:
1135+ #
1136+ # notice: Q: "...in/stopsrc -s s": 0513-056 Timeout waiting for command response. If you specified a foreign host,
1137+ # Q: "...in/stopsrc -s s": see the /etc/inittab file on the foreign host to verify that the SRC daemon
1138+ # Q: "...in/stopsrc -s s": (srcmstr) was started with the -r flag to accept remote requests.
1139+ # Q: "...in/stopsrc -s s": 0513-059 The sendmail Subsystem has been started. Subsystem PID is 13042068.
1140+ #
1141+ # Another failure case. Likely on next agent run (default of 5 minutes) the service will have stopped or we will try again.
1142+ # error: Finished command related to promiser '/usr/bin/stopsrc -s sendmail' -- an error occurred, returned 1
1143+ # notice: Q: "...in/stopsrc -s s": 0513-056 Timeout waiting for command response. If you specified a foreign host,
1144+ # Q: "...in/stopsrc -s s": see the /etc/inittab file on the foreign host to verify that the SRC daemon
1145+ # Q: "...in/stopsrc -s s": (srcmstr) was started with the -r flag to accept remote requests.
1146+ bundle agent aix_services(service, desired_state)
1147+ {
1148+ vars:
1149+ # current state can be: active, inoperative, stopping
1150+ "current_state" string => execresult("$(paths.lssrc) -s $(service) | tail -1 | awk '{print $NF}'", useshell);
1151+
1152+ classes:
1153+ "needs_start" expression => and(
1154+ strcmp("$(current_state)", "inoperative"),
1155+ strcmp("$(desired_state)", "start")
1156+ );
1157+ "needs_restart" expression => and(
1158+ strcmp("$(desired_state)", "restart")
1159+ );
1160+ "needs_stop" expression => and(
1161+ strcmp("$(current_state)", "active"),
1162+ strcmp("$(desired_state)", "stop")
1163+ );
1164+
1165+ commands:
1166+ needs_start::
1167+ "$(paths.startsrc) -s $(service)";
1168+ needs_restart::
1169+ "$(paths.stopsrc) -s $(service); $(paths.startsrc) -s $(service)"
1170+ contain => in_shell;
1171+ needs_stop::
1172+ "$(paths.stopsrc) -s $(service)";
1173+
1174+ reports:
1175+ DEBUG::
1176+ "Current state of service $(service) is $(current_state). Desired state is $(desired_state).";
1177+ }
0 commit comments