move init installation to functions.sh
Costa Tsaousis (ktsaou) committed
Mar 27, 2017 at 02:36 UTC
d3aa6e735805ec2cd2fea664a6309d52b4ab59e0
2 files changed
+79
-59
installer/functions.sh
+78
@@ -342,3 +342,81 @@ issystemd() {
342
# else, it is not systemd
343
return 1
344
}
345
+
346
+install_non_systemd_init() {
347
+ [ "${UID}" != 0 ] && return 1
348
+
349
+ local key="unknown"
350
+ if [ -f /etc/os-release ]
351
+ then
352
+ source /etc/os-release || return 1
353
+ key="${ID}-${VERSION_ID}"
354
+
355
+ elif [ -f /etc/centos-release ]
356
+ then
357
+ key=$(</etc/centos-release)
358
+ fi
359
+
360
+ if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
361
+ then
362
+ if [ "${key}" = "gentoo" ]
363
+ then
364
+ echo >&2 "Installing OpenRC init file..."
365
+ run cp system/netdata-openrc /etc/init.d/netdata && \
366
+ run chmod 755 /etc/init.d/netdata && \
367
+ run rc-update add netdata default && \
368
+ return 0
369
+
370
+ elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
371
+ then
372
+ echo >&2 "Installing LSB init file..."
373
+ run cp system/netdata-lsb /etc/init.d/netdata && \
374
+ run chmod 755 /etc/init.d/netdata && \
375
+ run update-rc.d netdata defaults && \
376
+ run update-rc.d netdata enable && \
377
+ return 0
378
+
379
+ elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
380
+ then
381
+ echo >&2 "Installing init.d file..."
382
+ run cp system/netdata-init-d /etc/init.d/netdata && \
383
+ run chmod 755 /etc/init.d/netdata && \
384
+ run chkconfig netdata on && \
385
+ return 0
386
+ else
387
+ echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
388
+ return 1
389
+ fi
390
+ elif [ -f /etc/init.d/netdata ]
391
+ then
392
+ echo >&2 "file '/etc/init.d/netdata' already exists."
393
+ return 0
394
+ else
395
+ echo >&2 "I don't know what init file to install on system '${key}'. Open a github issue to help us fix it."
396
+ fi
397
+
398
+ return 1
399
+}
400
+
401
+install_netdata_service() {
402
+ if issystemd
403
+ then
404
+ # systemd is running on this system
405
+ if [ ! -f /etc/systemd/system/netdata.service ]
406
+ then
407
+ echo >&2 "Installing systemd service..."
408
+ run cp system/netdata.service /etc/systemd/system/netdata.service && \
409
+ run systemctl daemon-reload && \
410
+ run systemctl enable netdata && \
411
+ return 0
412
+ else
413
+ echo >&2 "file '/etc/systemd/system/netdata.service' already exists."
414
+ return 0
415
+ fi
416
+ else
417
+ install_non_systemd_init
418
+ return $?
419
+ fi
420
+
421
+ return 1
422
+}
netdata-installer.sh
+1
-59
@@ -824,67 +824,9 @@ fi
824
# -----------------------------------------------------------------------------
825
progress "Install netdata at system init"
826
827
-installed_init_d=0
828
-install_non_systemd_init() {
829
- [ "${UID}" != 0 ] && return 1
830
-
831
- local key="unknown"
832
- if [ -f /etc/os-release ]
833
- then
834
- source /etc/os-release || return 1
835
- key="${ID}-${VERSION_ID}"
836
-
837
- elif [ -f /etc/centos-release ]
838
- then
839
- key=$(</etc/centos-release)
840
- fi
841
-
842
- if [ -d /etc/init.d -a ! -f /etc/init.d/netdata ]
843
- then
844
- if [ "${key}" = "gentoo" ]
845
- then
846
- run cp system/netdata-openrc /etc/init.d/netdata && \
847
- run chmod 755 /etc/init.d/netdata && \
848
- run rc-update add netdata default && \
849
- installed_init_d=1
850
-
851
- elif [ "${key}" = "ubuntu-12.04" -o "${key}" = "ubuntu-14.04" -o "${key}" = "debian-7" ]
852
- then
853
- run cp system/netdata-lsb /etc/init.d/netdata && \
854
- run chmod 755 /etc/init.d/netdata && \
855
- run update-rc.d netdata defaults && \
856
- run update-rc.d netdata enable && \
857
- installed_init_d=1
858
-
859
- elif [ "${key}" = "CentOS release 6.8 (Final)" -o "${key}" = "amzn-2016.09" ]
860
- then
861
- run cp system/netdata-init-d /etc/init.d/netdata && \
862
- run chmod 755 /etc/init.d/netdata && \
863
- run chkconfig netdata on && \
864
- installed_init_d=1
865
- fi
866
- fi
867
-
868
- return 0
869
-}
870
-
827
if [ "${UID}" -eq 0 ]
828
then
873
-
874
- if issystemd
875
- then
876
- # systemd is running on this system
877
-
878
- if [ ! -f /etc/systemd/system/netdata.service ]
879
- then
880
- echo >&2 "Installing systemd service..."
881
- run cp system/netdata.service /etc/systemd/system/netdata.service && \
882
- run systemctl daemon-reload && \
883
- run systemctl enable netdata
884
- fi
885
- else
886
- install_non_systemd_init
887
- fi
829
+ install_netdata_service
830
fi
831
832