<def-group>

  <definition class="compliance" id="service_psacct_enabled" version="1">
    <metadata>
        <title>Enable Process Accounting (psacct)</title>
        
    <affected family="unix">
    <platform>Ubuntu 22.04</platform>
    </affected>
        <description>The psacct service should be enabled if possible.</description>
    </metadata>
    <criteria comment="package psacct installed and service psacct is configured to start" operator="AND">
    <criterion comment="psacct installed" test_ref="test_service_psacct_package_psacct_installed" />
      <criteria comment="service psacct is configured to start and is running" operator="AND">
        <criterion comment="psacct is running" test_ref="test_service_running_psacct" />
        <criteria operator="OR" comment="service psacct is configured to start">
          <criterion comment="multi-user.target wants psacct" test_ref="test_multi_user_wants_psacct" />
          <criterion comment="multi-user.target wants psacct socket" test_ref="test_multi_user_wants_psacct_socket" />
        </criteria>
      </criteria>
    </criteria>
  </definition>

  <linux:systemdunitdependency_test check="all" check_existence="any_exist" comment="systemd test" id="test_multi_user_wants_psacct" version="1">
    <linux:object object_ref="object_multi_user_target_for_psacct_enabled" />
    <linux:state state_ref="state_systemd_psacct_on"/>
  </linux:systemdunitdependency_test>
  <linux:systemdunitdependency_object id="object_multi_user_target_for_psacct_enabled" comment="list of dependencies of multi-user.target" version="1">
    <linux:unit>multi-user.target</linux:unit>
  </linux:systemdunitdependency_object>
  <linux:systemdunitdependency_state id="state_systemd_psacct_on" comment="psacct listed at least once in the dependencies" version="1">
    <linux:dependency entity_check="at least one">psacct.service</linux:dependency>
  </linux:systemdunitdependency_state>

  <linux:systemdunitdependency_test check="all" check_existence="any_exist" comment="systemd test" id="test_multi_user_wants_psacct_socket" version="1">
    <linux:object object_ref="object_multi_user_target_for_psacct_socket_enabled" />
    <linux:state state_ref="state_systemd_psacct_socket_on"/>
  </linux:systemdunitdependency_test>
  <linux:systemdunitdependency_object id="object_multi_user_target_for_psacct_socket_enabled" comment="list of dependencies of multi-user.target" version="1">
    <linux:unit>multi-user.target</linux:unit>
  </linux:systemdunitdependency_object>
  <linux:systemdunitdependency_state id="state_systemd_psacct_socket_on" comment="psacct listed at least once in the dependencies" version="1">
    <linux:dependency entity_check="at least one">psacct.socket</linux:dependency>
  </linux:systemdunitdependency_state>

  <linux:systemdunitproperty_test id="test_service_running_psacct" check="at least one" check_existence="at_least_one_exists" comment="Test that the psacct service is running" version="1">
    <linux:object object_ref="obj_service_running_psacct"/>
    <linux:state state_ref="state_service_running_psacct"/>
  </linux:systemdunitproperty_test>
  <linux:systemdunitproperty_object id="obj_service_running_psacct" comment="Retrieve the ActiveState property of psacct" version="1">
    <linux:unit operation="pattern match">^psacct\.(socket|service)$</linux:unit>
    <linux:property>ActiveState</linux:property>
  </linux:systemdunitproperty_object>
  <linux:systemdunitproperty_state id="state_service_running_psacct" version="1" comment="psacct is running">
      <linux:value>active</linux:value>
  </linux:systemdunitproperty_state>



  <linux:dpkginfo_test check="all" check_existence="all_exist"
  id="test_service_psacct_package_psacct_installed" version="1"
  comment="package psacct is installed">
    <linux:object object_ref="obj_test_service_psacct_package_psacct_installed" />
    
  </linux:dpkginfo_test>
  <linux:dpkginfo_object id="obj_test_service_psacct_package_psacct_installed" version="1">
    <linux:name>psacct</linux:name>
  </linux:dpkginfo_object>
  

</def-group>