pkg.re/essentialkaos/ek.10@v12.41.0+incompatible/initsystem/examples_test.go (about)

     1  //go:build linux || freebsd
     2  // +build linux freebsd
     3  
     4  package initsystem
     5  
     6  // ////////////////////////////////////////////////////////////////////////////////// //
     7  //                                                                                    //
     8  //                         Copyright (c) 2022 ESSENTIAL KAOS                          //
     9  //      Apache License, Version 2.0 <https://www.apache.org/licenses/LICENSE-2.0>     //
    10  //                                                                                    //
    11  // ////////////////////////////////////////////////////////////////////////////////// //
    12  
    13  import (
    14  	"fmt"
    15  )
    16  
    17  // ////////////////////////////////////////////////////////////////////////////////// //
    18  
    19  func ExampleSysV() {
    20  	if SysV() {
    21  		fmt.Println("SysV init system is used")
    22  	}
    23  }
    24  
    25  func ExampleUpstart() {
    26  	if Upstart() {
    27  		fmt.Println("Upstart init system is used")
    28  	}
    29  }
    30  
    31  func ExampleSystemd() {
    32  	if Systemd() {
    33  		fmt.Println("Systemd init system is used")
    34  	}
    35  }
    36  
    37  func ExampleIsPresent() {
    38  	serviceName := "crond"
    39  
    40  	if IsPresent(serviceName) {
    41  		fmt.Printf("Service %s is present\n", serviceName)
    42  	} else {
    43  		fmt.Printf("Unknown service %s\n", serviceName)
    44  	}
    45  }
    46  
    47  func ExampleIsWorks() {
    48  	serviceName := "crond"
    49  
    50  	works, err := IsWorks(serviceName)
    51  
    52  	if err != nil {
    53  		fmt.Printf("Error: %v\n", err)
    54  	}
    55  
    56  	if works {
    57  		fmt.Printf("Service %s is working\n", serviceName)
    58  	} else {
    59  		fmt.Printf("Service %s is stopped\n", serviceName)
    60  	}
    61  }
    62  
    63  func ExampleIsEnabled() {
    64  	serviceName := "crond"
    65  
    66  	enabled, err := IsEnabled(serviceName)
    67  
    68  	if err != nil {
    69  		fmt.Printf("Error: %v\n", err)
    70  	}
    71  
    72  	if enabled {
    73  		fmt.Printf("Service %s is enabled\n", serviceName)
    74  	} else {
    75  		fmt.Printf("Service %s is not enabled\n", serviceName)
    76  	}
    77  }