]> arthur.barton.de Git - netdata.git/blob - netdata-installer.sh
2663e7e3cf6be7ab9de1432f516d5d87a22b6088
[netdata.git] / netdata-installer.sh
1 #!/bin/bash
2
3 # reload the user profile
4 [ -f /etc/profile ] && . /etc/profile
5
6 # fix PKG_CHECK_MODULES error
7 if [ -d /usr/share/aclocal ]
8 then
9         ACLOCAL_PATH=${ACLOCAL_PATH-/usr/share/aclocal}
10         export ACLOCAL_PATH
11 fi
12
13 LC_ALL=C
14 umask 022
15
16 # you can set CFLAGS before running installer
17 CFLAGS="${CFLAGS--O3}"
18
19 # keep a log of this command
20 printf "\n# " >>netdata-installer.log
21 date >>netdata-installer.log
22 printf "CFLAGS=\"%s\" " "${CFLAGS}" >>netdata-installer.log
23 printf "%q " "$0" "${@}" >>netdata-installer.log
24 printf "\n" >>netdata-installer.log
25
26 ME="$0"
27 DONOTSTART=0
28 DONOTWAIT=0
29 NETDATA_PREFIX=
30 ZLIB_IS_HERE=0
31
32 usage() {
33         cat <<-USAGE
34
35         ${ME} <installer options>
36
37         Valid <installer options> are:
38
39            --install /PATH/TO/INSTALL
40
41                         If your give: --install /opt
42                         netdata will be installed in /opt/netdata
43
44            --dont-start-it
45
46                         Do not (re)start netdata.
47                         Just install it.
48
49            --dont-wait
50
51                         Do not wait for the user to press ENTER.
52                         Start immediately building it.
53
54            --zlib-is-really-here
55
56                         If you get errors about missing zlib,
57                         but you know it is available,
58                         you have a broken pkg-config.
59                         Use this option to allow it continue
60                         without checking pkg-config.
61
62         Netdata will by default be compiled with gcc optimization -O3
63         If you need to pass different CFLAGS, use something like this:
64
65           CFLAGS="<gcc options>" ${ME} <installer options>
66
67         For the installer to complete successfully, you will need
68         these packages installed:
69
70            gcc make autoconf automake pkg-config zlib1g-dev (or zlib-devel)
71            uuid-dev (or libuuid-devel)
72
73         For the plugins, you will at least need:
74
75            curl nodejs
76
77 USAGE
78 }
79
80 while [ ! -z "${1}" ]
81 do
82         if [ "$1" = "--install" ]
83                 then
84                 NETDATA_PREFIX="${2}/netdata"
85                 shift 2
86         elif [ "$1" = "--zlib-is-really-here" ]
87                 then
88                 ZLIB_IS_HERE=1
89                 shift 1
90         elif [ "$1" = "--dont-start-it" ]
91                 then
92                 DONOTSTART=1
93                 shift 1
94         elif [ "$1" = "--dont-wait" ]
95                 then
96                 DONOTWAIT=1
97                 shift 1
98         elif [ "$1" = "--help" -o "$1" = "-h" ]
99                 then
100                 usage
101                 exit 1
102         else
103                 echo >&2
104                 echo >&2 "ERROR:"
105                 echo >&2 "I cannot understand option '$1'."
106                 usage
107                 exit 1
108         fi
109 done
110
111 cat <<-BANNER
112
113         Welcome to netdata!
114         Nice to see you are giving it a try!
115
116         You are about to build and install netdata to your system.
117
118         It will be installed at these locations:
119
120           - the daemon    at ${NETDATA_PREFIX}/usr/sbin/netdata
121           - config files  at ${NETDATA_PREFIX}/etc/netdata
122           - web files     at ${NETDATA_PREFIX}/usr/share/netdata
123           - plugins       at ${NETDATA_PREFIX}/usr/libexec/netdata
124           - cache files   at ${NETDATA_PREFIX}/var/cache/netdata
125           - db files      at ${NETDATA_PREFIX}/var/lib/netdata
126           - log files     at ${NETDATA_PREFIX}/var/log/netdata
127           - pid file      at ${NETDATA_PREFIX}/var/run
128
129         This installer allows you to change the installation path.
130         Press Control-C and run the same command with --help for help.
131
132 BANNER
133
134 if [ "${UID}" -ne 0 ]
135         then
136         if [ -z "${NETDATA_PREFIX}" ]
137                 then
138                 cat <<-NONROOTNOPREFIX
139
140                 Sorry! This will fail!
141
142                 You are attempting to install netdata as non-root, but you plan to install it
143                 in system paths.
144
145                 Please set an installation prefix, like this:
146
147                         $0 ${@} --install /tmp
148
149                 or, run the installer as root:
150
151                         sudo $0 ${@}
152
153                 We suggest to install it as root, or certain data collectors will not be able
154                 to work. Netdata drops root privileges when running. So, if you plan to keep
155                 it, install it as root to get the full functionality.
156
157 NONROOTNOPREFIX
158                 exit 1
159
160         else
161                 cat <<-NONROOT
162
163                 IMPORTANT:
164                 You are about to install netdata as a non-root user.
165                 Netdata will work, but a few data collection modules that
166                 require root access will fail.
167
168                 If you installing permanently on your system, run the
169                 installer like this:
170
171                         sudo $0 ${@}
172
173 NONROOT
174         fi
175 fi
176
177 have_autotools=
178 if [ "$(type autoreconf 2> /dev/null)" ]
179 then
180         autoconf_maj_min() {
181                 local maj min IFS=.-
182
183                 maj=$1
184                 min=$2
185
186                 set -- $(autoreconf -V | sed -ne '1s/.* \([^ ]*\)$/\1/p')
187                 eval $maj=\$1 $min=\$2
188         }
189         autoconf_maj_min AMAJ AMIN
190
191         if [ "$AMAJ" -gt 2 ]
192         then
193                 have_autotools=Y
194         elif [ "$AMAJ" -eq 2 -a "$AMIN" -ge 60 ]
195         then
196                 have_autotools=Y
197         else
198                 echo "Found autotools $AMAJ.$AMIN"
199         fi
200 else
201         echo "No autotools found"
202 fi
203
204 if [ ! "$have_autotools" ]
205 then
206         if [ -f configure ]
207         then
208                 echo "Will skip autoreconf step"
209         else
210                 cat <<-"EOF"
211
212                 -------------------------------------------------------------------------------
213                 autotools 2.60 or later is required
214
215                 Sorry, you do not seem to have autotools 2.60 or later, which is
216                 required to build from the git sources of netdata.
217
218                 You can either install a suitable version of autotools and automake
219                 or download a netdata package which does not have these dependencies.
220
221                 Source packages where autotools have already been run are available
222                 here:
223                            https://firehol.org/download/netdata/
224
225                 The unsigned/master folder tracks the head of the git tree and released
226                 packages are also available.
227 EOF
228                 exit 1
229         fi
230 fi
231
232 if [ ${DONOTWAIT} -eq 0 ]
233         then
234         if [ ! -z "${NETDATA_PREFIX}" ]
235                 then
236                 read -p "Press ENTER to build and install netdata to '${NETDATA_PREFIX}' > "
237         else
238                 read -p "Press ENTER to build and install netdata to your system > "
239         fi
240 fi
241
242 build_error() {
243         cat <<-EOF
244
245         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
246
247         Sorry! NetData failed to build...
248
249         You many need to check these:
250
251         1. The package uuid-dev (or libuuid-devel) has to be installed.
252
253         2. The package zlib1g-dev (or zlib-devel) has to be installed.
254
255            If your system cannot find ZLIB, although it is installed
256            run me with the option:  --zlib-is-really-here
257
258         3. You need basic build tools installed, like:
259
260            gcc make autoconf automake pkg-config
261
262            Autoconf version 2.60 or higher is required.
263
264         If you still cannot get it to build, ask for help at github:
265
266            https://github.com/firehol/netdata/issues
267
268
269 EOF
270         trap - EXIT
271         exit 1
272 }
273
274 run() {
275         printf >>netdata-installer.log "# "
276         printf >>netdata-installer.log "%q " "${@}"
277         printf >>netdata-installer.log " ... "
278
279         printf >&2 "\n"
280         printf >&2 ":-----------------------------------------------------------------------------\n"
281         printf >&2 "Running command:\n"
282         printf >&2 "\n"
283         printf >&2 "%q " "${@}"
284         printf >&2 "\n"
285
286         "${@}"
287
288         local ret=$?
289         if [ ${ret} -ne 0 ]
290                 then
291                 printf >>netdata-installer.log "FAILED!\n"
292         else
293                 printf >>netdata-installer.log "OK\n"
294         fi
295
296         return ${ret}
297 }
298
299 if [ ${ZLIB_IS_HERE} -eq 1 ]
300         then
301         shift
302         echo >&2 "ok, assuming zlib is really installed."
303         export ZLIB_CFLAGS=" "
304         export ZLIB_LIBS="-lz"
305 fi
306
307 trap build_error EXIT
308
309 if [ "$have_autotools" ]
310 then
311         run ./autogen.sh || exit 1
312 fi
313
314 run ./configure \
315         --prefix="${NETDATA_PREFIX}/usr" \
316         --sysconfdir="${NETDATA_PREFIX}/etc" \
317         --localstatedir="${NETDATA_PREFIX}/var" \
318         --with-zlib --with-math --with-user=netdata \
319         CFLAGS="${CFLAGS}" || exit 1
320
321 # remove the build_error hook
322 trap - EXIT
323
324 if [ -f src/netdata ]
325         then
326         echo >&2 "Cleaning a possibly old compilation ..."
327         run make clean
328 fi
329
330 echo >&2 "Compiling netdata ..."
331 run make || exit 1
332
333 # backup user configurations
334 for x in apps_groups.conf charts.d.conf
335 do
336         if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}" ]
337                 then
338                 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}" "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup"
339         fi
340 done
341
342 echo >&2 "Installing netdata ..."
343 run make install || exit 1
344
345 # restore user configurations
346 for x in apps_groups.conf charts.d.conf
347 do
348         if [ -f "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" ]
349                 then
350                 cp -p "${NETDATA_PREFIX}/etc/netdata/${x}.installer_backup" "${NETDATA_PREFIX}/etc/netdata/${x}"
351         fi
352 done
353
354 NETDATA_ADDED_TO_DOCKER=0
355 if [ ${UID} -eq 0 ]
356         then
357         getent group netdata > /dev/null
358         if [ $? -ne 0 ]
359                 then
360                 echo >&2 "Adding netdata user group ..."
361                 run groupadd -r netdata
362         fi
363
364         getent passwd netdata > /dev/null
365         if [ $? -ne 0 ]
366                 then
367                 echo >&2 "Adding netdata user account ..."
368                 run useradd -r -g netdata -c netdata -s /sbin/nologin -d / netdata
369         fi
370
371         getent group docker > /dev/null
372         if [ $? -eq 0 ]
373                 then
374                 # find the users in the docker group
375                 docker=$(getent group docker | cut -d ':' -f 4)
376                 if [[ ",${docker}," =~ ,netdata, ]]
377                         then
378                         # netdata is already there
379                         :
380                 else
381                         # netdata is not in docker group
382                         echo >&2 "Adding netdata user to the docker group (needed to get container names) ..."
383                         run usermod -a -G docker netdata
384                 fi
385                 # let the uninstall script know
386                 NETDATA_ADDED_TO_DOCKER=1
387         fi
388 fi
389
390
391 # -----------------------------------------------------------------------------
392 # load options from the configuration file
393
394 # create an empty config if it does not exist
395 [ ! -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ] && touch "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
396
397 # function to extract values from the config file
398 config_option() {
399         local key="${1}" value="${2}" line=
400
401         if [ -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
402                 then
403                 line="$( grep "^[[:space:]]*${key}[[:space:]]*=[[:space:]]*" "${NETDATA_PREFIX}/etc/netdata/netdata.conf" | head -n 1 )"
404                 [ ! -z "${line}" ] && value="$( echo "${line}" | cut -d '=' -f 2 | sed -e "s/^[[:space:]]\+//g" -e "s/[[:space:]]\+$//g" )"
405         fi
406
407         echo "${value}"
408 }
409
410 # user
411 defuser="netdata"
412 [ ! "${UID}" = "0" ] && defuser="${USER}"
413 NETDATA_USER="$( config_option "run as user" "${defuser}" )"
414
415 NETDATA_WEB_USER="$( config_option "web files owner" "${defuser}" )"
416 NETDATA_WEB_GROUP="$( config_option "web files group" "${NETDATA_WEB_USER}" )"
417
418 # debug flags
419 defdebug=0
420 NETDATA_DEBUG="$( config_option "debug flags" ${defdebug} )"
421
422 # port
423 defport=19999
424 NETDATA_PORT="$( config_option "port" ${defport} )"
425
426 # directories
427 NETDATA_LIB_DIR="$( config_option "lib directory" "${NETDATA_PREFIX}/var/lib/netdata" )"
428 NETDATA_CACHE_DIR="$( config_option "cache directory" "${NETDATA_PREFIX}/var/cache/netdata" )"
429 NETDATA_WEB_DIR="$( config_option "web files directory" "${NETDATA_PREFIX}/usr/share/netdata/web" )"
430 NETDATA_LOG_DIR="$( config_option "log directory" "${NETDATA_PREFIX}/var/log/netdata" )"
431 NETDATA_CONF_DIR="$( config_option "config directory" "${NETDATA_PREFIX}/etc/netdata" )"
432 NETDATA_BIND="$( config_option "bind socket to IP" "*" )"
433 NETDATA_RUN_DIR="${NETDATA_PREFIX}/var/run"
434
435
436 # -----------------------------------------------------------------------------
437 # prepare the directories
438
439 # this is needed if NETDATA_PREFIX is not empty
440 if [ ! -d "${NETDATA_RUN_DIR}" ]
441         then
442         mkdir -p "${NETDATA_RUN_DIR}" || exit 1
443 fi
444
445 echo >&2 "Fixing directories (user: ${NETDATA_USER})..."
446 for x in "${NETDATA_WEB_DIR}" "${NETDATA_CONF_DIR}" "${NETDATA_CACHE_DIR}" "${NETDATA_LOG_DIR}" "${NETDATA_LIB_DIR}"
447 do
448         if [ ! -d "${x}" ]
449                 then
450                 echo >&2 "Creating directory '${x}'"
451                 run mkdir -p "${x}" || exit 1
452         fi
453
454         if [ ${UID} -eq 0 ]
455                 then
456                 if [ "${x}" = "${NETDATA_WEB_DIR}" ]
457                         then
458                         run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}..."
459                 else
460                         run chown -R "${NETDATA_USER}:${NETDATA_USER}" "${x}" || echo >&2 "WARNING: Cannot change the ownership of the files in directory ${x} to ${NETDATA_USER}..."
461                 fi
462         fi
463
464         run chmod 0755 "${x}" || echo >&2 "WARNING: Cannot change the permissions of the directory ${x} to 0755..."
465 done
466
467 if [ ${UID} -eq 0 ]
468         then
469         run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
470         run chmod 0755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
471         run setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
472         if [ $? -ne 0 ]
473                 then
474                 # fix apps.plugin to be setuid to root
475                 run chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
476                 run chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
477         fi
478 fi
479
480 # -----------------------------------------------------------------------------
481 # check if we can re-start netdata
482
483 if [ ${DONOTSTART} -eq 1 ]
484         then
485         if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
486                 then
487                 echo >&2 "Generating empty config file in: ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
488                 echo "# Get config from http://127.0.0.1:${NETDATA_PORT}/netdata.conf" >"${NETDATA_PREFIX}/etc/netdata/netdata.conf"
489
490                 if [ "${UID}" -eq 0 ]
491                         then
492                         chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
493                 fi
494                 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
495         fi
496         echo >&2 "OK. It is now installed and ready."
497         exit 0
498 fi
499
500 # -----------------------------------------------------------------------------
501 # stop a running netdata
502
503 isnetdata() {
504         [ -z "$1" -o ! -f "/proc/$1/stat" ] && return 1
505         [ "$(cat "/proc/$1/stat" | cut -d '(' -f 2 | cut -d ')' -f 1)" = "netdata" ] && return 0
506         return 1
507 }
508
509
510 echo >&2
511 echo >&2 "-------------------------------------------------------------------------------"
512 echo >&2
513 printf >&2 "Stopping a (possibly) running netdata..."
514 ret=0
515 count=0
516 while [ $ret -eq 0 ]
517 do
518         if [ $count -gt 30 ]
519                 then
520                 echo >&2 "Cannot stop the running netdata."
521                 exit 1
522         fi
523
524         count=$((count + 1))
525
526         pid=$(cat "${NETDATA_RUN_DIR}/netdata.pid" 2>/dev/null)
527         # backwards compatibility
528         [ -z "${pid}" ] && pid=$(cat /var/run/netdata.pid 2>/dev/null)
529         [ -z "${pid}" ] && pid=$(cat /var/run/netdata/netdata.pid 2>/dev/null)
530         
531         isnetdata $pid || pid=
532         if [ ! -z "${pid}" ]
533                 then
534                 run kill $pid 2>/dev/null
535                 ret=$?
536         else
537                 run killall netdata 2>/dev/null
538                 ret=$?
539         fi
540
541         test $ret -eq 0 && printf >&2 "." && sleep 2
542 done
543 echo >&2
544 echo >&2
545
546
547 # -----------------------------------------------------------------------------
548 # run netdata
549
550 echo >&2 "Starting netdata..."
551 run ${NETDATA_PREFIX}/usr/sbin/netdata -pidfile ${NETDATA_RUN_DIR}/netdata.pid "${@}"
552
553 if [ $? -ne 0 ]
554         then
555         echo >&2
556         echo >&2 "SORRY! FAILED TO START NETDATA!"
557         exit 1
558 else
559         echo >&2 "OK. NetData Started!"
560 fi
561
562
563 # -----------------------------------------------------------------------------
564 # save a config file, if it is not already there
565
566 if [ ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf" ]
567         then
568         echo >&2 "Downloading default configuration from netdata..."
569         sleep 5
570
571         # remove a possibly obsolete download
572         [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
573
574         # disable a proxy to get data from the local netdata
575         export http_proxy=
576         export https_proxy=
577
578         # try wget
579         wget 2>/dev/null -O "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
580         ret=$?
581
582         # try curl
583         if [ $ret -ne 0 -o ! -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
584                 then
585                 curl -s -o "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "http://localhost:${NETDATA_PORT}/netdata.conf"
586                 ret=$?
587         fi
588
589         if [ $ret -eq 0 -a -s "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ]
590                 then
591                 mv "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
592                 echo >&2 "New configuration saved for you to edit at ${NETDATA_PREFIX}/etc/netdata/netdata.conf"
593
594                 if [ "${UID}" -eq 0 ]
595                         then
596                         chown "${NETDATA_USER}" "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
597                 fi
598                 chmod 0664 "${NETDATA_PREFIX}/etc/netdata/netdata.conf"
599         else
600                 echo >&2 "Cannnot download configuration from netdata daemon using url 'http://localhost:${NETDATA_PORT}/netdata.conf'"
601                 [ -f "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new" ] && rm "${NETDATA_PREFIX}/etc/netdata/netdata.conf.new"
602         fi
603 fi
604
605 # -----------------------------------------------------------------------------
606 # Check for KSM
607
608 ksm_is_available_but_disabled() {
609         cat <<-KSM1
610
611         -------------------------------------------------------------------------------
612         Memory de-duplication instructions
613
614         I see you have kernel memory de-duper (called Kernel Same-page Merging,
615         or KSM) available, but it is not currently enabled.
616
617         To enable it run:
618
619         echo 1 >/sys/kernel/mm/ksm/run
620         echo 1000 >/sys/kernel/mm/ksm/sleep_millisecs
621
622         If you enable it, you will save 40-60% of netdata memory.
623
624 KSM1
625 }
626
627 ksm_is_not_available() {
628         cat <<-KSM2
629
630         -------------------------------------------------------------------------------
631         Memory de-duplication not present in your kernel
632
633         It seems you do not have kernel memory de-duper (called Kernel Same-page
634         Merging, or KSM) available.
635
636         To enable it, you need a kernel built with CONFIG_KSM=y
637
638         If you can have it, you will save 40-60% of netdata memory.
639
640 KSM2
641 }
642
643 if [ -f "/sys/kernel/mm/ksm/run" ]
644         then
645         if [ $(cat "/sys/kernel/mm/ksm/run") != "1" ]
646                 then
647                 ksm_is_available_but_disabled
648         fi
649 else
650         ksm_is_not_available
651 fi
652
653 # -----------------------------------------------------------------------------
654 # Check for version.txt
655
656 if [ ! -s web/version.txt ]
657         then
658         cat <<-VERMSG
659
660         -------------------------------------------------------------------------------
661         Version update check warning
662
663         The way you downloaded netdata, we cannot find its version. This means the
664         Update check on the dashboard, will not work.
665
666         If you want to have version update check, please re-install it
667         following the procedure in:
668
669         https://github.com/firehol/netdata/wiki/Installation
670
671 VERMSG
672 fi
673
674 # -----------------------------------------------------------------------------
675 # apps.plugin warning
676
677 if [ "${UID}" -ne 0 ]
678         then
679         cat <<-SETUID_WARNING
680
681         -------------------------------------------------------------------------------
682         apps.plugin needs privileges
683
684         Since you have installed netdata as a normal user, to have apps.plugin collect
685         all the needed data, you have to give it the access rights it needs, by running
686         either of the following sets of commands:
687
688         To run apps.plugin with escalated capabilities:
689
690                 sudo chown root:${NETDATA_USER} "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
691                 sudo chmod 0750 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
692                 sudo setcap cap_dac_read_search,cap_sys_ptrace+ep "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
693
694         or, to run apps.plugin as root:
695
696                 sudo chown root "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
697                 sudo chmod 4755 "${NETDATA_PREFIX}/usr/libexec/netdata/plugins.d/apps.plugin"
698
699         These commands allow apps.plugin to run as root.
700
701         apps.plugin is performing a hard-coded function of data collection for all
702         running processes. It cannot be instructed from the netdata daemon to perform
703         any task, so it is pretty safe to do this.
704
705 SETUID_WARNING
706 fi
707
708 # -----------------------------------------------------------------------------
709 # Keep un-install info
710
711 cat >netdata-uninstaller.sh <<-UNINSTALL
712         #!/bin/bash
713
714         # this script will uninstall netdata
715
716         if [ "\$1" != "--force" ]
717                 then
718                 echo >&2 "This script will REMOVE netdata from your system."
719                 echo >&2 "Run it again with --force to do it."
720                 exit 1
721         fi
722
723         echo >&2 "Stopping a possibly running netdata..."
724         killall netdata
725         sleep 2
726
727         deletedir() {
728                 if [ ! -z "\$1" -a -d "\$1" ]
729                         then
730                         echo
731                         echo "Deleting directory '\$1' ..."
732                         rm -I -R "\$1"
733                 fi
734         }
735
736         if [ ! -z "${NETDATA_PREFIX}" -a -d "${NETDATA_PREFIX}" ]
737                 then
738                 # installation prefix was given
739
740                 deletedir "${NETDATA_PREFIX}"
741
742         else
743                 # installation prefix was NOT given
744
745                 if [ -f "${NETDATA_PREFIX}/usr/sbin/netdata" ]
746                         then
747                         echo "Deleting ${NETDATA_PREFIX}/usr/sbin/netdata ..."
748                         rm -i "${NETDATA_PREFIX}/usr/sbin/netdata"
749                 fi
750
751                 deletedir "${NETDATA_PREFIX}/etc/netdata"
752                 deletedir "${NETDATA_PREFIX}/usr/share/netdata"
753                 deletedir "${NETDATA_PREFIX}/usr/libexec/netdata"
754                 deletedir "${NETDATA_PREFIX}/var/lib/netdata"
755                 deletedir "${NETDATA_PREFIX}/var/cache/netdata"
756                 deletedir "${NETDATA_PREFIX}/var/log/netdata"
757         fi
758
759         getent passwd netdata > /dev/null
760         if [ $? -eq 0 ]
761                 then
762                 echo
763                 echo "You may also want to remove the user netdata"
764                 echo "by running:"
765                 echo "   userdel netdata"
766         fi
767
768         getent group netdata > /dev/null
769         if [ $? -eq 0 ]
770                 then
771                 echo
772                 echo "You may also want to remove the group netdata"
773                 echo "by running:"
774                 echo "   groupdel netdata"
775         fi
776
777         getent group docker > /dev/null
778         if [ $? -eq 0 -a "${NETDATA_ADDED_TO_DOCKER}" = "1" ]
779                 then
780                 echo
781                 echo "You may also want to remove the netdata user from the docker group"
782                 echo "by running:"
783                 echo "   gpasswd -d netdata docker"
784         fi
785
786 UNINSTALL
787 chmod 750 netdata-uninstaller.sh
788
789 # -----------------------------------------------------------------------------
790
791 if [ "${NETDATA_BIND}" = "*" ]
792         then
793         access="localhost"
794 else
795         access="${NETDATA_BIND}"
796 fi
797
798 cat <<-END
799
800
801         -------------------------------------------------------------------------------
802
803         OK. NetData is installed and it is running (listening to ${NETDATA_BIND}:${NETDATA_PORT}).
804
805         -------------------------------------------------------------------------------
806
807
808         Hit http://${access}:${NETDATA_PORT}/ from your browser.
809
810         To stop netdata, just kill it, with:
811
812           killall netdata
813
814         To start it, just run it:
815
816           ${NETDATA_PREFIX}/usr/sbin/netdata
817
818
819         Enjoy!
820
821                                          Give netdata a Github Star, at:
822
823                                  https://github.com/firehol/netdata/wiki
824
825
826 END
827 echo >&2 "Uninstall script generated: ./netdata-uninstaller.sh"