Forum: Cfengine Help Subject: Manage Solaris 10 processes (a working example) Author: kholloway Link to topic: https://cfengine.com/forum/read.php?3,20813,20813#msg-20813
For all of you using zones and CF3 on Solaris this helps to identify a process running on your current zone and excludes children zones when run in a global so you don't accidentally kill 20 processes that you didn't mean to. :) ------PUT WHEREVER YOU NEED TO UP OR DOWN A SERVICE----- bundle agent whatever { methods: # Up example.. "any" usebundle => up_process("/var/cfengine3/bin/cf-serverd","start_cfserverd"), comment => "Check that cf-serverd is running"; # Down example.. "any" usebundle => down_process("/usr/local/sbin/proftpd","stop_proftpd"), comment => "Make sure proftpd is not running for all hosts"; } ------PUT IN YOUR COMMON LIBRARY------ # CFEngine doesn't handle zones properly so this is my workaround # NOTE: This means we can't use any of the process_* commands # Each bundle below should accomodate our various needs but feel free to create another one # if you need something more. # Bundle type is common so we can set global classes for restarts, etc. # If you don't need a global class then use bundle agent instead # NOTE: common bundles that set classes complain with the following error only if on CF3 3.0.4, 3.0.5p1 fixed this bug # !! Class identifier contains illegal characters # NOTE: variables are limited to 8192 characters so on a busy/large system a normal ps -efZ will cause CF3 to exit.. :( # Bundle to check if a process is running # $setclass is created ONLY if the process is NOT running bundle common up_process(process,setclass) { vars: solaris|solarisx86:: "zonename" string => execresult('/usr/bin/zonename','noshell'); "ps_output" string => execresult('/usr/bin/ps -efZ | /usr/bin/grep ${zonename} | /usr/bin/grep "${process}" | /usr/bin/grep -v gr ep','useshell'), policy => "overridable"; classes: solaris|solarisx86:: "${setclass}" not => regcmp(".*${process}.*", "${ps_output}"); reports: debug.(solaris|solarisx86):: "Process: ${setclass} was set for process ${process} in zone ${zonename}", ifvarclass => "${setclass}"; "PS Output: ${ps_output}"; } # Bundle to make sure a process is not running # Setclass is created ONLY if process is running bundle common down_process(process,setclass) { vars: solaris|solarisx86:: "zonename" string => execresult('/usr/bin/zonename','noshell'); "ps_output" string => execresult('/usr/bin/ps -efZ | /usr/bin/grep ${zonename} | /usr/bin/grep "${process}" | /usr/bin/grep -v gr ep','useshell'), policy => "overridable"; classes: solaris|solarisx86:: "${setclass}" expression => regcmp(".*${process}.*", "${ps_output}"); reports: debug.(solaris|solarisx86):: "Process: ${setclass} was set for process ${process} in zone ${zonename}", ifvarclass => "${setclass}"; "PS Output: ${ps_output}"; } _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine