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