File: cfengine_stdlib.cf

package info (click to toggle)
cfengine3 3.6.2-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 20,256 kB
  • ctags: 9,613
  • sloc: ansic: 116,129; sh: 12,366; yacc: 1,088; makefile: 1,006; lex: 391; perl: 197; xml: 21; sed: 4
file content (3932 lines) | stat: -rw-r--r-- 137,352 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
############################################################################
#  Copyright (C) CFEngine AS
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License LGPL as published by the
#  Free Software Foundation; version 3.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  To the extent this program is licensed as part of the Enterprise
#  versions of CFEngine, the applicable Commercial Open Source License
#  (COSL) may apply to this file if you as a licensee so wish it. See
#  included file COSL.txt.
###########################################################################
#
# CFEngine Community Open Promise-Body Library
#
# This initiative started by CFEngine promotes a
# standardized set of names and promise specifications
# for template functionality within CFEngine 3.
#
# The aim is to promote an industry standard for
# naming of configuration patterns, leading to a
# de facto middleware of standardized syntax.
#
# Names should be intuitive and parameters should be
# minimal to assist readability and comprehensibility.

# Contributions to this file are voluntarily given to
# the cfengine community, and are moderated by CFEngine.
# No liability or warranty for misuse is implied.
#
# If you add to this file, please try to make the
# contributions "self-documenting". Comments made
# after the bundle/body statement are retained in
# the online docs
#

# For CFEngine Core: 3.4.x (use lib/3.N for CFEngine 3.5.x and newer)

###################################################
# If you find CFEngine useful, please consider    #
# purchasing a commercial version of the software.#
###################################################

###################################################
# edit_line bundles
###################################################

bundle edit_line insert_lines(lines)
{
  insert_lines:

      "$(lines)"
      comment => "Append lines if they don't exist";
}

##

bundle edit_line insert_file(templatefile)
{
  insert_lines:

      "$(templatefile)"
      comment => "Insert the template file into the file being edited",
      insert_type => "file";
}

##

bundle edit_line comment_lines_matching(regex,comment)

# Comment lines of a file matching a regex

{
  replace_patterns:

      "^($(regex))$"

      replace_with => comment("$(comment)"),
      comment => "Search and replace string";
}

##

bundle edit_line uncomment_lines_matching(regex,comment)

# Uncomment lines of a file where the regex matches
# the text after the comment string

{
  replace_patterns:

      "^$(comment)\s?($(regex))$"

      replace_with => uncomment,
      comment => "Uncomment lines matching a regular expression";
}

##

bundle edit_line comment_lines_containing(regex,comment)

# Comment lines of a file containing a regex

{
  replace_patterns:

      "^((?!$(comment)).*$(regex).*)$"

      replace_with => comment("$(comment)"),
      comment => "Comment out lines in a file";
}

##

bundle edit_line uncomment_lines_containing(regex,comment)

# Uncomment lines of a file where the regex matches
# the text after the comment string

{
  replace_patterns:

      "^$(comment)\s?(.*$(regex).*)$"

      replace_with => uncomment,
      comment => "Uncomment a line containing a fragment";
}

##

bundle edit_line delete_lines_matching(regex)
{
  delete_lines:

      "$(regex)"

      comment => "Delete lines matching regular expressions";
}

##

bundle edit_line warn_lines_matching(regex)
{
  delete_lines:

      "$(regex)"

      comment => "Warn about lines in a file",
      action => warn_only;
}

##

bundle edit_line append_if_no_line(str)
{
  insert_lines:

      "$(str)"

      comment => "Append a line to the file if it doesn't already exist";
}

##

bundle edit_line append_if_no_lines(list)
{
  insert_lines:

      "$(list)"

      comment => "Append lines to the file if they don't already exist";
}

##

bundle edit_line replace_line_end(start,end)
#
# Lines starting with "$(start)" will get the ending given in "$(end)",
# whitespaces will be left unmodified.
# For example, replace_line_end("ftp", "2121/tcp") would replace
# "ftp             21/tcp"
# with
# "ftp             2121/tcp"
{
  field_edits:

      "\s*$(start)\s.*"
      comment => "Replace lines with $(this.start) and $(this.end)",
      edit_field => line("(^|\s)$(start)\s*", "2", "$(end)","set");
}

##

bundle edit_line append_to_line_end(start,end)
#
# Lines starting with "$(start)" and not ending with "$(end)"
# will get appended with "$(end)", whitespaces will be left unmodified.
# For example, append_to_line_end("kernel", "vga=791") would replace
# "kernel /boot/vmlinuz root=/dev/sda7"
# with
# "kernel /boot/vmlinuz root=/dev/sda7 resume=/dev/sda9 vga=791"
#
# WARNING: Be careful not to have multiple promises matching the same line,
#          which would result in the line growing indefinetively.
{
  field_edits:

      "\s*$(start)\s.*"
      comment => "Append lines with $(this.start) and $(this.end)",
      edit_field => line("(^|\s)$(start)\s*", "2", "$(end)","append");
}

##

bundle edit_line regex_replace(find,replace)
# You can think of this like a PCRE powered sed.
# Find exactly a regular expression and replace exactly the match with a string.
{
  replace_patterns:

      "$(find)"
      replace_with => value("$(replace)"),
      comment => "Search and replace string";
}

##

bundle edit_line resolvconf(search,list)

# search is the search domains with space
# list is an slist of nameserver addresses

{
  delete_lines:

      "search.*"     comment => "Reset search lines from resolver";
      "nameserver.*" comment => "Reset nameservers in resolver";

  insert_lines:

      "search $(search)"    comment => "Add search domains to resolver";
      "nameserver $(list)"  comment => "Add name servers to resolver";
}

##

bundle edit_line manage_variable_values_ini(tab, sectionName)

# Sets the RHS of configuration items in the file of the form
# LHS=RHS
# If the line is commented out with #, it gets uncommented first.
# Adds a new line if none exists.
# Removes any variable value pairs not defined for the ini section
# The argument is an associative array containing tab[SectionName][LHS]="RHS"
# don't change value when the RHS is dontchange

# Based on set_variable_values_ini
# Added delete lines section to empty out undefined variable values for INI section

#
# If you are running 3.2.1 or earlier or more specifically git commit # or
# earlier you can use this to work around the segfault bug.
# vars:
#     "$(file)"
#         edit_line => append_if_no_line("[#EOF#]"),
#         create => "true",
#         comment => "Work around bug<bug#here> where eof did not mean end
#                     of section and thus cannot select a region. This promise
#                     should be placed before your call to this bundle";
#      "$(file)"
#         edit_line   => manage_variable_values_ini("context.array", "SectionName"),
#         create => "true",
#         comment     => "Set the variale values only in the specified ini region";
#

{
  vars:
      "index" slist => getindices("$(tab)[$(sectionName)]");

      # Be careful if the index string contains funny chars
      "cindex[$(index)]" string => canonify("$(index)");

  classes:
      "edit_$(cindex[$(index)])"     not => strcmp("$($(tab)[$(sectionName)][$(index)])","dontchange"),
      comment => "Create conditions to make changes";

  field_edits:

      # If the line is there, but commented out, first uncomment it
      "#+\s*$(index)\s*=.*"
      select_region => INI_section("$(sectionName)"),
      edit_field => col("=","1","$(index)","set"),
      ifvarclass => "edit_$(cindex[$(index)])";

      # match a line starting like the key something
      "$(index)\s*=.*"
      edit_field => col("=","2","$($(tab)[$(sectionName)][$(index)])","set"),
      select_region => INI_section("$(sectionName)"),
      classes => if_ok("manage_variable_values_ini_not_$(cindex[$(index)])"),
      ifvarclass => "edit_$(cindex[$(index)])";

  delete_lines:
      ".*"
      select_region => INI_section("$(sectionName)"),
      comment       => "Remove all entries in the region so there are no extra entries";

  insert_lines:
      "[$(sectionName)]"
      location => start,
      comment => "Insert lines";

      "$(index)=$($(tab)[$(sectionName)][$(index)])"
      select_region => INI_section("$(sectionName)"),
      ifvarclass => "!manage_variable_values_ini_not_$(cindex[$(index)]).edit_$(cindex[$(index)])";

}

##

bundle edit_line set_variable_values_ini(tab, sectionName)

# Sets the RHS of configuration items in the file of the form
# LHS=RHS
# If the line is commented out with #, it gets uncommented first.
# Adds a new line if none exists.
# The argument is an associative array containing tab[SectionName][LHS]="RHS"
# don't change value when the RHS is dontchange

# Based on set_variable_values from cfengine_stdlib.cf, modified to
# use section to define were to write, and to handle commented-out lines.

#
# If you are running 3.2.1 or earlier or more specifically git commit # or
# earlier you can use this to work around the segfault bug.
# vars:
#     "$(file)"
#         edit_line => append_if_no_line("[#EOF#]"),
#         create => "true",
#         comment => "Work around bug<bug#here> where eof did not mean end
#                     of section and thus cannot select a region. This promise
#                     should be placed before your call to this bundle";
#      "$(file)"
#         edit_line   => set_variable_values_ini("context.array", "SectionName"),
#         create => "true",
#         comment     => "Set the variale values only in the specified ini region";
#

{
  vars:
      "index" slist => getindices("$(tab)[$(sectionName)]");

      # Be careful if the index string contains funny chars
      "cindex[$(index)]" string => canonify("$(index)");

  classes:
      "edit_$(cindex[$(index)])"     not => strcmp("$($(tab)[$(sectionName)][$(index)])","dontchange"),
      comment => "Create conditions to make changes";

  field_edits:

      # If the line is there, but commented out, first uncomment it
      "#+\s*$(index)\s*=.*"
      select_region => INI_section("$(sectionName)"),
      edit_field => col("=","1","$(index)","set"),
      ifvarclass => "edit_$(cindex[$(index)])";

      # match a line starting like the key something
      "$(index)\s*=.*"
      edit_field => col("=","2","$($(tab)[$(sectionName)][$(index)])","set"),
      select_region => INI_section("$(sectionName)"),
      classes => if_ok("set_variable_values_ini_not_$(cindex[$(index)])"),
      ifvarclass => "edit_$(cindex[$(index)])";

  insert_lines:
      "[$(sectionName)]"
      location => start,
      comment => "Insert lines";

      "$(index)=$($(tab)[$(sectionName)][$(index)])"
      select_region => INI_section("$(sectionName)"),
      ifvarclass => "!set_variable_values_ini_not_$(cindex[$(index)]).edit_$(cindex[$(index)])";

}

bundle edit_line set_quoted_values(v)
{
      # Sets the RHS of variables in shell-like files
      #   that is:
      #      LHS="RHS"
      # Adds a new line if no LHS exists
      # repairs RHS values if one does exist
      # If the line is commented out with #, it gets uncommented first.
      #
      # To use:
      #   1) Define an array, where the keys are the LHS and the values are the RHS
      #        "stuff[lhs-1]" string => "rhs1";
      #        "stuff[lhs-2]" string => "rhs2";
      #   2) The parameter passed to the edit_line promise is the fully qualified
      #      name of the array (i.e., "bundlename.stuff") WITHOUT any "$" or "@"

  vars:
      "index" slist => getindices("$(v)");
      # Be careful if the index string contains funny chars

      "cindex[$(index)]" string => canonify("$(index)");

  field_edits:
      # If the line is there, but commented out, first uncomment it
      "#+\s*$(index)\s*=.*"
      edit_field => col("=","1","$(index)","set");

      # match a line starting like the key = something
      "\s*$(index)\s*=.*"
      edit_field => col("=","2",'"$($(v)[$(index)])"',"set"),
      classes    => if_ok("$(cindex[$(index)])_in_file"),
      comment    => "Match a line starting like key = something";

  insert_lines:
      '$(index)="$($(v)[$(index)])"'
      comment    => "Insert a variable definition",
      ifvarclass => "!$(cindex[$(index)])_in_file";
}

##

bundle edit_line set_variable_values(v)

# Sets the RHS of variables in the file of the form
#   LHS = RHS
# Adds a new line if no LHS exists, repairs RHS values if one does exist
#
# To use:
#   1) Define an array, where the keys are the LHS and the values are the RHS
#        "stuff[lhs-1]" string => "rhs1";
#        "stuff[lhs-2]" string => "rhs2";
#   2) The parameter passed to the edit_line promise is the fully qualified
#      name of the array (i.e., "bundlename.stuff") WITHOUT any "$" or "@"

{
  vars:

      "index" slist => getindices("$(v)");

      # Be careful if the index string contains funny chars

      "cindex[$(index)]" string => canonify("$(index)");
      "cv"               string => canonify("$(v)");

  field_edits:

      # match a line starting like the key = something

      "\s*$(index)\s*=.*"

      edit_field => col("=","2","$($(v)[$(index)])","set"),
      classes => if_ok("$(cv)_$(cindex[$(index)])_in_file"),
      comment => "Match a line starting like key = something";

  insert_lines:

      "$(index)=$($(v)[$(index)])"

      comment => "Insert a variable definition",
      ifvarclass => "!$(cv)_$(cindex[$(index)])_in_file";
}

bundle edit_line set_config_values(v)

# Sets the RHS of configuration items in the file of the form
#   LHS RHS
# If the line is commented out with #, it gets uncommented first.
# Adds a new line if none exists.
# The argument is the fully-qualified name of an associative array containing v[LHS]="rhs"

{
  vars:
      "index" slist => getindices("$(v)");

      # Be careful if the index string contains funny chars
      "cindex[$(index)]" string => canonify("$(index)");

  replace_patterns:
      # If the line is there, maybe commented out, uncomment and replace with
      # the correct value
      "^\s*($(index)\s+(?!$($(v)[$(index)])$).*|# ?$(index)\s+.*)$"
      comment => "Correct the value",
      replace_with => value("$(index) $($(v)[$(index)])"),
      classes => always("replace_attempted_$(cindex[$(index)])");

  insert_lines:
      "$(index) $($(v)[$(index)])"
      ifvarclass => "replace_attempted_$(cindex[$(index)])";

}

bundle edit_line set_config_values_matching(v,pat)

# Sets the RHS of configuration items in the file of the form
#   LHS RHS
# If the line is commented out with #, it gets uncommented first.
# Adds a new line if none exists.
# Only elements of "v" that match the regex "pat" are used
# The argument is the fully-qualified name of an associative array containing v[LHS]="rhs"

{
  vars:
      "allparams" slist => getindices("$(v)");
      "index"     slist => grep("$(pat)", "allparams");

      # Be careful if the index string contains funny chars
      "cindex[$(index)]" string => canonify("$(index)");

  replace_patterns:
      # If the line is there, maybe commented out, uncomment and replace with
      # the correct value
      "^\s*($(index)\s+(?!$($(v)[$(index)])).*|# ?$(index)\s+.*)$"
      comment => "Correct the value",
      replace_with => value("$(index) $($(v)[$(index)])"),
      classes => always("replace_attempted_$(cindex[$(index)])");

  insert_lines:
      "$(index) $($(v)[$(index)])"
      ifvarclass => "replace_attempted_$(cindex[$(index)])";

}

##

bundle edit_line maintain_key_values(v,sep)

# Contributed by David Lee
# Purpose: Sets the RHS of configuration items with an giving separator

{
  vars:
      "index" slist => getindices("$(v)");
      # Be careful if the index string contains funny chars
      "cindex[$(index)]" string => canonify("$(index)");
      # Matching pattern for line (basically key-and-separator)
      "keypat[$(index)]" string => "\s*$(index)\s*$(sep)\s*";

      # Values may contain regexps. Escape them for replace_pattern matching.
      "ve[$(index)]" string => escape("$($(v)[$(index)])");

  classes:
      "$(cindex[$(index)])_key_in_file"
      comment => "Dynamic Class created if patterns matching",
      expression => regline("^$(keypat[$(index)]).*", "$(edit.filename)");

  replace_patterns:
      # For convergence need to use negative lookahead on value:
      # "key sep (?!value).*"
      "^($(keypat[$(index)]))(?!$(ve[$(index)])$).*"
      comment => "Replace definition of $(index)",
      replace_with => value("$(match.1)$($(v)[$(index)])");

  insert_lines:
      "$(index)$(sep)$($(v)[$(index)])"
      comment => "Insert definition of $(index)",
      ifvarclass => "!$(cindex[$(index)])_key_in_file";
}

##

bundle edit_line append_users_starting(v)

# For adding to /etc/passwd or etc/shadow, needs
# an array v[username] string => "line..."

{
  vars:

      "index"        slist => getindices("$(v)");

  classes:

      "add_$(index)"     not => userexists("$(index)"),
      comment => "Class created if user does not exist";

  insert_lines:

      "$($(v)[$(index)])"

      comment => "Append users into a password file format",
      ifvarclass => "add_$(index)";
}

##

bundle edit_line append_groups_starting(v)

# For adding groups to /etc/group, needs
# an array v[groupname] string => "line..."

{
  vars:

      "index"        slist => getindices("$(v)");

  classes:

      "add_$(index)"     not => groupexists("$(index)"),
      comment => "Class created if group does not exist";

  insert_lines:

      "$($(v)[$(index)])"

      comment => "Append users into a group file format",
      ifvarclass => "add_$(index)";

}

##

bundle edit_line set_colon_field(key,field,val)

# Set the value of field number "field" of the
# line whose first field is "key", in a colon-separated file.

{
  field_edits:

      "$(key):.*"

      comment => "Edit a colon-separated file, using the first field as a key",
      edit_field => col(":","$(field)","$(val)","set");
}

