generated from nginx/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathstartNIM.sh
executable file
·149 lines (127 loc) · 5.64 KB
/
startNIM.sh
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
#!/bin/bash
# Makes sure that Clickhouse is up and running - dedicated pod
RETCODE=-1
while [ ! $RETCODE = 0 ]
do
nc -z $NIM_CLICKHOUSE_ADDRESS $NIM_CLICKHOUSE_PORT
RETCODE=$?
echo "Waiting for ClickHouse..."
sleep 3
done
if [ -f "/deployment/counter.enabled" ]
then
export DATAPLANE_TYPE=NGINX_MANAGEMENT_SYSTEM
export DATAPLANE_FQDN="https://127.0.0.1:443"
export DATAPLANE_USERNAME=$NIM_USERNAME
export DATAPLANE_PASSWORD=$NIM_PASSWORD
export NMS_CH_HOST=$NIM_CLICKHOUSE_ADDRESS
export NMS_CH_PORT=$NIM_CLICKHOUSE_PORT
export NMS_CH_USER=$NIM_CLICKHOUSE_USERNAME
export NMS_CH_PASS=$NIM_CLICKHOUSE_PASSWORD
python3 /deployment/app.py &
fi
mkdir /nonexistent
/etc/nms/scripts/basic_passwords.sh $NIM_USERNAME $NIM_PASSWORD
# NGINX Management Suite version detection
# NMS >= 2.7.0 configuration is yaml
VERSION=`nms-core -v`
A=${VERSION%\/*}
B=${A##*\ }
RELEASE=`echo $B | awk -F- '{print $2"."$3"."$4}'`
echo -n "Detected NMS $RELEASE... "
case $RELEASE in
2.4.0|2.5.0|2.5.1|2.6.0)
echo "legacy nms.conf"
# Clickhouse configuration - dedicated pod
echo -e "
# Clickhouse config
clickhouse_address = $NIM_CLICKHOUSE_ADDRESS:$NIM_CLICKHOUSE_PORT
clickhouse_username = '$NIM_CLICKHOUSE_USERNAME'
clickhouse_password = '$NIM_CLICKHOUSE_PASSWORD'
" >> /etc/nms/nms.conf
;;
2.7.0|2.8.0|2.9.0|2.9.1|2.10.0|2.10.1|2.11.0|2.12.0)
echo "YAML nms.conf <= 2.12"
# Clickhouse configuration - dedicated pod
echo -e "
# Clickhouse config
clickhouse:
address: $NIM_CLICKHOUSE_ADDRESS:$NIM_CLICKHOUSE_PORT
username: '$NIM_CLICKHOUSE_USERNAME'
password: '$NIM_CLICKHOUSE_PASSWORD'
" >> /etc/nms/nms.conf
;;
*)
echo "YAML nms.conf >= 2.13"
# Clickhouse configuration - dedicated pod
export NIM_CLICKHOUSE_ADDRESSPORT=$NIM_CLICKHOUSE_ADDRESS:$NIM_CLICKHOUSE_PORT
yq '.clickhouse.address=strenv(NIM_CLICKHOUSE_ADDRESSPORT)|.clickhouse.username=strenv(NIM_CLICKHOUSE_USERNAME)|.clickhouse.password=strenv(NIM_CLICKHOUSE_PASSWORD)' /etc/nms/nms.conf > /etc/nms/nms.conf-updated
mv /etc/nms/nms.conf-updated /etc/nms/nms.conf
chown nms:nms /etc/nms/nms.conf
chmod 644 /etc/nms/nms.conf
yq '.clickhouse.address="tcp://"+strenv(NIM_CLICKHOUSE_ADDRESSPORT)|.clickhouse.username=strenv(NIM_CLICKHOUSE_USERNAME)|.clickhouse.password=strenv(NIM_CLICKHOUSE_PASSWORD)' /etc/nms/nms-sm-conf.yaml > /etc/nms/nms-sm-conf.yaml-updated
mv /etc/nms/nms-sm-conf.yaml-updated /etc/nms/nms-sm-conf.yaml
chown nms:nms /etc/nms/nms-sm-conf.yaml
chmod 644 /etc/nms/nms-sm-conf.yaml
;;
esac
# Start nms core - from /lib/systemd/system/nms-core.service
/bin/bash -c '`which mkdir` -p /var/lib/nms/dqlite/'
/bin/bash -c '`which mkdir` -p /var/lib/nms/secrets/'
/bin/bash -c '`which mkdir` -p /var/run/nms/'
/bin/bash -c '`which mkdir` -p /var/log/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/log/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/run/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/lib/nms/'
/bin/bash -c '`which chmod` 0775 /var/log/nms/'
/bin/bash -c '`which chown` -R nms:nms /etc/nms/certs/services/core'
/bin/bash -c '`which chown` nms:nms /etc/nms/certs/services/ca.crt'
/bin/bash -c '`which chmod` 0700 /etc/nms/certs/services/core'
/bin/bash -c '`which chmod` 0600 /etc/nms/certs/services/core/*'
su - nms -c 'function repeat { while [ 1 ] ; do "$@" ; sleep 1 ; done; };repeat /usr/bin/nms-core &' -s /bin/bash
# Start nms dpm - from /lib/systemd/system/nms-dpm.service
/bin/bash -c '`which mkdir` -p /var/lib/nms/streaming/'
/bin/bash -c '`which mkdir` -p /var/lib/nms/dqlite/'
/bin/bash -c '`which mkdir` -p /var/run/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/log/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/lib/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/run/nms/'
/bin/bash -c '`which chown` -R nms:nms /etc/nms/certs/services/dataplane-manager'
/bin/bash -c '`which chown` nms:nms /etc/nms/certs/services/ca.crt'
/bin/bash -c '`which chmod` 0700 /etc/nms/certs/services/dataplane-manager'
/bin/bash -c '`which chmod` 0600 /etc/nms/certs/services/dataplane-manager/*'
su - nms -c 'function repeat { while [ 1 ] ; do "$@" ; sleep 1 ; done; };repeat /usr/bin/nms-dpm &' -s /bin/bash
# Start nms ingestion - from /lib/systemd/system/nms-ingestion.service
/bin/bash -c '`which mkdir` -p /var/run/nms/'
/bin/bash -c '`which mkdir` -p /var/log/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/log/nms/'
/bin/bash -c '`which chmod` 0775 /var/log/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/run/nms/'
su - nms -c 'function repeat { while [ 1 ] ; do "$@" ; sleep 1 ; done; };repeat /usr/bin/nms-ingestion &' -s /bin/bash
# Start nms integrations - from /lib/systemd/system/nms-integrations.service
/bin/bash -c '`which mkdir` -p /var/lib/nms/dqlite/'
/bin/bash -c '`which mkdir` -p /var/run/nms/'
/bin/bash -c '`which mkdir` -p /var/log/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/lib/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/run/nms/'
/bin/bash -c '`which chown` -R nms:nms /var/log/nms/'
/bin/bash -c '`which chmod` 0775 /var/log/nms/'
/bin/bash -c '`which chown` nms:nms /etc/nms/certs/services/ca.crt'
su - nms -c 'function repeat { while [ 1 ] ; do "$@" ; sleep 1 ; done; };repeat /usr/bin/nms-integrations &' -s /bin/bash
sleep 5
# Start Security Monitoring
if [ -f /usr/bin/nms-sm ]
then
su - nms -c 'function repeat { while [ 1 ] ; do "$@" ; sleep 1 ; done; };repeat /usr/bin/nms-sm start &' -s /bin/bash
fi
chmod 666 /var/run/nms/*.sock
/etc/init.d/nginx start
# License activation
if ((${#NIM_LICENSE[@]}))
then
curl -s -X PUT -k https://127.0.0.1/api/platform/v1/license -u "$NIM_USERNAME:$NIM_PASSWORD" -d '{ "desiredState": { "content": "'$NIM_LICENSE'" }, "metadata": { "name": "license" } }' -H "Content-Type: application/json"
fi
while [ 1 ]
do
sleep 60
done