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