##

bundle edit_line set_user_field(user,field,val)

# Set the value of field number "field" in
# a :-field formatted file like /etc/passwd

{
  field_edits:

      "$(user):.*"

      comment => "Edit a user attribute in the password file",
      edit_field => col(":","$(field)","$(val)","set");
}

##

bundle edit_line append_user_field(group,field,allusers)

# For adding users to to a file like /etc/group
# at field position "field", comma separated subfields

{
  vars:

      "val" slist => { @(allusers) };

  field_edits:

      "$(group):.*"

      comment => "Append users into a password file format",
      edit_field => col(":","$(field)","$(val)","alphanum");
}

##

bundle edit_line expand_template(templatefile)

# Read in the named text file and expand $(var)
# inside the file

{
  insert_lines:

      "$(templatefile)"

      insert_type => "file",
      comment => "Expand variables in the template file",
      expand_scalars => "true";
}

bundle edit_line replace_or_add(pattern,line)

# Replace a pattern in a file with a single line.
# If the pattern is not found, add the line to the file.
# The pattern must match the whole line (it is automatically
# anchored to the start and end of the line) to avoid
# ambiguity.

{
  vars:
      "cline" string => canonify("$(line)");
      "eline" string => escape("$(line)");

  replace_patterns:
      "^(?!$(eline)$)$(pattern)$"
      comment => "Replace a pattern here",
      replace_with => value("$(line)"),
      classes => always("replace_done_$(cline)");

  insert_lines:
      "$(line)"
      ifvarclass => "replace_done_$(cline)";
}

##

bundle agent cronjob(commands,user,hours,mins)

# For adding lines to crontab for a user
# methods:
#  "cron" usebundle => cronjob("/bin/ls","mark","*","5,10");

{
  vars:
    SuSE::
      "crontab" string => "/var/spool/cron/tabs";
    redhat|fedora::
      "crontab" string => "/var/spool/cron";
    freebsd::
      "crontab" string => "/var/cron/tabs";
    !(SuSE|redhat|fedora|freebsd)::
      "crontab" string => "/var/spool/cron/crontabs";

  files:

    !windows::
      "$(crontab)/$(user)"

      comment => "A user's regular batch jobs are added to this file",
      create => "true",
      edit_line => append_if_no_line("$(mins) $(hours) * * * $(commands)"),
      perms => mo("600","$(user)"),
      classes => if_repaired("changed_crontab");

  processes:

    changed_crontab::
      "cron"
      comment => "Most crons need to be huped after file changes",
      signals => { "hup" };

}

##-------------------------------------------------------
## editing bodies
##-------------------------------------------------------

body edit_field quoted_var(newval,method)
{
      field_separator => "\"";
      select_field    => "2";
      value_separator  => " ";
      field_value     => "$(newval)";
      field_operation => "$(method)";
      extend_fields => "false";
      allow_blank_fields => "true";
}

##

body edit_field col(split,col,newval,method)
{
      field_separator    => "$(split)";
      select_field       => "$(col)";
      value_separator    => ",";
      field_value        => "$(newval)";
      field_operation    => "$(method)";
      extend_fields      => "true";
      allow_blank_fields => "true";
}

##

body edit_field line(split,col,newval,method)
{
      field_separator    => "$(split)";
      select_field       => "$(col)";
      value_separator    => " ";
      field_value        => "$(newval)";
      field_operation    => "$(method)";
      extend_fields      => "true";
      allow_blank_fields => "true";
}

##

body replace_with value(x)
{
      replace_value => "$(x)";
      occurrences => "all";
}

##

body select_region INI_section(x)
{
      select_start => "\[$(x)\]\s*";
      select_end => "\[.*\]\s*";
}

##-------------------------------------------------------
## edit_defaults
##-------------------------------------------------------

body edit_defaults std_defs
{
      empty_file_before_editing => "false";
      edit_backup => "false";
      #max_file_size => "300000";
}

##

body edit_defaults empty
{
      empty_file_before_editing => "true";
      edit_backup => "false";
      #max_file_size => "300000";
}

##

body edit_defaults no_backup
{
      edit_backup => "false";
}

##

body edit_defaults backup_timestamp
{
      empty_file_before_editing => "false";
      edit_backup => "timestamp";
      #max_file_size => "300000";
}

##-------------------------------------------------------
## location
##-------------------------------------------------------

body location start
{
      before_after => "before";
}

##

body location after(str)
{
      before_after => "after";
      select_line_matching => "$(str)";
}

##

body location before(str)
{
      before_after => "before";
      select_line_matching => "$(str)";
}

##-------------------------------------------------------
## replace_with
##-------------------------------------------------------

##

body replace_with comment(c)
{
      replace_value => "$(c) $(match.1)";
      occurrences => "all";
}

##

body replace_with uncomment
{
      replace_value => "$(match.1)";
      occurrences => "all";
}

####################################################
## agent bodyparts
####################################################

##-------------------------------------------------------
## action
##-------------------------------------------------------

body action if_elapsed(x)
{
      ifelapsed => "$(x)";
      expireafter => "$(x)";
}

##

body action if_elapsed_day
{
      ifelapsed => "1440";    # 60 x 24
      expireafter => "1400";
}

##

body action measure_performance(x)
{
      measurement_class => "Detect changes in $(this.promiser)";
      ifelapsed => "$(x)";
      expireafter => "$(x)";
}

##

body action warn_only
{
      action_policy => "warn";
      ifelapsed => "60";
}

##

body action bg(elapsed,expire)
{
      ifelapsed   => "$(elapsed)";
      expireafter => "$(expire)";
      background  => "true";
}

##

body action ifwin_bg
{
    windows::
      background => "true";
}

##

body action immediate
{
      ifelapsed => "0";
}

##

body action policy(p)
{
      action_policy => "$(p)";
}

##

# Log a message to log=[/file|stdout]

body action log_repaired(log,message)
{
      log_string => "$(sys.date), $(message)";
      log_repaired => "$(log)";
}

###

body action log_verbose
{
      log_level => "verbose";
}

##-------------------------------------------------------
## contain
##-------------------------------------------------------

body contain silent
{
      no_output => "true";
}

##

body contain in_dir(s)
{
      chdir => "$(s)";
}

##

body contain in_dir_shell(s)
{
      chdir => "$(s)";
      useshell => "true"; # canonical "useshell" but this is backwards-compatible
}

##

body contain silent_in_dir(s)
{
      chdir => "$(s)";
      no_output => "true";
}

##

body contain in_shell
{
      useshell => "true"; # canonical "useshell" but this is backwards-compatible
}

##

body contain in_shell_bg
{
      useshell => "true"; # canonical "useshell" but this is backwards-compatible
}

##

body contain in_shell_and_silent
{
      useshell => "true"; # canonical "useshell" but this is backwards-compatible
      no_output => "true";
}

##

body contain in_dir_shell_and_silent(dir)
{
      useshell => "true"; # canonical "useshell" but this is backwards-compatible
      no_output => "true";
      chdir => "$(dir)";
}

##

body contain setuid(x)
{
      exec_owner => "$(x)";
      useshell => "false"; # canonical "noshell" but this is backwards-compatible
}

##

body contain setuid_sh(x)
{
      exec_owner => "$(x)";
      useshell => "true"; # canonical "useshell" but this is backwards-compatible
}

##

body contain setuidgid_sh(owner,group)
{
      exec_owner => "$(owner)";
      exec_group => "$(group)";
      useshell => "true"; # canonical "useshell" but this is backwards-compatible
}

##

body contain jail(owner,root,dir)
{
      exec_owner => "$(owner)";
      useshell => "true"; # canonical "useshell" but this is backwards-compatible
      chdir => "$(dir)";
      chroot => "$(root)";
}

##

body contain setuid_umask(uid, umask)
###################################################
#       | Files               | Directories       #
###################################################
# Umask | Octal   Symbolic    | Octal   Symbolic  #
########+#####################+###################+
# 000   | 666     (rw-rw-rw-) | 777     (rwxrwxrwx)
# 002   | 664     (rw-rw-r--) | 775     (rwxrwxr-x)
# 022   | 644     (rw-r--r--) | 755     (rwxr-xr-x)
# 027   | 640     (rw-r-----) | 750     (rwxr-x---)
# 077   | 600     (rw-------) | 700     (rwx------)
# 277   | 400     (r--------) | 500     (r-x------)
{
      exec_owner => "$(uid)";
      umask => "$(umask)";
}

##-------------------------------------------------------
## classes
##-------------------------------------------------------

body classes if_repaired(x)
{
      promise_repaired => { "$(x)" };
}

##

body classes if_else(yes,no)

{
      promise_kept     => { "$(yes)" };
      promise_repaired => { "$(yes)" };
      repair_failed    => { "$(no)" };
      repair_denied    => { "$(no)" };
      repair_timeout   => { "$(no)" };
}

##

body classes cf2_if_else(yes,no)

# meant to match cf2 semantics

{
      promise_repaired => { "$(yes)" };
      repair_failed    => { "$(no)" };
      repair_denied    => { "$(no)" };
      repair_timeout   => { "$(no)" };
}

##

body classes if_notkept(x)
{
      repair_failed   => { "$(x)" };
      repair_denied   => { "$(x)" };
      repair_timeout  => { "$(x)" };
}

##

body classes if_ok(x)
{
      promise_repaired => { "$(x)" };
      promise_kept => { "$(x)" };
}

##

body classes if_ok_cancel(x)
{
      cancel_repaired => { "$(x)" };
      cancel_kept => { "$(x)" };
}

##

body classes cmd_repair(code,cl)
{
      repaired_returncodes => { "$(code)" };
      promise_repaired => { "$(cl)" };
}

body classes classes_generic(x)
# Define x prefixed/suffixed with promise outcome
{
      promise_repaired => { "promise_repaired_$(x)", "$(x)_repaired", "$(x)_ok", "$(x)_reached" };
      repair_failed => { "repair_failed_$(x)", "$(x)_failed", "$(x)_not_ok", "$(x)_not_kept", "$(x)_not_repaired", "$(x)_reached" };
      repair_denied => { "repair_denied_$(x)", "$(x)_denied", "$(x)_not_ok", "$(x)_not_kept", "$(x)_not_repaired", "$(x)_reached" };
      repair_timeout => { "repair_timeout_$(x)", "$(x)_timeout", "$(x)_not_ok", "$(x)_not_kept", "$(x)_not_repaired", "$(x)_reached" };
      promise_kept => { "promise_kept_$(x)", "$(x)_kept", "$(x)_ok", "$(x)_not_repaired", "$(x)_reached" };
}

##-------------------------------------------------------
## Persistent classes
##-------------------------------------------------------

body classes state_repaired(x)
{
      promise_repaired => { "$(x)" };
      persist_time => "10";
}

##

body classes enumerate(x)

#
# This is used by commercial editions to count
# instances of jobs in a cluster
#

{
      promise_repaired => { "mXC_$(x)" };
      promise_kept => { "mXC_$(x)" };
      persist_time => "15";
}

##

body classes always(x)

# Define a class no matter what the outcome of the promise is

{
      promise_repaired => { "$(x)" };
      promise_kept => { "$(x)" };
      repair_failed => { "$(x)" };
      repair_denied => { "$(x)" };
      repair_timeout => { "$(x)" };
}

###################################################
# agent bundles
###################################################

##..................................................
## files promises
##..................................................

# this is a workaround for the issue that recurse_with_base precludes
# a file from being deleted
bundle agent rm_rf(name)
{
  classes:
      "isdir" expression => isdir($(name));
  files:
    isdir::
      "$(name)"
      file_select => all,
      depth_search => recurse_with_base(999),
      delete => tidy;

    !isdir::
      "$(name)" delete => tidy;
}

##-------------------------------------------------------
## copy_from
##-------------------------------------------------------

body copy_from secure_cp(from,server)
{
      source      => "$(from)";
      servers     => { "$(server)" };
      compare     => "digest";
      encrypt     => "true";
      verify      => "true";
}

##

body copy_from remote_cp(from,server)
{
      servers     => { "$(server)" };
      source      => "$(from)";
      compare     => "mtime";
}

##

body copy_from remote_dcp(from,server)
{
      servers     => { "$(server)" };
      source      => "$(from)";
      compare     => "digest";
}

##

body copy_from local_cp(from)
{
      source      => "$(from)";
}

##

body copy_from local_dcp(from)
{
      source      => "$(from)";
      compare     => "digest";
}

##

body copy_from perms_cp(from)
{
      source      => "$(from)";
      preserve    => "true";
}

body copy_from backup_local_cp(from)
# Local copy, keeping a backup of old versions
{
      source      => "$(from)";
      copy_backup => "timestamp";
}

##

# Copy only if the file does not already exist, i.e. seed the placement

body copy_from seed_cp(from)
{
      source      => "$(from)";
      compare     => "exists";
}

##

body copy_from sync_cp(from,server)
{
      servers     => { "$(server)" };
      source      => "$(from)";
      purge       => "true";
      preserve    => "true";
      type_check  => "false";
}

##

body copy_from no_backup_cp(from)
{
      source      => "$(from)";
      copy_backup => "false";
}

##

body copy_from no_backup_dcp(from)
{
      source      => "$(from)";
      copy_backup => "false";
      compare     => "digest";
}

##

body copy_from no_backup_rcp(from,server)
{
      servers     => { "$(server)" };
      source      => "$(from)";
      compare     => "mtime";
      copy_backup => "false";
}

##-------------------------------------------------------
## link_from
##-------------------------------------------------------

body link_from ln_s(x)
{
      link_type => "symlink";
      source => "$(x)";
      when_no_source => "force";
}

##

body link_from linkchildren(tofile)
{
      source        => "$(tofile)";
      link_type     => "symlink";
      when_no_source  => "force";
      link_children => "true";
      when_linking_children => "if_no_such_file"; # "override_file";
}

##-------------------------------------------------------
## perms
##-------------------------------------------------------

body perms m(mode)
{
      mode   => "$(mode)";
}

##

body perms mo(mode,user)
{
      owners => { "$(user)" };
      mode   => "$(mode)";
}

##

body perms mog(mode,user,group)
{
      owners => { "$(user)" };
      groups => { "$(group)" };
      mode   => "$(mode)";
}

##

body perms og(u,g)
{
      owners => { "$(u)" };
      groups => { "$(g)" };
}

##

body perms owner(user)
{
      owners => { "$(user)" };
}

##-------------------------------------------------------
## ACLS (extended Unix perms)
##-------------------------------------------------------

body acl access_generic(acl)
# default/inherited ACLs are left unchanged,
# applicable for both files and directories on all platforms
{
      acl_method => "overwrite";
      aces => { "@(acl)" };

    windows::
      acl_type => "ntfs";

    !windows::
      acl_type => "posix";
}

##

body acl ntfs(acl)
{
      acl_type => "ntfs";
      acl_method => "overwrite";
      aces => { "@(acl)" };
}

##

body acl strict
# NOTE: May need to take ownership of file/dir
# to be sure no-one else is allowed access
{
      acl_method => "overwrite";

    windows::
      aces => { "user:Administrator:rwx" };
    !windows::
      aces => { "user:root:rwx" };
}

##-------------------------------------------------------
## depth_search
##-------------------------------------------------------

body depth_search recurse(d)

{
      depth => "$(d)";
      xdev  => "true";
}

##

body depth_search recurse_ignore(d,list)
{
      depth => "$(d)";
      exclude_dirs => { @(list) };
}

##

body depth_search include_base
{
      include_basedir => "true";
}

body depth_search recurse_with_base(d)
{
      depth => "$(d)";
      xdev  => "true";
      include_basedir => "true";
}

##-------------------------------------------------------
## delete
##-------------------------------------------------------

body delete tidy

{
      dirlinks => "delete";
      rmdirs   => "true";
}

##-------------------------------------------------------
## rename
##-------------------------------------------------------

body rename disable
{
      disable => "true";
}

##

body rename rotate(level)
{
      rotate => "$(level)";
}

##

body rename to(file)
{
      newname => "$(file)";
}

##-------------------------------------------------------
## file_select
##-------------------------------------------------------

body file_select name_age(name,days)
{
      leaf_name   => { "$(name)" };
      mtime       => irange(0,ago(0,0,"$(days)",0,0,0));
      file_result => "mtime.leaf_name";
}

##

body file_select days_old(days)
{
      mtime       => irange(0,ago(0,0,"$(days)",0,0,0));
      file_result => "mtime";
}

##

body file_select size_range(from,to)
{
      search_size => irange("$(from)","$(to)");
      file_result => "size";
}

##

body file_select exclude(name)
{
      leaf_name  => { "$(name)"};
      file_result => "!leaf_name";
}

##

body file_select plain
{
      file_types  => { "plain" };
      file_result => "file_types";
}

body file_select dirs
{
      file_types  => { "dir" };
      file_result => "file_types";
}

##

body file_select by_name(names)
{
      leaf_name  => { @(names)};
      file_result => "leaf_name";
}

##

body file_select ex_list(names)
{
      leaf_name  => { @(names)};
      file_result => "!leaf_name";
}

##

body file_select all
{
      leaf_name => { ".*" };
      file_result => "leaf_name";
}

##

body file_select older_than(years, months, days, hours, minutes, seconds)
# Generic older_than selection body, aimed to have a common definition handy
# for every case possible.
{
      mtime       => irange(0,ago("$(years)","$(months)","$(days)","$(hours)","$(minutes)","$(seconds)"));
      file_result => "mtime";
}

