Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

list_disabled_services , list_enabled_services not working #15

Open
say-paul opened this issue Jun 8, 2023 · 1 comment
Open

list_disabled_services , list_enabled_services not working #15

say-paul opened this issue Jun 8, 2023 · 1 comment

Comments

@say-paul
Copy link

say-paul commented Jun 8, 2023

let services = vec!["sshd","podman"];
let disabled_services =  match systemctl::list_disabled_services(){
        Ok(list) => list,
        Err(_) => bail!("Unable to fetch list of disabled services")
    };
    println!("disabled services : {:?}",disabled_services);
    for service in &services {
        if disabled_services.contains(&service.to_string()) {
            service_not_ok.push(service);
            log::warn!("service: {service} is disabled");
            continue;
        }
        println!("{service}: {}",systemctl::Unit::from_systemctl(service).unwrap().preset);
        match systemctl::Unit::from_systemctl(service) {
            Ok(service_details) => {
                if !service_details.active {
                    log::warn!("service: {service} is not running"); 
                    unforced_error=true;
                }
            },
            Err(err) => log::error!("Error fetching {service} status: {err}"),
        }   
    }

output is :

disabled services : []
sshd: true
podman: false
 WARN  greenboot > service: podman is not running

The disabled service list in empty where I expected podman to be present.

As

[sayan@ibm-p8-kvm-03-guest-02 ~]$ systemctl list-unit-files | grep podman
podman-auto-update.service                                                          disabled        disabled
podman-clean-transient.service                                                      disabled        disabled
podman-kube@.service                                                                disabled        disabled
podman-restart.service                                                              disabled        disabled
podman.service                                                                      disabled        disabled
podman.socket                                                                       disabled        disabled
podman-auto-update.timer                                                            disabled        disabled
@alexkunde
Copy link
Contributor

@say-paul can you please retest with the newest version in main branch?
This is what I get locally:

# list all disabled services via systemctl
systemctl list-unit-files | grep -i disabled | grep -i service | wc -l

16

# execute disabled services test only
cargo nextest run --no-capture disabled | grep -i service | wc -l

Finished test [unoptimized + debuginfo] target(s) in 0.04s
Starting 1 test across 1 binary (7 skipped)
START             systemctl test::test_disabled_services
PASS [   5.086s] systemctl test::test_disabled_services
------------
Summary [   5.086s] 1 test run: 1 passed, 7 skipped

16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants