1body classes if_failed(x)
2{
3      repair_failed => { "$(x)" };
4}
5
6body contain run_under_shell
7{
8      useshell => "useshell";
9}
10
11body action in_background
12{
13      background => "true";
14}
15
16
17bundle agent start_server(server_config)
18{
19  classes:
20      "debug_server" expression => "debug_mode";
21
22  vars:
23      "config_basename" string => filestat("$(server_config)", basename);
24      "dlog"            string => "$(sys.workdir)/server-debug.$(config_basename).log";
25
26  commands:
27    !debug_server.!windows::
28      "$(sys.cf_serverd) -Kf $(server_config)"
29        classes => if_failed("server_failed");
30    !debug_server.windows::
31      # Windows cannot daemonize and needs to start in background.
32      "$(sys.cf_serverd) -Kf $(server_config)"
33        action => in_background,
34        classes => if_failed("server_failed");
35
36    debug_server::
37      "$(sys.cf_serverd) -Kldf $(server_config) > $(dlog) 2>&1"
38        contain => run_under_shell,
39        action => in_background,
40        classes => if_failed("server_failed");
41
42    debug_server|windows::
43      # Sleep 3 seconds since cf-serverd takes some time to start in background
44      # mode. We need to add a handle with $(server_config) in it so that the
45      # promise is not skipped if this bundle is used for multiple configs.
46      "$(G.sleep) 3"
47        contain => run_under_shell,
48        handle => "sleep_for_$(server_config)";
49
50  reports:
51    debug_server::
52      "$(sys.cf_serverd) was run in debug mode, the logs will be in $(dlog)";
53}
54
55
56bundle agent run_test(test_name)
57{
58  classes:
59      "debug_client" expression => "debug_mode";
60
61  vars:
62      "dlog" string => "$(sys.workdir)/agent-debug.log";
63
64  commands:
65    !debug_client::
66      "$(sys.cf_agent) -KIf $(test_name) -D DEBUG,AUTO 2>&1 | $(G.tee) $(dlog)"
67        contain => run_under_shell;
68    debug_client::
69      "$(sys.cf_agent) -Kldf $(test_name) -D DEBUG,EXTRA,AUTO 2>&1 | $(G.tee) $(dlog)"
70        contain => run_under_shell;
71
72  reports:
73    debug_client::
74      "$(sys.cf_agent) was run in debug mode, the logs will be in $(dlog)";
75}
76
77
78bundle agent run_runagent(runagent_params)
79{
80  classes:
81      "debug_client" expression => "debug_mode";
82
83  vars:
84      "dlog" string => "$(sys.workdir)/runagent-debug.log";
85
86  commands:
87    !debug_client::
88      "$(sys.cf_runagent) -I $(runagent_params) 2>&1 | $(G.tee) $(dlog)"
89        contain => run_under_shell;
90    debug_client::
91      "$(sys.cf_runagent) -d $(runagent_params) 2>&1 | $(G.tee) $(dlog)"
92        contain => run_under_shell;
93
94  reports:
95    debug_client::
96      "$(sys.cf_runagent) was run in debug mode, the logs will be in $(dlog)";
97}
98
99
100bundle agent stop_server(server_config)
101{
102  # On some old platforms, "ps" truncates its output, which CFEngine depends on. This can lead to
103  # the test servers not being killed.
104  # On HP-UX you can set the DEFAULT_CMD_LINE_WIDTH inside /etc/default/ps to a higher value, which
105  # controls the maximum line length of "ps". Unfortunately it is not overridable from the
106  # environment.
107  processes:
108      "$(server_config)"
109        signals => { "term", "kill" };
110}
111