##

body file_select filetype_older_than(filetype, days)
# Select files of specified type older than specified number of days
# Note: This body only takes a single filetype, see filetypes_older_than
#       if you want to select more than one type of file
{
      file_types => { "$(filetype)" };
      mtime      => irange(0,ago(0,0,"$(days)",0,0,0));
      file_result => "file_types.mtime";
}

##

body file_select filetypes_older_than(filetypes, days)
# Select files of specified type older than specified number of days
# Note: This body only takes a list of filetypes
{
      file_types => { @(filetypes) };
      mtime      => irange(0,ago(0,0,"$(days)",0,0,0));
      file_result => "file_types.mtime";
}

##-------------------------------------------------------
## changes
##-------------------------------------------------------

body changes detect_all_change

# This is fierce, and will cost disk cycles

{
      hash           => "best";
      report_changes => "all";
      update_hashes  => "yes";
}

##

body changes detect_all_change_using(hash)

# Detect all changes using a configurable hashing algorithm
# for times when you care about both content and file stats e.g. mtime
# hash - supported hashing algorithm (md5, sha1, sha224, sha256, sha384,
#   sha512, best)

{
      hash           => "$(hash)";
      report_changes => "all";
      update_hashes  => "yes";
}

##

body changes detect_content

# This is a cheaper alternative

{
      hash           => "md5";
      report_changes => "content";
      update_hashes  => "yes";
}

##

body changes detect_content_using(hash)

# Detect content changes using a configurable hashing algorithm
# for times when you only care about content, not file stats e.g. mtime
# hash - supported hashing algorithm (md5, sha1, sha224, sha256, sha384,
#   sha512, best)

{
      hash           => "$(hash)";
      report_changes => "content";
      update_hashes  => "yes";
}

##

body changes noupdate
# Use on (small) files that should never change
{
      hash           => "sha256";
      report_changes => "content";
      update_hashes  => "no";
}

##

body changes diff
# Generates diff report (Nova and above)
{
      hash           => "sha256";
      report_changes => "content";
      report_diffs   => "true";
      update_hashes  => "yes";
}

##

body changes all_changes
# Generates diff report (Nova and above)
{
      hash           => "sha256";
      report_changes => "all";
      report_diffs   => "true";
      update_hashes  => "yes";
}

##

body changes diff_noupdate
{
      hash           => "sha256";
      report_changes => "content";
      report_diffs   => "true";
      update_hashes  => "no";
}

##--------------------------------------------------------------
## Packages promises
##--------------------------------------------------------------

body package_method zypper

{
      package_changes => "bulk";

      package_list_command => "$(paths.path[rpm]) -qa --queryformat \"i | repos | %{name} | %{version}-%{release} | %{arch}\n\"";

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_command => "$(paths.path[zypper]) list-updates";
      package_list_update_ifelapsed => "240";

      package_patch_list_command => "$(paths.path[zypper]) patches";
      package_installed_regex => "i.*";
      package_list_name_regex    => "[^|]+\|[^|]+\|\s+([^\s]+).*";
      package_list_version_regex => "[^|]+\|[^|]+\|[^|]+\|\s+([^\s]+).*";
      package_list_arch_regex    => "[^|]+\|[^|]+\|[^|]+\|[^|]+\|\s+([^\s]+).*";

      package_patch_installed_regex => ".*Installed.*|.*Not Applicable.*";
      package_patch_name_regex    => "[^|]+\|\s+([^\s]+).*";
      package_patch_version_regex => "[^|]+\|[^|]+\|\s+([^\s]+).*";

      package_name_convention => "$(name)";
      package_add_command => "$(paths.path[zypper]) --non-interactive install";
      package_delete_command => "$(paths.path[zypper]) --non-interactive remove --force-resolution";
      package_update_command => "$(paths.path[zypper]) --non-interactive update";
      package_patch_command => "$(paths.path[zypper]) --non-interactive patch$"; # $ means no args
      package_verify_command => "$(paths.path[zypper]) --non-interactive verify$";
}

##

bundle common debian_knowledge
{
  vars:
      "apt_prefix" string => "/usr/bin/env DEBIAN_FRONTEND=noninteractive LC_ALL=C PATH=/bin:/sbin/:/usr/bin:/usr/sbin";
      "call_dpkg" string => "$(apt_prefix) $(paths.path[dpkg])";
      "call_apt_get" string => "$(apt_prefix) $(paths.path[apt_get])";
      "call_aptitude" string => "$(apt_prefix) $(paths.path[aptitude])";
      "dpkg_options" string => "-o Dpkg::Options::=--force-confold -o Dpkg::Options::=--force-confdef";

      "dpkg_compare_equal" string => "$(call_dpkg) --compare-versions $(v1) eq $(v2)";
      "dpkg_compare_less" string => "$(call_dpkg) --compare-versions $(v1) lt $(v2)";
}

body package_method apt
{
      package_changes => "bulk";
      package_list_command => "$(debian_knowledge.call_dpkg) -l";
      package_list_name_regex    => ".i\s+([^\s]+).*";
      package_list_version_regex => ".i\s+[^\s]+\s+([^\s]+).*";
      package_installed_regex => ".i.*"; # packages that have been uninstalled may be listed
      package_name_convention => "$(name)";

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_ifelapsed => "240";

      # make correct version comparisons
      package_version_less_command => "$(debian_knowledge.dpkg_compare_less)";
      package_version_equal_command => "$(debian_knowledge.dpkg_compare_equal)";

    have_aptitude::
      package_add_command => "$(debian_knowledge.call_aptitude) $(debian_knowledge.dpkg_options) --assume-yes install";
      package_list_update_command => "/usr/bin/aptitude update";
      package_delete_command => "$(debian_knowledge.call_aptitude) $(debian_knowledge.dpkg_options) --assume-yes -q remove";
      package_update_command =>  "$(debian_knowledge.call_aptitude) $(debian_knowledge.dpkg_options) --assume-yes install";
      package_patch_command =>  "$(debian_knowledge.call_aptitude) $(debian_knowledge.dpkg_options) --assume-yes install";
      package_verify_command =>  "/usr/bin/aptitude show";
      package_noverify_regex => "(State: not installed|E: Unable to locate package .*)";

      package_patch_list_command => "/usr/bin/aptitude --assume-yes --simulate --verbose full-upgrade";
      package_patch_name_regex => "^Inst\s+(\S+)\s+.*";
      package_patch_version_regex => "^Inst\s+\S+\s+\[?\(?([^\],\s]+).*";

    !have_aptitude::
      package_add_command => "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
      package_list_update_command => "$(debian_knowledge.call_apt_get) update";
      package_delete_command => "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes -q remove";
      package_update_command =>  "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
      package_patch_command =>  "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
      package_verify_command => "$(debian_knowledge.call_dpkg) -s";
      package_noverify_returncode => "1";

      package_patch_list_command => "$(debian_knowledge.call_apt_get) --just-print dist-upgrade";
      package_patch_name_regex => "^Inst\s+(\S+)\s+.*";
      package_patch_version_regex => "^Inst\s+\S+\s+\[?\(?([^\],\s]+).*";

}

# Ignore aptitude because:
#  1) aptitude will remove "unneeded" packages unexpectly
#  2) aptitude return codes are useless
#  3) aptitude is a high level interface
#  4) aptitude provides little benefit
#  5) have_aptitude is a hard class and thus cannot be unset
body package_method apt_get
{
      package_changes => "bulk";
      package_list_command => "$(debian_knowledge.call_dpkg) -l";
      package_list_name_regex    => ".i\s+([^\s]+).*";
      package_list_version_regex => ".i\s+[^\s]+\s+([^\s]+).*";
      package_installed_regex => ".i.*"; # packages that have been uninstalled may be listed
      package_name_convention => "$(name)";

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_ifelapsed => "240";

      # make correct version comparisons
      package_version_less_command => "$(debian_knowledge.dpkg_compare_less)";
      package_version_equal_command => "$(debian_knowledge.dpkg_compare_equal)";

      # Target a specific release, such as backports
      package_add_command => "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
      package_list_update_command => "$(debian_knowledge.call_apt_get) update";
      package_delete_command => "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes -q remove";
      package_update_command =>  "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
      package_patch_command =>  "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
      package_verify_command => "$(debian_knowledge.call_dpkg) -s";
      package_noverify_returncode => "1";

      package_patch_list_command => "$(debian_knowledge.call_apt_get) --just-print dist-upgrade";
      package_patch_name_regex => "^Inst\s+(\S+)\s+.*";
      package_patch_version_regex => "^Inst\s+\S+\s+\[?\(?([^\],\s]+).*";
}

body package_method apt_get_release(release)
{
      package_changes => "bulk";
      package_list_command => "$(debian_knowledge.call_dpkg) -l";
      package_list_name_regex    => ".i\s+([^\s]+).*";
      package_list_version_regex => ".i\s+[^\s]+\s+([^\s]+).*";
      package_installed_regex => ".i.*"; # packages that have been uninstalled may be listed
      package_name_convention => "$(name)";

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_ifelapsed => "240";

      # make correct version comparisons
      package_version_less_command => "$(debian_knowledge.dpkg_compare_less)";
      package_version_equal_command => "$(debian_knowledge.dpkg_compare_equal)";

      # Target a specific release, such as backports
      package_add_command => "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes --target-release $(release) install";
      package_list_update_command => "$(debian_knowledge.call_apt_get) update";
      package_delete_command => "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes -q remove";
      package_update_command =>  "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes --target-release $(release) install";
      package_patch_command =>  "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes --target-release $(release) install";
      package_verify_command => "$(debian_knowledge.call_dpkg) -s";
      package_noverify_returncode => "1";

      package_patch_list_command => "$(debian_knowledge.call_apt_get) --just-print dist-upgrade";
      package_patch_name_regex => "^Inst\s+(\S+)\s+.*";
      package_patch_version_regex => "^Inst\s+\S+\s+\[?\(?([^\],\s]+).*";
}

##

body package_method dpkg_version(repo)
{
      package_changes => "individual";
      package_list_command => "$(debian_knowledge.call_dpkg) -l";

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_command => "$(debian_knowledge.call_apt_get) update";
      package_list_update_ifelapsed => "240";

      package_list_name_regex    => ".i\s+([^\s]+).*";
      package_list_version_regex => ".i\s+[^\s]+\s+([^\s]+).*";

      package_installed_regex => ".i.*"; # packages that have been uninstalled may be listed

      package_file_repositories => { "$(repo)" };

    debian.x86_64::
      package_name_convention => "$(name)_$(version)_amd64.deb";

    debian.i686::
      package_name_convention => "$(name)_$(version)_i386.deb";

    have_aptitude::
      package_patch_list_command => "/usr/bin/aptitude --assume-yes --simulate --verbose full-upgrade";
      package_patch_name_regex => "^Inst\s+(\S+)\s+.*";
      package_patch_version_regex => "^Inst\s+\S+\s+\[?\(?([^\],\s]+).*";
    !have_aptitude::
      package_patch_list_command => "$(debian_knowledge.call_apt_get) --just-print dist-upgrade";
      package_patch_name_regex => "^Inst\s+(\S+)\s+.*";
      package_patch_version_regex => "^Inst\s+\S+\s+\[?\(?([^\],\s]+).*";

    debian::
      package_add_command => "$(debian_knowledge.call_dpkg) --install";
      package_delete_command => "$(debian_knowledge.call_dpkg) --purge";
      package_update_command =>  "$(debian_knowledge.call_dpkg) --install";
      package_patch_command =>  "$(debian_knowledge.call_dpkg) --install";

      # make correct version comparisons
      package_version_less_command => "$(debian_knowledge.dpkg_compare_less)";
      package_version_equal_command => "$(debian_knowledge.dpkg_compare_equal)";
}

##

body package_method rpm_version(repo)
{
      package_changes => "individual";

      package_list_command => "$(paths.path[rpm]) -qa --queryformat \"i | repos | %{name} | %{version}-%{release} | %{arch}\n\"";

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_command => "$(paths.path[yum]) --quiet check-update";
      package_list_update_ifelapsed => "240";

      package_list_name_regex    => "[^|]+\|[^|]+\|\s+([^\s|]+).*";
      package_list_version_regex => "[^|]+\|[^|]+\|[^|]+\|\s+([^\s|]+).*";
      package_list_arch_regex    => "[^|]+\|[^|]+\|[^|]+\|[^|]+\|\s+([^\s]+).*";

      package_installed_regex => "i.*";

      package_file_repositories => { "$(repo)" };

      package_name_convention => "$(name)-$(version).$(arch).rpm";

      package_add_command => "$(paths.path[rpm]) -ivh ";
      package_update_command => "$(paths.path[rpm]) -Uvh ";
      package_patch_command => "$(paths.path[rpm]) -Uvh ";
      package_delete_command => "$(paths.path[rpm]) -e --nodeps";
      package_verify_command => "$(paths.path[rpm]) -V";
      package_noverify_regex => ".*[^\s].*";
}

##

body package_method windows_feature
{
      package_changes => "individual";

      package_name_convention   => "$(name)";
      package_delete_convention => "$(name)";

      package_installed_regex => ".*";
      package_list_name_regex => "(.*)";
      package_list_version_regex => "(.*)";  # FIXME: the listing does not give version, so takes name for version too now

      package_add_command    => "$(sys.winsysdir)\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"Import-Module ServerManager; Add-WindowsFeature -Name\"";
      package_delete_command => "$(sys.winsysdir)\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"Import-Module ServerManager; Remove-WindowsFeature -confirm:$false -Name\"";
      package_list_command   => "$(sys.winsysdir)\\WindowsPowerShell\\v1.0\\powershell.exe -Command \"Import-Module ServerManager; Get-WindowsFeature | where {$_.installed -eq $True} |foreach {$_.Name}\"";
}

##

body package_method msi_implicit(repo)
# Use whole file name as promiser, e.g. "7-Zip-4.50-x86_64.msi",
# the name, version and arch is then deduced from the promiser
{
      package_changes => "individual";
      package_file_repositories => { "$(repo)" };

      package_installed_regex => ".*";

      package_name_convention => "$(name)-$(version)-$(arch).msi";
      package_delete_convention => "$(firstrepo)$(name)-$(version)-$(arch).msi";

      package_name_regex => "^(\S+)-(\d+\.?)+";
      package_version_regex => "^\S+-((\d+\.?)+)";
      package_arch_regex => "^\S+-[\d\.]+-(.*).msi";

      package_add_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i";
      package_update_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i";
      package_delete_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /x";
}

##

body package_method msi_explicit(repo)
# use software name as promiser, e.g. "7-Zip", and explicitly
# specify any package_version and package_arch
{
      package_changes => "individual";
      package_file_repositories => { "$(repo)" };

      package_installed_regex => ".*";

      package_name_convention => "$(name)-$(version)-$(arch).msi";
      package_delete_convention => "$(firstrepo)$(name)-$(version)-$(arch).msi";

      package_add_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i";
      package_update_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /i";
      package_delete_command => "\"$(sys.winsysdir)\msiexec.exe\" /qn /x";
}

##

# This package_method uses yum to install, update and list packages.
#
# It will use "rpm -e" to remove packages. Please note that if several packages
# with the same name but varying versions or architectures are installed,
# "rpm -e" will return an error and not delete any of them.
body package_method yum
{
      package_changes => "bulk";
      package_list_command => "$(paths.path[yum]) --quiet list installed";
      package_patch_list_command => "$(paths.path[yum]) --quiet check-update";

      # Remember to escape special characters like |

      package_list_name_regex    => "([^.]+).*";
      package_list_version_regex => "[^\s]\s+([^\s]+).*";
      package_list_arch_regex    => "[^.]+\.([^\s]+).*";

      package_installed_regex => ".*(installed|\s+@).*";
      package_name_convention => "$(name)-$(version).$(arch)";

      # just give the package name to rpm to delete, otherwise it gets "name.*" (from package_name_convention above)
      package_delete_convention => "$(name)";

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_command => "$(paths.path[yum]) --quiet check-update";
      package_list_update_ifelapsed => "240";

      package_patch_installed_regex => "^\s.*";
      package_patch_name_regex    => "([^.]+).*";
      package_patch_version_regex => "[^\s]\s+([^\s]+).*";
      package_patch_arch_regex    => "[^.]+\.([^\s]+).*";

      package_add_command => "$(paths.path[yum]) -y install";
      package_update_command => "$(paths.path[yum]) -y update";
      package_patch_command => "$(paths.path[yum]) -y update";
      package_delete_command => "$(paths.path[rpm]) -e --nodeps";
      package_verify_command => "$(paths.path[rpm]) -V";
}

##

body package_method yum_rpm

# Contributed by Trond Hasle Amundsen
# More efficient package method for RPM-based systems - uses rpm
# instead of yum to list installed packages
#
# It will use "rpm -e" to remove packages. Please note that if several packages
# with the same name but varying versions or architectures are installed,
# "rpm -e" will return an error and not delete any of them.

{
      package_changes => "bulk";
      package_list_command => "$(paths.path[rpm]) -qa --qf '%{name}.%{arch} %{version}-%{release}\n'";
      package_patch_list_command => "$(paths.path[yum]) --quiet check-update";

      package_list_name_regex    => "([^.]+).*";
      package_list_version_regex => "[^\s]\s+([^\s]+).*";
      package_list_arch_regex    => "[^.]+\.([^\s]+).*";

      package_installed_regex => ".*";
      package_name_convention => "$(name)-$(version).$(arch)";

      # just give the package name to rpm to delete, otherwise it gets "name-*.*" (from package_name_convention above)
      package_delete_convention => "$(name)";

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_command => "$(paths.path[yum]) --quiet check-update";
      package_list_update_ifelapsed => "240";

      package_patch_installed_regex => "^\s.*";
      package_patch_name_regex    => "([^.]+).*";
      package_patch_version_regex => "[^\s]\s+([^\s]+).*";
      package_patch_arch_regex    => "[^.]+\.([^\s]+).*";

      package_add_command    => "$(paths.path[yum]) -y install";
      package_update_command => "$(paths.path[yum]) -y update";
      package_patch_command  => "$(paths.path[yum]) -y update";
      package_delete_command => "$(paths.path[rpm]) -e --nodeps";
      package_verify_command => "$(paths.path[rpm]) -V";
}

##

body package_method yum_rpm_enable_repo(repoid)

# based on yum_rpm with addition to enable a repository for the install
# Sometimes repositories are configured but disabled by default. For example
# this pacakge_method could be used when installing a package that exists in
# the EPEL, which normally you do not want to install packages from.
{
      package_changes => "bulk";
      package_list_command => "$(paths.path[rpm]) -qa --qf '%{name} %{version}-%{release} %{arch}\n'";
      package_patch_list_command => "$(paths.path[yum]) --quiet check-update";

      package_list_name_regex    => "^(\S+?)\s\S+?\s\S+$";
      package_list_version_regex => "^\S+?\s(\S+?)\s\S+$";
      package_list_arch_regex    => "^\S+?\s\S+?\s(\S+)$";

      package_installed_regex => ".*";
      package_name_convention => "$(name)";

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_command => "$(paths.path[yum]) --quiet check-update";
      package_list_update_ifelapsed => "240";

      package_patch_installed_regex => "^\s.*";
      package_patch_name_regex    => "([^.]+).*";
      package_patch_version_regex => "[^\s]\s+([^\s]+).*";
      package_patch_arch_regex    => "[^.]+\.([^\s]+).*";

      package_add_command    => "$(paths.path[yum]) --enablerepo=$(repoid) -y install";
      package_update_command => "$(paths.path[yum]) --enablerepo=$(repoid) -y update";
      package_patch_command => "$(paths.path[yum]) -y update";
      package_delete_command => "$(paths.path[rpm]) -e --nodeps --allmatches";
      package_verify_command => "$(paths.path[rpm]) -V";
}

##

body package_method yum_group

# Makes use of the "groups of packages" feature of Yum possible. (yum groupinstall, groupremove)
#
# Groups must be specified by their groupids, available through yum grouplist -v (between parentheses)
# $ yum grouplist -v|grep Networking|head -n 1
#   Networking Tools (network-tools)       <--- network-tools is the groupid
#
# Policies examples:
#
# -Install "web-server" group:
# ----------------------------
#
# packages:
#   "web-server"
#     package_policy   =>  "add",
#     package_method   =>  yum_group;
#
# -Remove "debugging" and "php" groups:
# -------------------------------------
#
# vars:
#   "groups"  slist  => { "debugging", "php" };
#
# packages:
#   "$(groups)"
#      package_policy   =>   "delete",
#      package_method   =>   yum_group;
#

{
      package_add_command             =>  "$(paths.path[yum]) groupinstall -y";
      package_changes                 =>  "bulk";
      package_delete_command          =>  "$(paths.path[yum]) groupremove -y";
      package_delete_convention       =>  "$(name)";
      package_installed_regex         =>  "^i.*";

      # Generate a dpkg -l like listing, "i" means installed, "a" available, and a dummy version 1
      package_list_command            =>
      "$(paths.path[yum]) grouplist -v|awk '$0 ~ /^Done$/ {next} {sub(/.*\(/, \"\");sub(/\).*/, \"\")} /Available/ {h=\"a\";next} /Installed/ {h=\"i\";next} h==\"i\" || h==\"a\" {print h\" \"$0\" 1\"}'";

      package_list_name_regex         =>  "a|i ([^\s]+) 1";
      package_list_update_command     =>  "$(paths.path[yum]) --quiet check-update";
      package_list_update_ifelapsed   =>  "240";
      package_list_version_regex      =>  "(1)";
      package_name_convention         =>  "$(name)";
      package_name_regex              =>  "(.*)";
      package_noverify_returncode     =>  "0";
      package_update_command          =>  "$(paths.path[yum]) groupupdate";

      # grep -x to only get full line matching
      package_verify_command          => "$(paths.path[yum]) grouplist -v|awk '$0 ~ /^Done$/ {next} {sub(/.*\(/, \"\");sub(/\).*/, \"\")} /Available/ {h=\"a\";next} /Installed/ {h=\"i\";next} h==\"i\"|grep -qx";
}

##

body package_method rpm_filebased(path)

# Contributed by Aleksey Tsalolikhin. Written on 29-Feb-2012.
# Based on yum_rpm body in COPBL by Trond Hasle Amundsen.
# Purpose: install packages from local filesystem-based package repository.
# Note: Specify the path to the local package repository in the argument.

# Example of how to use it:
#
# {{{
# packages:
# "epel-release"
# package_policy => "add",
# package_version => "5-4",
# package_architectures => { "noarch" },
# package_method => rpm_filebased("/repo/RPMs");
# }}}

{
      package_file_repositories => { "$(path)" };
      # the above is an addition to Trond's yum_rpm body

      package_add_command => "$(paths.path[rpm]) -ihv ";
      # The above is a change from Trond's yum_rpm body, this makes the commands rpm only.
      # The reason I changed the install command from yum to rpm is yum will be default
      # refuse to install the epel-release RPM as it does not have the EPEL GPG key,
      # but rpm goes ahead and installs the epel-release RPM and the EPEL GPG key.

      package_name_convention => "$(name)-$(version).$(arch).rpm";
      # The above is a change from Tron's yum_rpm body. When package_file_repositories is in play,
      # package_name_convention has to match the file name, not the package name, per the
      # CFEngine 3 Reference Manual

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_command => "$(paths.path[yum]) --quiet check-update";
      package_list_update_ifelapsed => "240";

      # The rest is unchanged from Trond's yum_rpm body
      package_changes => "bulk";
      package_list_command => "$(paths.path[rpm]) -qa --qf '%{name} %{version}-%{release} %{arch}\n'";

      package_list_name_regex => "^(\S+?)\s\S+?\s\S+$";
      package_list_version_regex => "^\S+?\s(\S+?)\s\S+$";
      package_list_arch_regex => "^\S+?\s\S+?\s(\S+)$";

      package_installed_regex => ".*";

      package_delete_command => "$(paths.path[rpm]) -e --allmatches";
      package_verify_command => "$(paths.path[rpm]) -V";
}

##

# OpenSolaris based systems (Solaris 11, Illumos, etc) use the much better
# Image Package System.
#
# A note about Solaris 11.1 versioning format:
#
# $ pkg list -v --no-refresh zsh
# FMRI                                                                         IFO
# pkg://solaris/shell/zsh@4.3.17,5.11-0.175.1.0.0.24.0:20120904T174236Z        i--
# name--------- |<----->| |/________________________\|
# version---------------- |\                        /|
#
# Notice that the publisher and timestamp aren't used. And that the package
# version then must have the commas replaced by underscores.
#
# Thus,
#     4.3.17,5.11-0.175.1.0.0.24.0
# Becomes:
#     4.3.17_5.11-0.175.1.0.0.24.0
#
# Therefore, a properly formatted package promise looks like this:
#    "shell/zsh"
#      package_policy  => "addupdate",
#      package_method  => ips,
#      package_select  => ">=",
#      package_version => "4.3.17_5.11-0.175.1.0.0.24.0";

body package_method ips
{
      package_changes => "bulk";
      package_list_command => "$(paths.path[pkg]) list -v --no-refresh";
      package_list_name_regex    => "pkg://.+?(?<=/)([^\s]+)@.*$";
      package_list_version_regex => "[^\s]+@([^\s]+):.*";
      package_installed_regex => ".*(i..)"; # all reported are installed

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_command => "$(paths.path[pkg]) refresh --full";
      package_list_update_ifelapsed => "240";

      package_add_command => "$(paths.path[pkg]) install --accept ";
      package_delete_command => "$(paths.path[pkg]) uninstall";
      package_update_command =>  "$(paths.path[pkg]) install --accept";
      package_patch_command =>  "$(paths.path[pkg]) install --accept";
      package_verify_command =>  "$(paths.path[pkg]) list -a -v --no-refresh";
      package_noverify_regex => "(.*---|pkg list: no packages matching .* installed)";
}

##

# SmartOS (solaris 10 fork by Joyent) uses pkgin

body package_method smartos
{
      package_changes => "bulk";
      package_list_command => "/opt/local/bin/pkgin list";
      package_list_name_regex    => "(.*)\-[0-9]+.*";
      package_list_version_regex => ".*\-([0-9][^\s]+).*";

      package_installed_regex => ".*"; # all reported are installed

      package_list_update_command => "/opt/local/bin/pkgin -y update";
      package_list_update_ifelapsed => "240";

      package_add_command => "/opt/local/bin/pkgin -y install";

      package_delete_command => "/opt/local/bin/pkgin -y remove";
      package_update_command =>  "/opt/local/bin/pkgin upgrade";
}

# OpenCSW (Solaris software packages)

body package_method opencsw
{
      package_changes => "bulk";
      package_list_command => "/opt/csw/bin/pkgutil -c";
      package_list_name_regex    => "CSW(.*?)\s.*";
      package_list_version_regex => ".*?\s+(.*),.*";

      package_installed_regex => ".*"; # all reported are installed

      package_list_update_command => "/opt/csw/bin/pkgutil -U";
      package_list_update_ifelapsed => "240";

      package_add_command => "/opt/csw/bin/pkgutil -yi";

      package_delete_command => "/opt/csw/bin/pkgutil -yr";
      package_update_command =>  "/opt/csw/bin/pkgutil -yu";
}

# The older solaris package system is poorly designed, with too many different
# names to track. See the example in tests/units/unit_package_solaris.cf
# to see how to use this

body package_method solaris (pkgname, spoolfile, adminfile)
{
      package_changes => "individual";
      package_list_command => "$(paths.path[pkginfo]) -l";
      package_multiline_start    =>  "\s*PKGINST:\s+[^\s]+.*";
      package_list_name_regex    => "\s*PKGINST:\s+([^\s]+).*";
      package_list_version_regex => "\s*VERSION:\s+([^\s]+).*";
      package_list_arch_regex    => "\s*ARCH:\s+([^\s]+)";
      package_installed_regex => "\s*STATUS:\s*(completely|partially)\s+installed.*";
      package_name_convention => "$(name)";
      package_add_command => "$(paths.path[pkgadd]) -n -a /tmp/$(adminfile) -d /tmp/$(spoolfile)";
      package_delete_command => "$(paths.path[pkgrm]) -n -a /tmp/$(adminfile)";
}

##

#
# The following bundle is part of a package setup for solaris, see unit examples
#

bundle edit_line create_solaris_admin_file
{
  insert_lines:

      "mail=
instance=unique
partial=nocheck
runlevel=nocheck
idepend=nocheck
rdepend=nocheck
space=nocheck
setuid=nocheck
conflict=nocheck
action=nocheck
networktimeout=60
networkretries=3
authentication=quit
keystore=/var/sadm/security
proxy=
basedir=default"
      comment => "Insert contents of Solaris admin file (automatically install packages)";
}

##

body package_method freebsd
{
      package_changes => "individual";

      # Could use rpm for this
      package_list_command => "/usr/sbin/pkg_info";

      # Remember to escape special characters like |

      package_list_name_regex    => "([^\s]+)-.*";
      package_list_version_regex => "[^\s]+-([^\s]+).*";

      package_name_regex    => "([^\s]+)-.*";
      package_version_regex => "[^\s]+-([^\s]+).*";

      package_installed_regex => ".*";

      package_name_convention => "$(name)-$(version)";

      package_add_command => "/usr/sbin/pkg_add -r";
      package_delete_command => "/usr/sbin/pkg_delete";
}

body package_method freebsd_portmaster
{
      package_changes => "individual";

      package_list_command => "/usr/sbin/pkg_info";

      package_list_name_regex    => "([^\s]+)-.*";
      package_list_version_regex => "[^\s]+-([^\s]+).*";

      package_installed_regex => ".*";

      package_name_convention => "$(name)";
      package_delete_convention => "$(name)-$(version)";

      package_file_repositories => {
				     "/usr/ports/accessibility/",
				     "/usr/port/arabic/",
				     "/usr/ports/archivers/",
				     "/usr/ports/astro/",
				     "/usr/ports/audio/",
				     "/usr/ports/benchmarks/",
				     "/usr/ports/biology/",
				     "/usr/ports/cad/",
				     "/usr/ports/chinese/",
				     "/usr/ports/comms/",
				     "/usr/ports/converters/",
				     "/usr/ports/databases/",
				     "/usr/ports/deskutils/",
				     "/usr/ports/devel/",
				     "/usr/ports/dns/",
				     "/usr/ports/editors/",
				     "/usr/ports/emulators/",
				     "/usr/ports/finance/",
				     "/usr/ports/french/",
				     "/usr/ports/ftp/",
				     "/usr/ports/games/",
				     "/usr/ports/german/",
				     "/usr/ports/graphics/",
				     "/usr/ports/hebrew/",
				     "/usr/ports/hungarian/",
				     "/usr/ports/irc/",
				     "/usr/ports/japanese/",
				     "/usr/ports/java/",
				     "/usr/ports/korean/",
				     "/usr/ports/lang/",
				     "/usr/ports/mail/",
				     "/usr/ports/math/",
				     "/usr/ports/mbone/",
				     "/usr/ports/misc/",
				     "/usr/ports/multimedia/",
				     "/usr/ports/net/",
				     "/usr/ports/net-im/",
				     "/usr/ports/net-mgmt/",
				     "/usr/ports/net-p2p/",
				     "/usr/ports/news/",
				     "/usr/ports/packages/",
				     "/usr/ports/palm/",
				     "/usr/ports/polish/",
				     "/usr/ports/ports-mgmt/",
				     "/usr/ports/portuguese/",
				     "/usr/ports/print/",
				     "/usr/ports/russian/",
				     "/usr/ports/science/",
				     "/usr/ports/security/",
				     "/usr/ports/shells/",
				     "/usr/ports/sysutils/",
				     "/usr/ports/textproc/",
				     "/usr/ports/ukrainian/",
				     "/usr/ports/vietnamese/",
				     "/usr/ports/www/",
				     "/usr/ports/x11/",
				     "/usr/ports/x11-clocks/",
				     "/usr/ports/x11-drivers/",
				     "/usr/ports/x11-fm/",
				     "/usr/ports/x11-fonts/",
				     "/usr/ports/x11-servers/",
				     "/usr/ports/x11-themes/",
				     "/usr/ports/x11-toolkits/",
				     "/usr/ports/x11-wm/",
      };

      package_add_command => "/usr/local/sbin/portmaster -D -G --no-confirm";
      package_update_command => "/usr/local/sbin/portmaster -D -G --no-confirm";
      package_delete_command => "/usr/local/sbin/portmaster --no-confirm -e";
}

##

body package_method alpinelinux
{
      package_changes => "bulk";
      package_list_command => "/sbin/apk info -v";
      package_list_name_regex    => "([^\s]+)-.*";
      package_list_version_regex => "[^\s]+-([^\s]+).*";
      package_name_regex    => ".*";
      package_installed_regex => ".*";
      package_name_convention => "$(name)";
      package_add_command => "/sbin/apk add";
      package_delete_command => "/sbin/apk del";
}

##

body package_method emerge
{
      package_changes => "individual";
      package_list_command => "/bin/sh -c '/bin/ls -d /var/db/pkg/*/* | cut -c 13-'";
      package_list_name_regex => ".*/([^\s]+)-\d.*";
      package_list_version_regex => ".*/[^\s]+-(\d.*)";
      package_installed_regex => ".*";                          # all reported are installed
      package_name_convention => "$(name)";
      package_list_update_command => "/bin/true";               # I prefer manual syncing
      #package_list_update_command => "/usr/bin/emerge --sync"; # if you like automatic
      package_list_update_ifelapsed => "240";                   # should happen every 4 hours

      package_add_command => "/usr/bin/emerge -q --quiet-build";
      package_delete_command => "/usr/bin/emerge --depclean";
      package_update_command => "/usr/bin/emerge --update";
      package_patch_command => "/usr/bin/emerge --update";
      package_verify_command => "/usr/bin/emerge -s";
      package_noverify_regex => ".*(Not Installed|Applications found : 0).*";
}

##

body package_method pacman

{
      package_changes => "bulk";

      package_list_command => "/usr/bin/pacman -Q";
      package_verify_command  => "/usr/bin/pacman -Q";
      package_noverify_regex  => "error:\b.*\bwas not found";

      # set it to "0" to avoid caching of list during upgrade
      package_list_update_ifelapsed => "240";

      package_list_name_regex    => "(.*)\s+.*";
      package_list_version_regex => ".*\s+(.*)";
      package_installed_regex => ".*";

      package_name_convention => "$(name)";
      package_add_command => "/usr/bin/pacman -S --noconfirm --noprogressbar --needed";
      package_delete_command => "/usr/bin/pacman -Rs --noconfirm";
      package_update_command => "/usr/bin/pacman -S --noconfirm --noprogressbar --needed";
}

##

# Single bundle for all the similar managers simplifies promises

body package_method generic
{
    SuSE::
      package_changes => "bulk";
      package_list_command => "$(paths.path[rpm]) -qa --queryformat \"i | repos | %{name} | %{version}-%{release} | %{arch}\n\"";
      # set it to "0" to avoid caching of list during upgrade
      package_list_update_command => "$(paths.path[zypper]) list-updates";
      package_list_update_ifelapsed => "0";
      package_patch_list_command => "$(paths.path[zypper]) patches";
      package_installed_regex => "i.*";
      package_list_name_regex    => "[^|]+\|[^|]+\|\s+([^\s]+).*";
      package_list_version_regex => "[^|]+\|[^|]+\|[^|]+\|\s+([^\s]+).*";
      package_list_arch_regex    => "[^|]+\|[^|]+\|[^|]+\|[^|]+\|\s+([^\s]+).*";
      package_patch_installed_regex => ".*Installed.*|.*Not Applicable.*";
      package_patch_name_regex    => "[^|]+\|\s+([^\s]+).*";
      package_patch_version_regex => "[^|]+\|[^|]+\|\s+([^\s]+).*";
      package_name_convention => "$(name)";
      package_add_command => "$(paths.path[zypper]) --non-interactive install";
      package_delete_command => "$(paths.path[zypper]) --non-interactive remove --force-resolution";
      package_update_command => "$(paths.path[zypper]) --non-interactive update";
      package_patch_command => "$(paths.path[zypper]) --non-interactive patch$"; # $ means no args
      package_verify_command => "$(paths.path[zypper]) --non-interactive verify$";

    redhat::
      package_changes => "bulk";
      package_list_command => "$(paths.path[rpm]) -qa --qf '%{name} %{version}-%{release} %{arch}\n'";
      package_patch_list_command => "$(paths.path[yum]) --quiet check-update";
      package_list_name_regex    => "^(\S+?)\s\S+?\s\S+$";
      package_list_version_regex => "^\S+?\s(\S+?)\s\S+$";
      package_list_arch_regex    => "^\S+?\s\S+?\s(\S+)$";
      package_installed_regex => ".*";
      package_name_convention => "$(name)";
      package_list_update_command => "$(paths.path[yum]) --quiet check-update";
      package_list_update_ifelapsed => "0";     # sometimes, caching is pretty disturbing
      package_patch_installed_regex => "^\s.*";
      package_patch_name_regex    => "([^.]+).*";
      package_patch_version_regex => "[^\s]\s+([^\s]+).*";
      package_patch_arch_regex    => "[^.]+\.([^\s]+).*";
      package_add_command    => "$(paths.path[yum]) -y install";
      package_update_command => "$(paths.path[yum]) -y update";
      package_patch_command => "$(paths.path[yum]) -y update";
      package_delete_command => "$(paths.path[rpm]) -e --nodeps --allmatches";
      package_verify_command => "$(paths.path[rpm]) -V";

      # package_changes => "bulk";
      # package_list_command => "$(paths.path[yum]) list installed";
      # package_patch_list_command => "$(paths.path[yum]) check-update";
      # package_list_name_regex    => "([^.]+).*";
      # package_list_version_regex => "[^\s]\s+([^\s]+).*";
      # package_list_arch_regex    => "[^.]+\.([^\s]+).*";
      # package_installed_regex => ".*(installed|\s+@).*";
      # package_name_convention => "$(name).$(arch)";
      # package_list_update_ifelapsed => "240";
      # package_patch_installed_regex => "^\s.*";
      # package_patch_name_regex    => "([^.]+).*";
      # package_patch_version_regex => "[^\s]\s+([^\s]+).*";
      # package_patch_arch_regex    => "[^.]+\.([^\s]+).*";
      # package_add_command => "$(paths.path[yum]) -y install";
      # package_delete_command => "$(paths.path[rpm]) -e --nodeps";
      # package_verify_command => "$(paths.path[rpm]) -V";

    debian::
      package_changes => "bulk";
      package_list_command => "$(debian_knowledge.call_dpkg) -l";
      package_list_name_regex    => ".i\s+([^\s]+).*";
      package_list_version_regex => ".i\s+[^\s]+\s+([^\s]+).*";
      package_installed_regex => ".i.*"; # packages that have been uninstalled may be listed
      package_name_convention => "$(name)";
      package_list_update_ifelapsed => "240";		# 4 hours

      # make correct version comparisons
      package_version_less_command => "$(debian_knowledge.dpkg_compare_less)";
      package_version_equal_command => "$(debian_knowledge.dpkg_compare_equal)";

    debian.have_aptitude::
      package_add_command => "$(debian_knowledge.call_aptitude) $(debian_knowledge.dpkg_options) --assume-yes install";
      package_list_update_command => "/usr/bin/aptitude update";
      package_delete_command => "$(debian_knowledge.call_aptitude) $(debian_knowledge.dpkg_options) --assume-yes remove";
      package_update_command =>  "$(debian_knowledge.call_aptitude) $(debian_knowledge.dpkg_options) --assume-yes install";
      package_patch_command =>  "$(debian_knowledge.call_aptitude) $(debian_knowledge.dpkg_options) --assume-yes install";
      package_verify_command =>  "/usr/bin/aptitude show";
      package_noverify_regex => "(State: not installed|E: Unable to locate package .*)";

      package_patch_list_command => "/usr/bin/aptitude --assume-yes --simulate --verbose full-upgrade";
      package_patch_name_regex => "^Inst\s+(\S+)\s+.*";
      package_patch_version_regex => "^Inst\s+\S+\s+\[?\(?([^\],\s]+).*";

    debian.!have_aptitude::
      package_add_command => "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
      package_list_update_command => "$(debian_knowledge.call_apt_get) update";
      package_delete_command => "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes remove";
      package_update_command =>  "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
      package_patch_command =>  "$(debian_knowledge.call_apt_get) $(debian_knowledge.dpkg_options) --yes install";
      package_verify_command => "$(debian_knowledge.call_dpkg) -s";
      package_noverify_returncode => "1";

      package_patch_list_command => "$(debian_knowledge.call_apt_get) --just-print dist-upgrade";
      package_patch_name_regex => "^Inst\s+(\S+)\s+.*";
      package_patch_version_regex => "^Inst\s+\S+\s+\[?\(?([^\],\s]+).*";

    freebsd::
      package_changes => "individual";
      package_list_command => "/usr/sbin/pkg_info";
      package_list_name_regex    => "([^\s]+)-.*";
      package_list_version_regex => "[^\s]+-([^\s]+).*";
      package_name_regex    => "([^\s]+)-.*";
      package_version_regex => "[^\s]+-([^\s]+).*";
      package_installed_regex => ".*";
      package_name_convention => "$(name)-$(version)";
      package_add_command => "/usr/sbin/pkg_add -r";
      package_delete_command => "/usr/sbin/pkg_delete";

    alpinelinux::
      package_changes => "bulk";
      package_list_command => "/sbin/apk info -v";
      package_list_name_regex    => "([^\s]+)-.*";
      package_list_version_regex => "[^\s]+-([^\s]+).*";
      package_name_regex    => ".*";
      package_installed_regex => ".*";
      package_name_convention => "$(name)";
      package_add_command => "/sbin/apk add";
      package_delete_command => "/sbin/apk del";

    gentoo::
      package_changes => "individual";
      package_list_command => "/bin/sh -c '/bin/ls -d /var/db/pkg/*/* | cut -c 13-'";
      package_list_name_regex => ".*/([^\s]+)-\d.*";
      package_list_version_regex => ".*/[^\s]+-(\d.*)";
      package_installed_regex => ".*";                          # all reported are installed
      package_name_convention => "$(name)";
      package_list_update_command => "/bin/true";               # I prefer manual syncing
      #package_list_update_command => "/usr/bin/emerge --sync"; # if you like automatic
      package_list_update_ifelapsed => "240";                   # should happen every 4 hours

      package_add_command => "/usr/bin/emerge -q --quiet-build";
      package_delete_command => "/usr/bin/emerge --depclean";
      package_update_command => "/usr/bin/emerge --update";
      package_patch_command => "/usr/bin/emerge --update";
      package_verify_command => "/usr/bin/emerge -s";
      package_noverify_regex => ".*(Not Installed|Applications found : 0).*";

    archlinux::
      package_changes => "bulk";
      package_list_command => "/usr/bin/pacman -Q";
      package_verify_command  => "/usr/bin/pacman -Q";
      package_noverify_regex  => "error:\b.*\bwas not found";
      package_list_name_regex    => "(.*)\s+.*";
      package_list_version_regex => ".*\s+(.*)";
      package_installed_regex => ".*";
      package_name_convention => "$(name)";
      package_list_update_ifelapsed => "240";
      package_add_command => "/usr/bin/pacman -S --noconfirm --noprogressbar --needed";
      package_delete_command => "/usr/bin/pacman -Rs --noconfirm";
      package_update_command => "/usr/bin/pacman -S --noconfirm --noprogressbar --needed";
}

##

##-------------------------------------------------------
## storage promises
##-------------------------------------------------------

body volume min_free_space(free)
{
      check_foreign  => "false";
      freespace      => "$(free)";
      sensible_size  => "10000";
      sensible_count => "2";
}

##

body mount nfs(server,source)
{
      mount_type => "nfs";
      mount_source => "$(source)";
      mount_server => "$(server)";
      edit_fstab => "true";
}

##

body mount nfs_p(server,source,perm)
{
      mount_type => "nfs";
      mount_source => "$(source)";
      mount_server => "$(server)";
      mount_options => {"$(perm)"};
      edit_fstab => "true";
}

##

body mount unmount
{
      mount_type => "nfs";
      edit_fstab => "true";
      unmount => "true";
}

##-------------------------------------------------------
## process promises
##-------------------------------------------------------

body process_select exclude_procs(x)
{
      command => "$(x)";
      process_result => "!command";
}

##

body process_select days_older_than(d)
{
      stime_range    => irange(ago(0,0,"$(d)",0,0,0),now);
      process_result => "stime";
}

##

body process_count any_count(cl)

{
      match_range => "0,0";
      out_of_range_define => { "$(cl)" };
}

##

body process_count check_range(name,lower,upper)
{
      match_range => irange("$(lower)","$(upper)");
      out_of_range_define => { "$(name)_out_of_range" };
}

##-------------------------------------------------------
## service promises
##-------------------------------------------------------

body service_method bootstart
{
      service_autostart_policy => "boot_time";
      service_dependence_chain => "start_parent_services";
    windows::
      service_type => "windows";
}

##

body service_method force_deps
{
      service_dependence_chain => "all_related";
    windows::
      service_type => "windows";
}

##

