@@ -6,6 +6,38 @@ agent_binary_path="/usr/bin/observe-agent"
6
6
observeagent_config_dir=" /etc/observe-agent"
7
7
tmp_dir=" /tmp/observe-agent"
8
8
9
+ # Parse args
10
+ while [ $# -gt 0 ]; do
11
+ opt=$1
12
+ shift
13
+ arg=" "
14
+ if [[ " $opt " == * " =" * ]]; then
15
+ arg=$( echo $opt | cut -d' =' -f2)
16
+ opt=$( echo $opt | cut -d' =' -f1)
17
+ elif [ $# -gt 0 ]; then
18
+ arg=" $1 "
19
+ shift
20
+ fi
21
+ case " $opt " in
22
+ --token)
23
+ TOKEN=" $arg "
24
+ ;;
25
+ --observe_url)
26
+ OBSERVE_URL=" $arg "
27
+ ;;
28
+ --logs_enabled)
29
+ LOGS_ENABLED=" $arg "
30
+ ;;
31
+ --metrics_enabled)
32
+ METRICS_ENABLED=" $arg "
33
+ ;;
34
+ * )
35
+ echo " Unknown option: $opt "
36
+ exit 1
37
+ ;;
38
+ esac
39
+ done
40
+
9
41
# If the observe-agent.yaml file already exists, leave it alone.
10
42
# Otherwise we need to know what the collection endpoint and token are.
11
43
if [ ! -f " $observeagent_config_dir /observe-agent.yaml" ]; then
@@ -48,26 +80,44 @@ sudo rm -rf $observeagent_config_dir/connections
48
80
sudo cp -fR $tmp_dir /connections $observeagent_config_dir /connections
49
81
sudo chown -R root:root $observeagent_config_dir
50
82
51
- # Set up the systemd service if it doesn't exist already.
52
- if ! systemctl list-unit-files observe-agent.service | grep observe-agent > /dev/null; then
53
- echo " Installing observe-agent.service as a systemd service. This may ask for your password..."
54
- sudo cp -f $tmp_dir /observe-agent.service /etc/systemd/system/observe-agent.service
55
- sudo chown root:root /etc/systemd/system/observe-agent.service
56
- sudo systemctl daemon-reload
57
- sudo systemctl enable observe-agent.service
58
- sudo systemctl start observe-agent
59
- elif systemctl is-active --quiet observe-agent; then
60
- echo " Restarting observe-agent.service. This may ask for your password..."
61
- sudo systemctl restart observe-agent
62
- fi
63
-
64
83
# Initialize the agent config file if it doesn't exist.
65
84
if [ -f " $observeagent_config_dir /observe-agent.yaml" ]; then
66
85
echo " Leaving existing observe-agent.yaml in place."
67
86
else
68
87
echo " Initializing observe-agent.yaml"
69
- sudo $agent_binary_path init-config --token $TOKEN --observe_url $OBSERVE_URL --config_path $observeagent_config_dir /observe-agent.yaml
88
+ INIT_FLAGS=" --config_path $observeagent_config_dir /observe-agent.yaml --token $TOKEN --observe_url $OBSERVE_URL --host_monitoring::enabled=true"
89
+ if [ -n " $LOGS_ENABLED " ]; then
90
+ if [[ " ${LOGS_ENABLED,,} " == " true" ]]; then
91
+ INIT_FLAGS=" $INIT_FLAGS --host_monitoring::logs::enabled=true"
92
+ else
93
+ INIT_FLAGS=" $INIT_FLAGS --host_monitoring::logs::enabled=false"
94
+ fi
95
+ fi
96
+ if [ -n " $METRICS_ENABLED " ]; then
97
+ if [[ " ${METRICS_ENABLED,,} " == " true" ]]; then
98
+ INIT_FLAGS=" $INIT_FLAGS --host_monitoring::metrics::host::enabled=true"
99
+ else
100
+ INIT_FLAGS=" $INIT_FLAGS --host_monitoring::metrics::host::enabled=false"
101
+ fi
102
+ fi
103
+ sudo $agent_binary_path init-config $INIT_FLAGS
70
104
sudo chown root:root $observeagent_config_dir /observe-agent.yaml
71
105
fi
72
106
107
+ # Check if systemd is available.
108
+ if [[ -d /run/systemd/system ]]; then
109
+ # Set up the systemd service if it doesn't exist already.
110
+ if ! systemctl list-unit-files observe-agent.service | grep observe-agent > /dev/null; then
111
+ echo " Installing observe-agent.service as a systemd service. This may ask for your password..."
112
+ sudo cp -f $tmp_dir /observe-agent.service /etc/systemd/system/observe-agent.service
113
+ sudo chown root:root /etc/systemd/system/observe-agent.service
114
+ sudo systemctl daemon-reload
115
+ sudo systemctl enable observe-agent.service
116
+ sudo systemctl start observe-agent
117
+ elif systemctl is-active --quiet observe-agent; then
118
+ echo " Restarting observe-agent.service. This may ask for your password..."
119
+ sudo systemctl restart observe-agent
120
+ fi
121
+ fi
122
+
73
123
echo " Observe agent successfully installed to $agent_binary_path with config in $observeagent_config_dir "
0 commit comments