bundle agent standard_services(service,state)
{
      # DATA,

  vars:

    any::

      "stakeholders[cfengine3]" slist => { "cfengine_in" };
      "stakeholders[acpid]" slist => { "cpu", "cpu0", "cpu1", "cpu2", "cpu3" };
      "stakeholders[mongod]" slist => { "mongo_in" };
      "stakeholders[postfix]" slist => { "smtp_in" };
      "stakeholders[sendmail]" slist => { "smtp_in" };
      "stakeholders[www]" slist => { "www_in", "wwws_in", "www_alt_in" };
      "stakeholders[ssh]" slist => { "ssh_in" };
      "stakeholders[mysql]" slist => { "mysql_in" };
      "stakeholders[nfs]" slist => { "nfsd_in" };
      "stakeholders[syslog]" slist => { "syslog" };
      "stakeholders[rsyslog]" slist => { "syslog" };
      "stakeholders[tomcat5]" slist => { "www_alt_in" };
      "stakeholders[tomcat6]" slist => { "www_alt_in" };

    linux::

      "startcommand[acpid]"   string => "/etc/init.d/acpid start";
      "restartcommand[acpid]" string => "/etc/init.d/acpid restart";
      "reloadcommand[acpid]"  string => "/etc/init.d/acpid reload";
      "stopcommand[acpid]"    string => "/etc/init.d/acpid stop";
      "pattern[acpid]"        string => ".*acpid.*";

      "startcommand[cfengine3]"   string => "/etc/init.d/cfengine3 start";
      "restartcommand[cfengine3]" string => "/etc/init.d/cfengine3 restart";
      "reloadcommand[cfengine3]"  string => "/etc/init.d/cfengine3 reload";
      "stopcommand[cfengine3]"    string => "/etc/init.d/cfengine3 stop";
      "pattern[cfengine3]"        string => ".*cf-execd.*";

      "startcommand[fancontrol]"   string => "/etc/init.d/fancontrol start";
      "restartcommand[fancontrol]" string => "/etc/init.d/fancontrol restart";
      "reloadcommand[fancontrol]"  string => "/etc/init.d/fancontrol reload";
      "stopcommand[fancontrol]"    string => "/etc/init.d/fancontrol stop";
      "pattern[fancontrol]"        string => ".*fancontrol.*";

      "startcommand[hddtemp]"   string => "/etc/init.d/hddtemp start";
      "restartcommand[hddtemp]" string => "/etc/init.d/hddtemp restart";
      "reloadcommand[hddtemp]"  string => "/etc/init.d/hddtemp reload";
      "stopcommand[hddtemp]"    string => "/etc/init.d/hddtemp stop";
      "pattern[hddtemp]"        string => ".*hddtemp.*";

      "startcommand[irqbalance]"   string => "/etc/init.d/irqbalance start";
      "restartcommand[irqbalance]" string => "/etc/init.d/irqbalance restart";
      "reloadcommand[irqbalance]"  string => "/etc/init.d/irqbalance reload";
      "stopcommand[irqbalance]"    string => "/etc/init.d/irqbalance stop";
      "pattern[irqbalance]"        string => ".*irqbalance.*";

      "startcommand[lm-sensor]"   string => "/etc/init.d/lm-sensor start";
      "restartcommand[lm-sensor]" string => "/etc/init.d/lm-sensor restart";
      "reloadcommand[lm-sensor]"  string => "/etc/init.d/lm-sensor reload";
      "stopcommand[lm-sensor]"    string => "/etc/init.d/lm-sensor stop";
      "pattern[lm-sensor]"        string => ".*psensor.*";

      "startcommand[mongod]"   string => "/etc/init.d/mongod start";
      "restartcommand[mongod]" string => "/etc/init.d/mongod restart";
      "reloadcommand[mongod]"  string => "/etc/init.d/mongod reload";
      "stopcommand[mongod]"    string => "/etc/init.d/mongod stop";
      "pattern[mongod]"        string => ".*mongod.*";

      "startcommand[openvpn]"   string => "/etc/init.d/openvpn start";
      "restartcommand[openvpn]" string => "/etc/init.d/openvpn restart";
      "reloadcommand[openvpn]"  string => "/etc/init.d/openvpn reload";
      "stopcommand[openvpn]"    string => "/etc/init.d/openvpn stop";
      "pattern[openvpn]"        string => ".*openvpn.*";

      "startcommand[postfix]"   string => "/etc/init.d/postfix start";
      "restartcommand[postfix]" string => "/etc/init.d/postfix restart";
      "reloadcommand[postfix]"  string => "/etc/init.d/postfix reload";
      "stopcommand[postfix]"    string => "/etc/init.d/postfix stop";
      "pattern[postfix]"        string => ".*postfix.*";

      "startcommand[rsync]"   string => "/etc/init.d/rsync start";
      "restartcommand[rsync]" string => "/etc/init.d/rsync restart";
      "reloadcommand[rsync]"  string => "/etc/init.d/rsync reload";
      "stopcommand[rsync]"    string => "/etc/init.d/rsync stop";
      "pattern[rsync]"        string => ".*rsync.*";

      "startcommand[rsyslog]"   string => "/etc/init.d/rsyslog start";
      "restartcommand[rsyslog]" string => "/etc/init.d/rsyslog restart";
      "reloadcommand[rsyslog]"  string => "/etc/init.d/rsyslog reload";
      "stopcommand[rsyslog]"    string => "/etc/init.d/rsyslog stop";
      "pattern[rsyslog]"        string => ".*rsyslogd.*";

      "startcommand[sendmail]"   string => "/etc/init.d/sendmail start";
      "restartcommand[sendmail]" string => "/etc/init.d/sendmail restart";
      "reloadcommand[sendmail]"  string => "/etc/init.d/sendmail reload";
      "stopcommand[sendmail]"    string => "/etc/init.d/sendmail stop";
      "pattern[sendmail]"        string => ".*sendmail.*";

      "startcommand[tomcat5]"   string => "/etc/init.d/tomcat5 start";
      "restartcommand[tomcat5]" string => "/etc/init.d/tomcat5 restart";
      "reloadcommand[tomcat5]"  string => "/etc/init.d/tomcat5 reload";
      "stopcommand[tomcat5]"    string => "/etc/init.d/tomcat5 stop";
      "pattern[tomcat5]"        string => ".*tomcat5.*";

      "startcommand[tomcat6]"   string => "/etc/init.d/tomcat6 start";
      "restartcommand[tomcat6]" string => "/etc/init.d/tomcat6 restart";
      "reloadcommand[tomcat6]"  string => "/etc/init.d/tomcat6 reload";
      "stopcommand[tomcat6]"    string => "/etc/init.d/tomcat6 stop";
      "pattern[tomcat6]"        string => ".*tomcat6.*";

      "startcommand[varnish]"   string => "/etc/init.d/varnish start";
      "restartcommand[varnish]" string => "/etc/init.d/varnish restart";
      "reloadcommand[varnish]"  string => "/etc/init.d/varnish reload";
      "stopcommand[varnish]"    string => "/etc/init.d/varnish stop";
      "pattern[varnish]"        string => ".*varnish.*";

      "startcommand[wpa_supplicant]"   string => "/etc/init.d/wpa_supplicant start";
      "restartcommand[wpa_supplicant]" string => "/etc/init.d/wpa_supplicant restart";
      "reloadcommand[wpa_supplicant]"  string => "/etc/init.d/wpa_supplicant reload";
      "stopcommand[wpa_supplicant]"    string => "/etc/init.d/wpa_supplicant stop";
      "pattern[wpa_supplicant]"        string => ".*wpa_supplicant.*";

    SuSE|suse::

      "startcommand[mysql]"   string => "/etc/init.d/mysqld start";
      "restartcommand[mysql]" string => "/etc/init.d/mysqld restart";
      "reloadcommand[mysql]"  string => "/etc/init.d/mysqld reload";
      "stopcommand[mysql]"    string => "/etc/init.d/mysqld stop";
      "pattern[mysql]"        string => ".*mysqld.*";

      "startcommand[www]"   string => "/etc/init.d/apache2 start";
      "restartcommand[www]" string => "/etc/init.d/apache2 restart";
      "reloadcommand[www]"  string => "/etc/init.d/apache2 reload";
      "stopcommand[www]"    string => "/etc/init.d/apache2 stop";
      "pattern[www]"        string => ".*apache2.*";

      "startcommand[ntpd]"   string => "/etc/init.d/ntpd start";
      "restartcommand[ntpd]" string => "/etc/init.d/ntpd restart";
      "reloadcommand[ntpd]"  string => "/etc/init.d/ntpd reload";
      "stopcommand[ntpd]"    string => "/etc/init.d/ntpd stop";
      "pattern[ntpd]"        string => ".*ntpd.*";

      "startcommand[ssh]"   string => "/etc/init.d/sshd start";
      "restartcommand[ssh]" string => "/etc/init.d/sshd restart";
      "reloadcommand[ssh]"  string => "/etc/init.d/sshd reload";
      "stopcommand[ssh]"    string => "/etc/init.d/sshd stop";
      "pattern[ssh]"        string => ".*sshd.*";

    redhat::

      "startcommand[anacron]"   string => "/etc/init.d/anacron start";
      "restartcommand[anacron]" string => "/etc/init.d/anacron restart";
      "reloadcommand[anacron]"  string => "/etc/init.d/anacron reload";
      "stopcommand[anacron]"    string => "/etc/init.d/anacron stop";
      "pattern[anacron]"        string => ".*anacron.*";

      "startcommand[atd]"   string => "/etc/init.d/atd start";
      "restartcommand[atd]" string => "/etc/init.d/atd restart";
      "reloadcommand[atd]"  string => "/etc/init.d/atd reload";
      "stopcommand[atd]"    string => "/etc/init.d/atd stop";
      "pattern[atd]"        string => ".*sbin/atd.*";

      "startcommand[auditd]"   string => "/etc/init.d/auditd start";
      "restartcommand[auditd]" string => "/etc/init.d/auditd restart";
      "reloadcommand[auditd]"  string => "/etc/init.d/auditd reload";
      "stopcommand[auditd]"    string => "/etc/init.d/auditd stop";
      "pattern[auditd]"        string => ".*auditd$";

      "startcommand[autofs]"   string => "/etc/init.d/autofs start";
      "restartcommand[autofs]" string => "/etc/init.d/autofs restart";
      "reloadcommand[autofs]"  string => "/etc/init.d/autofs reload";
      "stopcommand[autofs]"    string => "/etc/init.d/autofs stop";
      "pattern[autofs]"        string => ".*automount.*";

      "startcommand[bluetoothd]"   string => "/etc/init.d/bluetooth start";
      "restartcommand[bluetoothd]" string => "/etc/init.d/bluetooth restart";
      "reloadcommand[bluetoothd]"  string => "/etc/init.d/bluetooth reload";
      "stopcommand[bluetoothd]"    string => "/etc/init.d/bluetooth stop";
      "pattern[bluetoothd]"        string => ".*hcid.*";

      "startcommand[capi]"   string => "/etc/init.d/capi start";
      "restartcommand[capi]" string => "/etc/init.d/capi restart";
      "reloadcommand[capi]"  string => "/etc/init.d/capi reload";
      "stopcommand[capi]"    string => "/etc/init.d/capi stop";
      "pattern[capi]"        string => ".*capiinit.*";

      "startcommand[conman]"   string => "/etc/init.d/conman start";
      "restartcommand[conman]" string => "/etc/init.d/conman restart";
      "reloadcommand[conman]"  string => "/etc/init.d/conman reload";
      "stopcommand[conman]"    string => "/etc/init.d/conman stop";
      "pattern[conman]"        string => ".*conmand.*";

      "startcommand[cpuspeed]"   string => "/etc/init.d/cpuspeed start";
      "restartcommand[cpuspeed]" string => "/etc/init.d/cpuspeed restart";
      "reloadcommand[cpuspeed]"  string => "/etc/init.d/cpuspeed reload";
      "stopcommand[cpuspeed]"    string => "/etc/init.d/cpuspeed stop";
      "pattern[cpuspeed]"        string => ".*cpuspeed.*";

      "startcommand[crond]"   string => "/etc/init.d/crond start";
      "restartcommand[crond]" string => "/etc/init.d/crond restart";
      "reloadcommand[crond]"  string => "/etc/init.d/crond reload";
      "stopcommand[crond]"    string => "/etc/init.d/crond stop";
      "pattern[crond]"        string => ".*crond.*";

      "startcommand[dc_client]"   string => "/etc/init.d/dc_client start";
      "restartcommand[dc_client]" string => "/etc/init.d/dc_client restart";
      "reloadcommand[dc_client]"  string => "/etc/init.d/dc_client reload";
      "stopcommand[dc_client]"    string => "/etc/init.d/dc_client stop";
      "pattern[dc_client]"        string => ".*dc_client.*";

      "startcommand[dc_server]"   string => "/etc/init.d/dc_server start";
      "restartcommand[dc_server]" string => "/etc/init.d/dc_server restart";
      "reloadcommand[dc_server]"  string => "/etc/init.d/dc_server reload";
      "stopcommand[dc_server]"    string => "/etc/init.d/dc_server stop";
      "pattern[dc_server]"        string => ".*dc_server.*";

      "startcommand[dnsmasq]"   string => "/etc/init.d/dnsmasq start";
      "restartcommand[dnsmasq]" string => "/etc/init.d/dnsmasq restart";
      "reloadcommand[dnsmasq]"  string => "/etc/init.d/dnsmasq reload";
      "stopcommand[dnsmasq]"    string => "/etc/init.d/dnsmasq stop";
      "pattern[dnsmasq]"        string => ".*dnsmasq.*";

      "startcommand[dund]"   string => "/etc/init.d/dund start";
      "restartcommand[dund]" string => "/etc/init.d/dund restart";
      "reloadcommand[dund]"  string => "/etc/init.d/dund reload";
      "stopcommand[dund]"    string => "/etc/init.d/dund stop";
      "pattern[dund]"        string => ".*dund.*";

      "startcommand[gpm]"   string => "/etc/init.d/gpm start";
      "restartcommand[gpm]" string => "/etc/init.d/gpm restart";
      "reloadcommand[gpm]"  string => "/etc/init.d/gpm reload";
      "stopcommand[gpm]"    string => "/etc/init.d/gpm stop";
      "pattern[gpm]"        string => ".*gpm.*";

      "startcommand[haldaemon]"   string => "/etc/init.d/haldaemon start";
      "restartcommand[haldaemon]" string => "/etc/init.d/haldaemon restart";
      "reloadcommand[haldaemon]"  string => "/etc/init.d/haldaemon reload";
      "stopcommand[haldaemon]"    string => "/etc/init.d/haldaemon stop";
      "pattern[haldaemon]"        string => ".*hald.*";

      "startcommand[hidd]"   string => "/etc/init.d/hidd start";
      "restartcommand[hidd]" string => "/etc/init.d/hidd restart";
      "reloadcommand[hidd]"  string => "/etc/init.d/hidd reload";
      "stopcommand[hidd]"    string => "/etc/init.d/hidd stop";
      "pattern[hidd]"        string => ".*hidd.*";

      #  "startcommand[ip6tables]"   string => "/etc/init.d/ip6tables start";
      #  "restartcommand[ip6tables]" string => "/etc/init.d/ip6tables restart";
      #  "reloadcommand[ip6tables]"  string => "/etc/init.d/ip6tables reload";
      #  "stopcommand[ip6tables]"    string => "/etc/init.d/ip6tables stop";
      #  "pattern[ip6tables]"        string => ".*ip6tables.*";

      #  "startcommand[iptables]"   string => "/etc/init.d/iptables start";
      #  "restartcommand[iptables]" string => "/etc/init.d/iptables restart";
      #  "reloadcommand[iptables]"  string => "/etc/init.d/iptables reload";
      #  "stopcommand[iptables]"    string => "/etc/init.d/iptables stop";
      #  "pattern[iptables]"        string => ".*iptables.*";

      "startcommand[irda]"   string => "/etc/init.d/irda start";
      "restartcommand[irda]" string => "/etc/init.d/irda restart";
      "reloadcommand[irda]"  string => "/etc/init.d/irda reload";
      "stopcommand[irda]"    string => "/etc/init.d/irda stop";
      "pattern[irda]"        string => ".*irattach.*";

      "startcommand[iscsid]"   string => "/etc/init.d/iscsid start";
      "restartcommand[iscsid]" string => "/etc/init.d/iscsid restart";
      "reloadcommand[iscsid]"  string => "/etc/init.d/iscsid reload";
      "stopcommand[iscsid]"    string => "/etc/init.d/iscsid stop";
      "pattern[iscsid]"        string => ".*iscsid.*";

      "startcommand[isdn]"   string => "/etc/init.d/isdn start";
      "restartcommand[isdn]" string => "/etc/init.d/isdn restart";
      "reloadcommand[isdn]"  string => "/etc/init.d/isdn reload";
      "stopcommand[isdn]"    string => "/etc/init.d/isdn stop";
      "pattern[isdn]"        string => ".*isdnlog.*";

      "startcommand[lvm2-monitor]"   string => "/etc/init.d/lvm2-monitor start";
      "restartcommand[lvm2-monitor]" string => "/etc/init.d/lvm2-monitor restart";
      "reloadcommand[lvm2-monitor]"  string => "/etc/init.d/lvm2-monitor reload";
      "stopcommand[lvm2-monitor]"    string => "/etc/init.d/lvm2-monitor stop";
      "pattern[lvm2-monitor]"        string => ".*vgchange.*";

      "startcommand[mcstrans]"   string => "/etc/init.d/mcstrans start";
      "restartcommand[mcstrans]" string => "/etc/init.d/mcstrans restart";
      "reloadcommand[mcstrans]"  string => "/etc/init.d/mcstrans reload";
      "stopcommand[mcstrans]"    string => "/etc/init.d/mcstrans stop";
      "pattern[mcstrans]"        string => ".*mcstransd.*";

      "startcommand[mdmonitor]"   string => "/etc/init.d/mdmonitor start";
      "restartcommand[mdmonitor]" string => "/etc/init.d/mdmonitor restart";
      "reloadcommand[mdmonitor]"  string => "/etc/init.d/mdmonitor reload";
      "stopcommand[mdmonitor]"    string => "/etc/init.d/mdmonitor stop";
      "pattern[mdmonitor]"        string => ".*mdadm.*";

      "startcommand[mdmpd]"   string => "/etc/init.d/mdmpd start";
      "restartcommand[mdmpd]" string => "/etc/init.d/mdmpd restart";
      "reloadcommand[mdmpd]"  string => "/etc/init.d/mdmpd reload";
      "stopcommand[mdmpd]"    string => "/etc/init.d/mdmpd stop";
      "pattern[mdmpd]"        string => ".*mdmpd.*";

      "startcommand[messagebus]"   string => "/etc/init.d/messagebus start";
      "restartcommand[messagebus]" string => "/etc/init.d/messagebus restart";
      "reloadcommand[messagebus]"  string => "/etc/init.d/messagebus reload";
      "stopcommand[messagebus]"    string => "/etc/init.d/messagebus stop";
      "pattern[messagebus]"        string => ".*dbus-daemon.*";

      "startcommand[microcode_ctl]"   string => "/etc/init.d/microcode_ctl start";
      "restartcommand[microcode_ctl]" string => "/etc/init.d/microcode_ctl restart";
      "reloadcommand[microcode_ctl]"  string => "/etc/init.d/microcode_ctl reload";
      "stopcommand[microcode_ctl]"    string => "/etc/init.d/microcode_ctl stop";
      "pattern[microcode_ctl]"        string => ".*microcode_ctl.*";

      "startcommand[multipathd]"   string => "/etc/init.d/multipathd start";
      "restartcommand[multipathd]" string => "/etc/init.d/multipathd restart";
      "reloadcommand[multipathd]"  string => "/etc/init.d/multipathd reload";
      "stopcommand[multipathd]"    string => "/etc/init.d/multipathd stop";
      "pattern[multipathd]"        string => ".*multipathd.*";

      "startcommand[mysql]"   string => "/etc/init.d/mysqld start";
      "restartcommand[mysql]" string => "/etc/init.d/mysqld restart";
      "reloadcommand[mysql]"  string => "/etc/init.d/mysqld reload";
      "stopcommand[mysql]"    string => "/etc/init.d/mysqld stop";
      "pattern[mysql]"        string => ".*mysqld.*";

      "startcommand[netplugd]"   string => "/etc/init.d/netplugd start";
      "restartcommand[netplugd]" string => "/etc/init.d/netplugd restart";
      "reloadcommand[netplugd]"  string => "/etc/init.d/netplugd reload";
      "stopcommand[netplugd]"    string => "/etc/init.d/netplugd stop";
      "pattern[netplugd]"        string => ".*netplugd.*";

      "startcommand[NetworkManager]"   string => "/etc/init.d/NetworkManager start";
      "restartcommand[NetworkManager]" string => "/etc/init.d/NetworkManager restart";
      "reloadcommand[NetworkManager]"  string => "/etc/init.d/NetworkManager reload";
      "stopcommand[NetworkManager]"    string => "/etc/init.d/NetworkManager stop";
      "pattern[NetworkManager]"        string => ".*NetworkManager.*";

      "startcommand[nfs]"   string => "/etc/init.d/nfs start";
      "restartcommand[nfs]" string => "/etc/init.d/nfs restart";
      "reloadcommand[nfs]"  string => "/etc/init.d/nfs reload";
      "stopcommand[nfs]"    string => "/etc/init.d/nfs stop";
      "pattern[nfs]"        string => ".*nfsd.*";

      "startcommand[nfslock]"   string => "/etc/init.d/nfslock start";
      "restartcommand[nfslock]" string => "/etc/init.d/nfslock restart";
      "reloadcommand[nfslock]"  string => "/etc/init.d/nfslock reload";
      "stopcommand[nfslock]"    string => "/etc/init.d/nfslock stop";
      "pattern[nfslock]"        string => ".*rpc.statd.*";

      "startcommand[nscd]"   string => "/etc/init.d/nscd start";
      "restartcommand[nscd]" string => "/etc/init.d/nscd restart";
      "reloadcommand[nscd]"  string => "/etc/init.d/nscd reload";
      "stopcommand[nscd]"    string => "/etc/init.d/nscd stop";
      "pattern[nscd]"        string => ".*nscd.*";

      "startcommand[ntpd]"   string => "/etc/init.d/ntpd start";
      "restartcommand[ntpd]" string => "/etc/init.d/ntpd restart";
      "reloadcommand[ntpd]"  string => "/etc/init.d/ntpd reload";
      "stopcommand[ntpd]"    string => "/etc/init.d/ntpd stop";
      "pattern[ntpd]"        string => ".*ntpd.*";

      "startcommand[oddjobd]"   string => "/etc/init.d/oddjobd start";
      "restartcommand[oddjobd]" string => "/etc/init.d/oddjobd restart";
      "reloadcommand[oddjobd]"  string => "/etc/init.d/oddjobd reload";
      "stopcommand[oddjobd]"    string => "/etc/init.d/oddjobd stop";
      "pattern[oddjobd]"        string => ".*oddjobd.*";

      "startcommand[pand]"   string => "/etc/init.d/pand start";
      "restartcommand[pand]" string => "/etc/init.d/pand restart";
      "reloadcommand[pand]"  string => "/etc/init.d/pand reload";
      "stopcommand[pand]"    string => "/etc/init.d/pand stop";
      "pattern[pand]"        string => ".*pand.*";

      "startcommand[pcscd]"   string => "/etc/init.d/pcscd start";
      "restartcommand[pcscd]" string => "/etc/init.d/pcscd restart";
      "reloadcommand[pcscd]"  string => "/etc/init.d/pcscd reload";
      "stopcommand[pcscd]"    string => "/etc/init.d/pcscd stop";
      "pattern[pcscd]"        string => ".*pcscd.*";

      "startcommand[portmap]"   string => "/etc/init.d/portmap start";
      "restartcommand[portmap]" string => "/etc/init.d/portmap restart";
      "reloadcommand[portmap]"  string => "/etc/init.d/portmap reload";
      "stopcommand[portmap]"    string => "/etc/init.d/portmap stop";
      "pattern[portmap]"        string => ".*portmap.*";

      "startcommand[postgresql]"   string => "/etc/init.d/postgresql start";
      "restartcommand[postgresql]" string => "/etc/init.d/postgresql restart";
      "reloadcommand[postgresql]"  string => "/etc/init.d/postgresql reload";
      "stopcommand[postgresql]"    string => "/etc/init.d/postgresql stop";
      "pattern[postgresql]"        string => ".*postmaster.*";

      "startcommand[rdisc]"   string => "/etc/init.d/rdisc start";
      "restartcommand[rdisc]" string => "/etc/init.d/rdisc restart";
      "reloadcommand[rdisc]"  string => "/etc/init.d/rdisc reload";
      "stopcommand[rdisc]"    string => "/etc/init.d/rdisc stop";
      "pattern[rdisc]"        string => ".*rdisc.*";

      "startcommand[rdisc]"   string => "/etc/init.d/rdisc start";
      "restartcommand[rdisc]" string => "/etc/init.d/rdisc restart";
      "reloadcommand[rdisc]"  string => "/etc/init.d/rdisc reload";
      "stopcommand[rdisc]"    string => "/etc/init.d/rdisc stop";
      "pattern[rdisc]"        string => ".*rdisc.*";

      "startcommand[readahead_early]"   string => "/etc/init.d/readahead_early start";
      "restartcommand[readahead_early]" string => "/etc/init.d/readahead_early restart";
      "reloadcommand[readahead_early]"  string => "/etc/init.d/readahead_early reload";
      "stopcommand[readahead_early]"    string => "/etc/init.d/readahead_early stop";
      "pattern[readahead_early]"        string => ".*readahead.*early.*";

      "startcommand[readahead_later]"   string => "/etc/init.d/readahead_later start";
      "restartcommand[readahead_later]" string => "/etc/init.d/readahead_later restart";
      "reloadcommand[readahead_later]"  string => "/etc/init.d/readahead_later reload";
      "stopcommand[readahead_later]"    string => "/etc/init.d/readahead_later stop";
      "pattern[readahead_later]"        string => ".*readahead.*later.*";

      "startcommand[restorecond]"   string => "/etc/init.d/restorecond start";
      "restartcommand[restorecond]" string => "/etc/init.d/restorecond restart";
      "reloadcommand[restorecond]"  string => "/etc/init.d/restorecond reload";
      "stopcommand[restorecond]"    string => "/etc/init.d/restorecond stop";
      "pattern[restorecond]"        string => ".*restorecond.*";

      "startcommand[rhnsd]"   string => "/sbin/service rhnsd start";
      "restartcommand[rhnsd]" string => "/sbin/service rhnsd restart";
      "reloadcommand[rhnsd]"  string => "/sbin/service rhnsd reload";
      "stopcommand[rhnsd]"    string => "/sbin/service rhnsd stop";
      "pattern[rhnsd]"        string => "rhnsd";

      "startcommand[rpcgssd]"   string => "/etc/init.d/rpcgssd start";
      "restartcommand[rpcgssd]" string => "/etc/init.d/rpcgssd restart";
      "reloadcommand[rpcgssd]"  string => "/etc/init.d/rpcgssd reload";
      "stopcommand[rpcgssd]"    string => "/etc/init.d/rpcgssd stop";
      "pattern[rpcgssd]"        string => ".*rpc.gssd.*";

      "startcommand[rpcidmapd]"   string => "/etc/init.d/rpcidmapd start";
      "restartcommand[rpcidmapd]" string => "/etc/init.d/rpcidmapd restart";
      "reloadcommand[rpcidmapd]"  string => "/etc/init.d/rpcidmapd reload";
      "stopcommand[rpcidmapd]"    string => "/etc/init.d/rpcidmapd stop";
      "pattern[rpcidmapd]"        string => ".*rpc.idmapd.*";

      "startcommand[rpcsvcgssd]"   string => "/etc/init.d/rpcsvcgssd start";
      "restartcommand[rpcsvcgssd]" string => "/etc/init.d/rpcsvcgssd restart";
      "reloadcommand[rpcsvcgssd]"  string => "/etc/init.d/rpcsvcgssd reload";
      "stopcommand[rpcsvcgssd]"    string => "/etc/init.d/rpcsvcgssd stop";
      "pattern[rpcsvcgssd]"        string => ".*rpc.svcgssd.*";

      "startcommand[saslauthd]"   string => "/etc/init.d/saslauthd start";
      "restartcommand[saslauthd]" string => "/etc/init.d/saslauthd restart";
      "reloadcommand[saslauthd]"  string => "/etc/init.d/saslauthd reload";
      "stopcommand[saslauthd]"    string => "/etc/init.d/saslauthd stop";
      "pattern[saslauthd]"        string => ".*saslauthd.*";

      "startcommand[smartd]"   string => "/etc/init.d/smartd start";
      "restartcommand[smartd]" string => "/etc/init.d/smartd restart";
      "reloadcommand[smartd]"  string => "/etc/init.d/smartd reload";
      "stopcommand[smartd]"    string => "/etc/init.d/smartd stop";
      "pattern[smartd]"        string => ".*smartd.*";

      "startcommand[snmpd]"   string => "/etc/init.d/snmpd start";
      "restartcommand[snmpd]" string => "/sbin/service snmpd restart";
      "reloadcommand[snmpd]"  string => "/sbin/service snmpd reload";
      "stopcommand[snmpd]"    string => "/etc/init.d/snmpd stop";
      "pattern[snmpd]"        string => "/usr/sbin/snmpd";

      "startcommand[svnserve]"   string => "/etc/init.d/svnserve start";
      "restartcommand[svnserve]" string => "/etc/init.d/svnserve restart";
      "reloadcommand[svnserve]"  string => "/etc/init.d/svnserve reload";
      "stopcommand[svnserve]"    string => "/etc/init.d/svnserve stop";
      "pattern[svnserve]"        string => ".*svnserve.*";

      "startcommand[syslog]"   string => "/etc/init.d/syslog start";
      "restartcommand[syslog]" string => "/etc/init.d/syslog restart";
      "reloadcommand[syslog]"  string => "/etc/init.d/syslog reload";
      "stopcommand[syslog]"    string => "/etc/init.d/syslog stop";
      "pattern[syslog]"        string => ".*syslogd.*";

      "startcommand[tcsd]"   string => "/etc/init.d/tcsd start";
      "restartcommand[tcsd]" string => "/etc/init.d/tcsd restart";
      "reloadcommand[tcsd]"  string => "/etc/init.d/tcsd reload";
      "stopcommand[tcsd]"    string => "/etc/init.d/tcsd stop";
      "pattern[tcsd]"        string => ".*tcsd.*";

      "startcommand[www]"   string => "/etc/init.d/httpd start";
      "restartcommand[www]" string => "/etc/init.d/httpd restart";
      "reloadcommand[www]"  string => "/etc/init.d/httpd reload";
      "stopcommand[www]"    string => "/etc/init.d/httpd stop";
      "pattern[www]"        string => ".*httpd.*";

      "startcommand[xfs]"   string => "/etc/init.d/xfs start";
      "restartcommand[xfs]" string => "/etc/init.d/xfs restart";
      "reloadcommand[xfs]"  string => "/etc/init.d/xfs reload";
      "stopcommand[xfs]"    string => "/etc/init.d/xfs stop";
      "pattern[xfs]"        string => ".*xfs.*";

      "startcommand[ypbind]"   string => "/etc/init.d/ypbind start";
      "restartcommand[ypbind]" string => "/etc/init.d/ypbind restart";
      "reloadcommand[ypbind]"  string => "/etc/init.d/ypbind reload";
      "stopcommand[ypbind]"    string => "/etc/init.d/ypbind stop";
      "pattern[ypbind]"        string => ".*ypbind.*";

      "startcommand[yum-updatesd]"   string => "/etc/init.d/yum-updatesd start";
      "restartcommand[yum-updatesd]" string => "/etc/init.d/yum-updatesd restart";
      "reloadcommand[yum-updatesd]"  string => "/etc/init.d/yum-updatesd reload";
      "stopcommand[yum-updatesd]"    string => "/etc/init.d/yum-updatesd stop";
      "pattern[yum-updatesd]"        string => ".*yum-updatesd.*";

      "startcommand[ssh]"   string => "/etc/init.d/sshd start";
      "restartcommand[ssh]" string => "/etc/init.d/sshd restart";
      "reloadcommand[ssh]"  string => "/etc/init.d/sshd reload";
      "stopcommand[ssh]"    string => "/etc/init.d/sshd stop";
      "pattern[ssh]"        string => ".*sshd.*";

    debian|ubuntu::

      "startcommand[atd]"   string => "/etc/init.d/atd start";
      "restartcommand[atd]" string => "/etc/init.d/atd restart";
      "reloadcommand[atd]"  string => "/etc/init.d/atd reload";
      "stopcommand[atd]"    string => "/etc/init.d/atd stop";
      "pattern[atd]"        string => "atd.*";

      "startcommand[bluetoothd]"   string => "/etc/init.d/bluetoothd start";
      "restartcommand[bluetoothd]" string => "/etc/init.d/bluetoothd restart";
      "reloadcommand[bluetoothd]"  string => "/etc/init.d/bluetoothd reload";
      "stopcommand[bluetoothd]"    string => "/etc/init.d/bluetoothd stop";
      "pattern[bluetoothd]"        string => ".*bluetoothd.*";

      "startcommand[bootlogd]"   string => "/etc/init.d/bootlogd start";
      "restartcommand[bootlogd]" string => "/etc/init.d/bootlogd restart";
      "reloadcommand[bootlogd]"  string => "/etc/init.d/bootlogd reload";
      "stopcommand[bootlogd]"    string => "/etc/init.d/bootlogd stop";
      "pattern[bootlogd]"        string => ".*bootlogd.*";

      "startcommand[crond]"   string => "/etc/init.d/cron start";
      "restartcommand[crond]" string => "/etc/init.d/cron restart";
      "reloadcommand[crond]"  string => "/etc/init.d/cron reload";
      "stopcommand[crond]"    string => "/etc/init.d/cron stop";
      "pattern[crond]"        string => ".*cron.*";

      "startcommand[kerneloops]"   string => "/etc/init.d/kerneloops start";
      "restartcommand[kerneloops]" string => "/etc/init.d/kerneloops restart";
      "reloadcommand[kerneloops]"  string => "/etc/init.d/kerneloops reload";
      "stopcommand[kerneloops]"    string => "/etc/init.d/kerneloops stop";
      "pattern[kerneloops]"        string => ".*kerneloops.*";

      "startcommand[mysql]"   string => "/etc/init.d/mysql start";
      "restartcommand[mysql]" string => "/etc/init.d/mysql restart";
      "reloadcommand[mysql]"  string => "/etc/init.d/mysql reload";
      "stopcommand[mysql]"    string => "/etc/init.d/mysql stop";
      "pattern[mysql]"        string => ".*mysqld.*";

      "startcommand[ntpd]"   string => "/etc/init.d/ntp start";
      "restartcommand[ntpd]" string => "/etc/init.d/ntp restart";
      "reloadcommand[ntpd]"  string => "/etc/init.d/ntp reload";
      "stopcommand[ntpd]"    string => "/etc/init.d/ntp stop";
      "pattern[ntpd]"        string => ".*ntpd.*";

      "startcommand[NetworkManager]"   string => "/etc/init.d/network-manager start";
      "restartcommand[NetworkManager]" string => "/etc/init.d/network-manager restart";
      "reloadcommand[NetworkManager]"  string => "/etc/init.d/network-manager reload";
      "stopcommand[NetworkManager]"    string => "/etc/init.d/network-manager stop";
      "pattern[NetworkManager]"        string => ".*NetworkManager.*";

      "startcommand[ondemand]"   string => "/etc/init.d/ondemand start";
      "restartcommand[ondemand]" string => "/etc/init.d/ondemand restart";
      "reloadcommand[ondemand]"  string => "/etc/init.d/ondemand reload";
      "stopcommand[ondemand]"    string => "/etc/init.d/ondemand stop";
      "pattern[ondemand]"        string => ".*ondemand.*";

      "startcommand[plymouth]"   string => "/etc/init.d/plymouthd start";
      "restartcommand[plymouth]" string => "/etc/init.d/plymouthd restart";
      "reloadcommand[plymouth]"  string => "/etc/init.d/plymouthd reload";
      "stopcommand[plymouth]"    string => "/etc/init.d/plymouthd stop";
      "pattern[plymouth]"        string => ".*plymouthd.*";

      "startcommand[postgresql84]"   string => "/etc/init.d/postgresql-8.4 start";
      "restartcommand[postgresql84]" string => "/etc/init.d/postgresql-8.4 restart";
      "reloadcommand[postgresql84]"  string => "/etc/init.d/postgresql-8.4 reload";
      "stopcommand[postgresql84]"    string => "/etc/init.d/postgresql-8.4 stop";
      "pattern[postgresql84]"        string => ".*postgresql.*";

      "startcommand[postgresql91]"   string => "/etc/init.d/postgresql-9.1 start";
      "restartcommand[postgresql91]" string => "/etc/init.d/postgresql-9.1 restart";
      "reloadcommand[postgresql91]"  string => "/etc/init.d/postgresql-9.1 reload";
      "stopcommand[postgresql91]"    string => "/etc/init.d/postgresql-9.1 stop";
      "pattern[postgresql91]"        string => ".*postgresql.*";

      "startcommand[saned]"   string => "/etc/init.d/saned start";
      "restartcommand[saned]" string => "/etc/init.d/saned restart";
      "reloadcommand[saned]"  string => "/etc/init.d/saned reload";
      "stopcommand[saned]"    string => "/etc/init.d/saned stop";
      "pattern[saned]"        string => ".*saned.*";

      "startcommand[udev]"   string => "/etc/init.d/udev start";
      "restartcommand[udev]" string => "/etc/init.d/udev restart";
      "reloadcommand[udev]"  string => "/etc/init.d/udev reload";
      "stopcommand[udev]"    string => "/etc/init.d/udev stop";
      "pattern[udev]"        string => ".*udev.*";

      "startcommand[udevmonitor]"   string => "/etc/init.d/udevmonitor start";
      "restartcommand[udevmonitor]" string => "/etc/init.d/udevmonitor restart";
      "reloadcommand[udevmonitor]"  string => "/etc/init.d/udevmonitor reload";
      "stopcommand[udevmonitor]"    string => "/etc/init.d/udevmonitor stop";
      "pattern[udevmonitor]"        string => ".*udevadm.*monitor.*";

      "startcommand[www]"   string => "/etc/init.d/apache2 start";
      "restartcommand[www]" string => "/etc/init.d/apache2 restart";
      "reloadcommand[www]"  string => "/etc/init.d/apache2 reload";
      "stopcommand[www]"    string => "/etc/init.d/apache2 stop";
      "pattern[www]"        string => ".*apache2.*";

      "startcommand[ssh]"   string => "/etc/init.d/ssh start";
      "restartcommand[ssh]" string => "/etc/init.d/ssh restart";
      "reloadcommand[ssh]"  string => "/etc/init.d/ssh reload";
      "stopcommand[ssh]"    string => "/etc/init.d/ssh stop";
      "pattern[ssh]"        string => ".*sshd.*";

      "startcommand[snmpd]"   string => "/etc/init.d/snmpd start";
      "restartcommand[snmpd]" string => "/etc/init.d/snmpd restart";
      "reloadcommand[snmpd]"  string => "/etc/init.d/snmpd reload";
      "stopcommand[snmpd]"    string => "/etc/init.d/snmpd stop";
      "pattern[snmpd]"        string => "/usr/sbin/snmpd";

      # METHODS that implement these ............................................

  classes:

      "start" expression => strcmp("start","$(state)"),
      comment => "Check if to start a service";
      "restart" expression => strcmp("restart","$(state)"),
      comment => "Check if to restart a service";
      "reload" expression => strcmp("reload","$(state)"),
      comment => "Check if to reload a service";
      "stop"  expression => strcmp("stop","$(state)"),
      comment => "Check if to stop a service";

      # Do we want to include the packages here too?

  processes:

    start::

      "$(pattern[$(service)])" ->  { "@(stakeholders[$(service)])" }

      comment => "Verify that the service appears in the process table",
      restart_class => "start_$(service)";

    stop::

      "$(pattern[$(service)])" -> { "@(stakeholders[$(service)])" }

      comment => "Verify that the service does not appear in the process",
      process_stop => "$(stopcommand[$(service)])",
      signals => { "term", "kill"};

  commands:

      "$(startcommand[$(service)])" -> { "@(stakeholders[$(service)])" }

      comment => "Execute command to start the $(service) service",
      ifvarclass => canonify("start_$(service)");

    restart::
      "$(restartcommand[$(service)])" -> { "@(stakeholders[$(service)])" }

      comment => "Execute command to restart the $(service) service";

    reload::
      "$(reloadcommand[$(service)])" -> { "@(stakeholders[$(service)])" }

      comment => "Execute command to reload the $(service) service";
}

##-------------------------------------------------------
## database promises
##-------------------------------------------------------

body database_server local_mysql(username, password)
{
      db_server_owner => "$(username)";
      db_server_password => "$(password)";
      db_server_host => "localhost";
      db_server_type => "mysql";
      db_server_connection_db => "mysql";
}

##

body database_server local_postgresql(username, password)
{
      db_server_owner => "$(username)";
      db_server_password => "$(password)";
      db_server_host => "localhost";
      db_server_type => "postgres";
      db_server_connection_db => "postgres";
}

##-------------------------------------------------------
## guest_environment promises
##-------------------------------------------------------

body environment_resources kvm(name, arch, cpu_count, mem_kb, disk_file)
{
      env_spec =>
      "<domain type='kvm'>
  <name>$(name)</name>
  <memory>$(mem_kb)</memory>
  <currentMemory>$(mem_kb)</currentMemory>
  <vcpu>$(cpu_count)</vcpu>
  <os>
    <type arch='$(arch)'>hvm</type>
  </os>
  <features>
    <acpi/>
    <apic/>
    <pae/>
  </features>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>restart</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='disk'>
      <source file='$(disk_file)'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <interface type='network'>
      <source network='default'/>
    </interface>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' autoport='yes'/>
  </devices>
</domain>";
}

####################################################
## monitor bodyparts
####################################################

body match_value scan_log(line)
{
      select_line_matching => "$(line)";
      track_growing_file => "true";
}

##

body match_value scan_changing_file(line)
{
      select_line_matching => "$(line)";
      track_growing_file => "false";
}

##

body match_value single_value(regex)
{
      select_line_matching => "$(regex)";
      extraction_regex => "($(regex))";
}

##

body match_value line_match_value(line_match, extract_regex)
{
      select_line_matching => "$(line_match)";
      extraction_regex => "$(extract_regex)";
}

##

body action sample_rate(x)
{
      ifelapsed => "$(x)";
      expireafter => "10";
}

bundle common paths
# In addition to defining common paths, this bundle also defines context
# classes for paths that are defined (_stdlib_has_path_xxx) and paths that
# exist (_stdlib_path_exists_xxx)
{
  vars:

      #
      # Common full pathname of commands for OS
      #

    any::
      "path[getfacl]"  string => "/usr/bin/getfacl";

    aix::

      "path[awk]"      string => "/usr/bin/awk";
      "path[bc]"       string => "/usr/bin/bc";
      "path[cat]"      string => "/bin/cat";
      "path[cksum]"    string => "/usr/bin/cksum";
      "path[crontabs]" string => "/var/spool/cron/crontabs";
      "path[cut]"      string => "/usr/bin/cut";
      "path[dc]"       string => "/usr/bin/dc";
      "path[df]"       string => "/usr/bin/df";
      "path[diff]"     string => "/usr/bin/diff";
      "path[dig]"      string => "/usr/bin/dig";
      "path[echo]"     string => "/usr/bin/echo";
      "path[egrep]"    string => "/usr/bin/egrep";
      "path[find]"     string => "/usr/bin/find";
      "path[grep]"     string => "/usr/bin/grep";
      "path[ls]"       string => "/usr/bin/ls";
      "path[netstat]"  string => "/usr/bin/netstat";
      "path[ping]"     string => "/usr/bin/ping";
      "path[perl]"     string => "/usr/bin/perl";
      "path[printf]"   string => "/usr/bin/printf";
      "path[sed]"      string => "/usr/bin/sed";
      "path[sort]"     string => "/usr/bin/sort";
      "path[tr]"       string => "/usr/bin/tr";

    freebsd|netbsd::

      "path[awk]"      string => "/usr/bin/awk";
      "path[bc]"       string => "/usr/bin/bc";
      "path[cat]"      string => "/bin/cat";
      "path[cksum]"    string => "/usr/bin/cksum";
      "path[crontabs]" string => "/var/cron/tabs";
      "path[cut]"      string => "/usr/bin/cut";
      "path[dc]"       string => "/usr/bin/dc";
      "path[df]"       string => "/bin/df";
      "path[diff]"     string => "/usr/bin/diff";
      "path[dig]"      string => "/usr/bin/dig";
      "path[echo]"     string => "/bin/echo";
      "path[egrep]"    string => "/usr/bin/egrep";
      "path[find]"     string => "/usr/bin/find";
      "path[grep]"     string => "/usr/bin/grep";
      "path[ls]"       string => "/bin/ls";
      "path[netstat]"  string => "/usr/bin/netstat";
      "path[ping]"     string => "/usr/bin/ping";
      "path[perl]"     string => "/usr/bin/perl";
      "path[printf]"   string => "/usr/bin/printf";
      "path[sed]"      string => "/usr/bin/sed";
      "path[sort]"     string => "/usr/bin/sort";
      "path[tr]"       string => "/usr/bin/tr";

    openbsd::

      "path[awk]"      string => "/usr/bin/awk";
      "path[bc]"       string => "/usr/bin/bc";
      "path[cat]"      string => "/bin/cat";
      "path[cksum]"    string => "/bin/cksum";
      "path[crontabs]" string => "/var/cron/tabs";
      "path[cut]"      string => "/usr/bin/cut";
      "path[dc]"       string => "/usr/bin/dc";
      "path[df]"       string => "/bin/df";
      "path[diff]"     string => "/usr/bin/diff";
      "path[dig]"      string => "/usr/sbin/dig";
      "path[echo]"     string => "/bin/echo";
      "path[egrep]"    string => "/usr/bin/egrep";
      "path[find]"     string => "/usr/bin/find";
      "path[grep]"     string => "/usr/bin/grep";
      "path[ls]"       string => "/bin/ls";
      "path[netstat]"  string => "/usr/bin/netstat";
      "path[ping]"     string => "/usr/bin/ping";
      "path[perl]"     string => "/usr/bin/perl";
      "path[printf]"   string => "/usr/bin/printf";
      "path[sed]"      string => "/usr/bin/sed";
      "path[sort]"     string => "/usr/bin/sort";
      "path[tr]"       string => "/usr/bin/tr";

    solaris::

      "path[awk]"      string => "/usr/bin/awk";
      "path[bc]"       string => "/usr/bin/bc";
      "path[cat]"      string => "/usr/bin/cat";
      "path[cksum]"    string => "/usr/bin/cksum";
      "path[crontabs]" string => "/var/spool/cron/crontabs";
      "path[cut]"      string => "/usr/bin/cut";
      "path[dc]"       string => "/usr/bin/dc";
      "path[df]"       string => "/usr/bin/df";
      "path[diff]"     string => "/usr/bin/diff";
      "path[dig]"      string => "/usr/sbin/dig";
      "path[echo]"     string => "/usr/bin/echo";
      "path[egrep]"    string => "/usr/bin/egrep";
      "path[find]"     string => "/usr/bin/find";
      "path[grep]"     string => "/usr/bin/grep";
      "path[ls]"       string => "/usr/bin/ls";
      "path[netstat]"  string => "/usr/bin/netstat";
      "path[ping]"     string => "/usr/bin/ping";
      "path[perl]"     string => "/usr/bin/perl";
      "path[printf]"   string => "/usr/bin/printf";
      "path[sed]"      string => "/usr/bin/sed";
      "path[sort]"     string => "/usr/bin/sort";
      "path[tr]"       string => "/usr/bin/tr";
      #
      "path[svcs]"     string => "/usr/bin/svcs";
      "path[svcadm]"   string => "/usr/sbin/svcadm";

    redhat::

      "path[awk]"           string => "/bin/awk";
      "path[bc]"            string => "/usr/bin/bc";
      "path[cat]"           string => "/bin/cat";
      "path[cksum]"         string => "/usr/bin/cksum";
      "path[createrepo]"    string => "/usr/bin/createrepo";
      "path[crontab]"       string => "/usr/bin/crontab";
      "path[crontabs]"      string => "/var/spool/cron";
      "path[cut]"           string => "/bin/cut";
      "path[dc]"            string => "/usr/bin/dc";
      "path[df]"            string => "/bin/df";
      "path[diff]"          string => "/usr/bin/diff";
      "path[dig]"           string => "/usr/bin/dig";
      "path[domainname]"    string => "/bin/domainname";
      "path[echo]"          string => "/bin/echo";
      "path[egrep]"         string => "/bin/egrep";
      "path[find]"          string => "/usr/bin/find";
      "path[grep]"          string => "/bin/grep";
      "path[hostname]"      string => "/bin/hostname";
      "path[init]"          string => "/sbin/init";
      "path[iptables]"      string => "/sbin/iptables";
      "path[iptables_save]" string => "/sbin/iptables-save";
      "path[ls]"            string => "/bin/ls";
      "path[netstat]"       string => "/bin/netstat";
      "path[ping]"          string => "/usr/bin/ping";
      "path[perl]"          string => "/usr/bin/perl";
      "path[printf]"        string => "/usr/bin/printf";
      "path[sed]"           string => "/bin/sed";
      "path[sort]"          string => "/bin/sort";
      "path[sysctl]"        string => "/sbin/sysctl";
      "path[test]"          string => "/usr/bin/test";
      "path[tr]"            string => "/usr/bin/tr";

      #
      "path[chkconfig]" string => "/sbin/chkconfig";
      "path[groupadd]"  string => "/usr/sbin/groupadd";
      "path[groupdel]"  string => "/usr/sbin/groupdel";
      "path[ifconfig]"  string => "/sbin/ifconfig";
      "path[ip]"        string => "/sbin/ip";
      "path[rpm]"       string => "/bin/rpm";
      "path[service]"   string => "/sbin/service";
      "path[svc]"       string => "/sbin/service";
      "path[useradd]"   string => "/usr/sbin/useradd";
      "path[userdel]"   string => "/usr/sbin/userdel";
      "path[yum]"       string => "/usr/bin/yum";

    debian::

      "path[awk]"           string => "/usr/bin/awk";
      "path[bc]"            string => "/usr/bin/bc";
      "path[cat]"           string => "/bin/cat";
      "path[chkconfig]"     string => "/sbin/chkconfig";
      "path[cksum]"         string => "/usr/bin/cksum";
      "path[createrepo]"    string => "/usr/bin/createrepo";
      "path[crontab]"       string => "/usr/bin/crontab";
      "path[crontabs]"      string => "/var/spool/cron/crontabs";
      "path[cut]"           string => "/usr/bin/cut";
      "path[dc]"            string => "/usr/bin/dc";
      "path[df]"            string => "/bin/df";
      "path[diff]"          string => "/usr/bin/diff";
      "path[dig]"           string => "/usr/bin/dig";
      "path[dmidecode]"     string => "/usr/sbin/dmidecode";
      "path[domainname]"    string => "/bin/domainname";
      "path[echo]"          string => "/bin/echo";
      "path[egrep]"         string => "/bin/egrep";
      "path[find]"          string => "/usr/bin/find";
      "path[grep]"          string => "/bin/grep";
      "path[hostname]"      string => "/bin/hostname";
      "path[ls]"            string => "/bin/ls";
      "path[init]"          string => "/sbin/init";
      "path[iptables]"      string => "/sbin/iptables";
      "path[iptables_save]" string => "/sbin/iptables-save";
      "path[netstat]"       string => "/bin/netstat";
      "path[ping]"          string => "/bin/ping";
      "path[perl]"          string => "/usr/bin/perl";
      "path[printf]"        string => "/usr/bin/printf";
      "path[sed]"           string => "/bin/sed";
      "path[sort]"          string => "/usr/bin/sort";
      "path[sysctl]"        string => "/sbin/sysctl";
      "path[test]"          string => "/usr/bin/test";
      "path[tr]"            string => "/usr/bin/tr";

      #
      "path[apt_cache]"           string => "/usr/bin/apt-cache";
      "path[apt_config]"          string => "/usr/bin/apt-config";
      "path[apt_get]"             string => "/usr/bin/apt-get";
      "path[apt_key]"             string => "/usr/bin/apt-key";
      "path[aptitude]"            string => "/usr/bin/aptitude";
      "path[dpkg]"                string => "/usr/bin/dpkg";
      "path[groupadd]"            string => "/usr/sbin/groupadd";
      "path[ifconfig]"            string => "/sbin/ifconfig";
      "path[ip]"                  string => "/sbin/ip";
      "path[service]"             string => "/usr/sbin/service";
      "path[svc]"                 string => "/usr/sbin/service";
      "path[update_alternatives]" string => "/usr/bin/update-alternatives";
      "path[update_rc_d]"         string => "/usr/sbin/update-rc.d";
      "path[useradd]"             string => "/usr/sbin/useradd";

    SuSE||SUSE||suse::

      "path[awk]"              string => "/usr/bin/awk";
      "path[bundle common]"    string => "/usr/bin/bundle common";
      "path[cat]"              string => "/bin/cat";
      "path[cksum]"            string => "/usr/bin/cksum";
      "path[createrepo]"       string => "/usr/bin/createrepo";
      "path[crontab]"          string => "/usr/bin/crontab";
      "path[crontabs]"         string => "/vars:/spool/cron/tabs";
      "path[cut]"              string => "/usr/bin/cut";
      "path[dc]"               string => "/usr/bin/dc";
      "path[df]"               string => "/bin/df";
      "path[diff]"             string => "/usr/bin/diff";
      "path[dig]"              string => "/usr/bin/dig";
      "path[domainname]"       string => "/bin/domainname";
      "path[echo]"             string => "/bin/echo";
      "path[egrep]"            string => "/usr/bin/egrep";
      "path[find]"             string => "/usr/bin/find";
      "path[free]"             string => "/usr/bin/free";
      "path[grep]"             string => "/usr/bin/grep";
      "path[hostname]"         string => "/bin/hostname";
      "path[init]"             string => "/sbin/init";
      "path[iptables]"         string => "/usr/sbin/iptables";
      "path[iptables_save]"    string => "/usr/sbin/iptables-save";
      "path[ls]"               string => "/bin/ls";
      "path[lsof]"             string => "/usr/bin/lsof";
      "path[netstat]"          string => "/bin/netstat";
      "path[ping]"             string => "/bin/ping";
      "path[perl]"             string => "/usr/bin/perl";
      "path[printf]"           string => "/usr/bin/printf";
      "path[sed]"              string => "/bin/sed";
      "path[sort]"             string => "/usr/bin/sort";
      "path[test]"             string => "/usr/bin/test";
      "path[tr]"               string => "/usr/bin/tr";

      #
      "path[chkconfig]"        string => "/sbin/chkconfig";
      "path[groupadd]"         string => "/usr/sbin/groupadd";
      "path[groupdel]"         string => "/usr/sbin/groupdel";
      "path[groupmod]"         string => "/usr/sbin/groupmod";
      "path[ifconfig]"         string => "/sbin/ifconfig";
      "path[ip]"               string => "/sbin/ip";
      "path[rpm]"              string => "/bin/rpm";
      "path[service]"          string => "/sbin/service";
      "path[useradd]"          string => "/usr/sbin/useradd";
      "path[userdel]"          string => "/usr/sbin/userdel";
      "path[usermod]"          string => "/usr/sbin/usermod";
      "path[zypper]"           string => "/usr/bin/zypper";
      "path[logger]"           string => "/usr/bin/logger";

    any::
      "all_paths"     slist => getindices("path");
      "$(all_paths)" string => "$(path[$(all_paths)])";

  classes:
      "_stdlib_has_path_$(all_paths)"
      expression => isvariable("$(all_paths)"),
      comment    => "It's useful to know if a given path is defined";

      "_stdlib_path_exists_$(all_paths)"
      expression => fileexists("$(path[$(all_paths)])"),
      comment    => "It's useful to know if $(all_paths) exists on the filesystem as defined";
}

###############################################################################
#####     To make 3.4 clients able to run on the lastest 3.6.0 policy     #####
###############################################################################

bundle agent logrotate(log_files, max_size, rotate_levels)
# @brief rotate specified "log_files" larger than "max_size". Keep
# "rotate_levels" versions of the files before overwriting the oldest one
# @depends rotate
# @depends bigger_than
# @param log_files single file or list of files to evaluate for rotation
# @param max_size minimum size in bytes that the file will grow to before being rotated
# @param rotate_levels number of rotations to keep before overwriting the oldest one
#
# **Example:**
#
# ```cf3
# bundle agent example
# {
#   vars:
#     "logdirs" slist => { "/var/log/syslog", "/var/log/maillog"};
#
#   methods:
#     "logrotate" usebundle => logrotate( @(logdirs), "1M", "2" );
#     "logrotate" usebundle => logrotate( "/var/log/mylog, "1", "5" );
#     "logrotate" usebundle => logrotate( "/var/log/alog, "500k", "7" );
# }
# ```
{
  files:
      "$(log_files)"
      comment     => "Rotate file if above specified size",
      rename      => rotate("$(rotate_levels)"),
      file_select => bigger_than("$(max_size)");
}

bundle agent prunedir(dir, max_days)
# @brief delete plain files inside "dir" older than "max_days" (not recursively).
# @depends tidy
# @depends recurse
# @depends filetype_older_than
# @param dir directory to examine for files
# @param max_days maximum number of days old a files mtime is allowed to before deletion
#
# **Example:**
#
# ```cf3
# bundle agent example
# {
#   vars:
#     "dirs" slist => { "/tmp/logs", "/tmp/logs2" };
#
#   methods:
#     "prunedir" usebundle => prunedir( @(dirs), "1" );
# }
# ```
{
  files:
      "$(dir)"
      comment       => "Delete plain files inside directory older than max_days",
      delete        => tidy,
      file_select   => filetype_older_than("plain", "$(max_days)"),
      depth_search  => recurse("1");
}

body file_select bigger_than(size)
{
      search_size => irange("0","$(size)");
      file_result => "!size";
}

###############################################################################