diff --git a/Extras/init/longview b/Extras/init/longview index 8259829..1dc29c0 100755 --- a/Extras/init/longview +++ b/Extras/init/longview @@ -1,45 +1,70 @@ -#!/bin/bash +#!/bin/sh -SUCCESS="\E[32;40mSuccess\E[0m" -FAILED="\E[31;40mFailed\E[0m" +### BEGIN INIT INFO +# Provides: longview +# Required-Start: $network $local_fs +# Required-Stop: $network $local_fs +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: Longview Monitoring Agent +### END INIT INFO -LV="/opt/linode/longview/Linode/Longview.pl" +set -e + +umask 022 + +DAEMON="/opt/linode/longview/Linode/Longview.pl" +PID="/var/run/longview.pid" +. /lib/lsb/init-functions case "$1" in start) - echo -n $"Starting longview: " - $LV - RET=$? - [ $RET -eq 0 ] && echo -e $SUCCESS || echo -e $FAILED - exit $RET - ;; + log_daemon_msg "Starting Longview Agent" "longview" + if start-stop-daemon --start -p $PID --startas $DAEMON 2>/dev/null; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; debug) - echo -n $"Starting longview (With Debug Flag): " - $LV Debug - RET=$? - [ $RET -eq 0 ] && echo -e $SUCCESS || echo -e $FAILED - exit $RET - ;; + log_daemon_msg "Starting Longview Agent (With Debug Flag)" "longview" + if start-stop-daemon --start -p $PID --startas $DAEMON Debug 2>/dev/null; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; stop) - echo -n $"Stopping longview: " - kill `cat /var/run/longview.pid` 2>/dev/null - RET=$? - [ $RET -eq 0 ] && echo -e $SUCCESS || echo -e $FAILED - exit $RET - ;; + log_daemon_msg "Stopping Longview Agent" "longview" + if start-stop-daemon --stop --quiet -p $PID 2>/dev/null; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; restart) - $0 stop - $0 start - ;; + log_daemon_msg "Restarting Longview Agent" "longview" + start-stop-daemon --stop --quiet --oknodo --retry 30 -p /var/run/longview.pid + if start-stop-daemon --start -p $PID --startas $DAEMON 2>/dev/null; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; + reload|force-reload) + log_daemon_msg "Restarting Longview Agent" "longview" + if start-stop-daemon --stop --quiet --oknodo --signal HUP -p /var/run/longview.pid; then + log_end_msg 0 + else + log_end_msg 1 + fi + ;; status) - [ ! -e /var/run/longview.pid ] && echo "No longview pid file: status unknown" && exit 1 - PID=`cat /var/run/longview.pid` - grep "linode-longview" "/proc/$PID/cmdline" 2>/dev/null - RET=$? - [ $RET -eq 0 ] && echo "Longview is running" || echo "Longview is not running" - exit $RET - ;; + status_of_proc -p $PID $DAEMON longview && exit 0 || exit $? + ;; *) - echo $"Usage: $0 {start|stop|restart|status}" - ;; -esac \ No newline at end of file + log_action_msg "Usage: /etc/init.d/longview {start|stop|restart|force-reload|reload|status}" + exit 1 +esac + +exit 0 \ No newline at end of file diff --git a/Extras/init/longview.centos.sh b/Extras/init/longview.centos.sh new file mode 100644 index 0000000..c184c3b --- /dev/null +++ b/Extras/init/longview.centos.sh @@ -0,0 +1,46 @@ +#!/bin/bash +#chkconfig: 2345 50 10 +#description: Longview statistics gathering +#processname: linode-longview + +LVDAEMON="/opt/linode/longview/Linode/Longview.pl" + +. /etc/rc.d/init.d/functions + +case "$1" in + start) + echo -n "Starting longview: " + $LVDAEMON + RET=$? + [ $RET -eq 0 ] && success || failure + echo + exit $RET + ;; + debug) + echo -n "Starting longview (With Debug Flag): " + $LVDAEMON Debug + RET=$? + [ $RET -eq 0 ] && success || failure + echo + exit $RET + ;; + stop) + echo -n "Stopping longview: " + kill `cat /var/run/longview.pid` 2>/dev/null + RET=$? + [ $RET -eq 0 ] && success || failure + [ $RET -eq 0 ] && rm /var/run/longview.pid + echo + exit $RET + ;; + restart) + $0 stop + $0 start + ;; + status) + status -p /var/run/longview.pid longview + ;; + *) + echo $"Usage: $0 {start|stop|restart|status}" + ;; +esac \ No newline at end of file diff --git a/Extras/init/longview.generic.sh b/Extras/init/longview.generic.sh new file mode 100755 index 0000000..8259829 --- /dev/null +++ b/Extras/init/longview.generic.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +SUCCESS="\E[32;40mSuccess\E[0m" +FAILED="\E[31;40mFailed\E[0m" + +LV="/opt/linode/longview/Linode/Longview.pl" + +case "$1" in + start) + echo -n $"Starting longview: " + $LV + RET=$? + [ $RET -eq 0 ] && echo -e $SUCCESS || echo -e $FAILED + exit $RET + ;; + debug) + echo -n $"Starting longview (With Debug Flag): " + $LV Debug + RET=$? + [ $RET -eq 0 ] && echo -e $SUCCESS || echo -e $FAILED + exit $RET + ;; + stop) + echo -n $"Stopping longview: " + kill `cat /var/run/longview.pid` 2>/dev/null + RET=$? + [ $RET -eq 0 ] && echo -e $SUCCESS || echo -e $FAILED + exit $RET + ;; + restart) + $0 stop + $0 start + ;; + status) + [ ! -e /var/run/longview.pid ] && echo "No longview pid file: status unknown" && exit 1 + PID=`cat /var/run/longview.pid` + grep "linode-longview" "/proc/$PID/cmdline" 2>/dev/null + RET=$? + [ $RET -eq 0 ] && echo "Longview is running" || echo "Longview is not running" + exit $RET + ;; + *) + echo $"Usage: $0 {start|stop|restart|status}" + ;; +esac \ No newline at end of file diff --git a/Extras/specs/centos-longview.spec b/Extras/specs/centos-longview.spec new file mode 100644 index 0000000..1c43a9a --- /dev/null +++ b/Extras/specs/centos-longview.spec @@ -0,0 +1,82 @@ +Name: linode-longview +Version: 1.1 +Release: 3 +Summary: Linode Longview Agent +License: GPLv2+ +BuildArch: noarch + +Requires: perl(Crypt::SSLeay),perl(DBD::mysql) +Obsoletes: longview + +%description +The Linode Longview data collection agent + +%prep +http_fetch() { + mkdir -p `dirname $2` + if command -v wget >/dev/null 2>&1; then + wget -q -4 -O $2 $1 || { + echo >&2 "Failed to fetch $1. Aborting install."; + exit 1; + } + elif command -v curl >/dev/null 2>&1; then + curl -sf4L $1 > $2 || { + echo >&2 "Failed to fetch $1. Aborting install."; + exit 1; + } + else + echo "Unable to find curl or wget, can not fetch needed files" + exit 1 + fi +} +[ -e $OLDPWD/Extras/lib/perl5/Linux/Distribution.pm ] || http_fetch http://cpansearch.perl.org/src/CHORNY/Linux-Distribution-0.21/lib/Linux/Distribution.pm $OLDPWD/Extras/lib/perl5/Linux/Distribution.pm +[ -e $OLDPWD/Extras/lib/perl5/Try/Tiny.pm ] || http_fetch http://cpansearch.perl.org/src/DOY/Try-Tiny-0.18/lib/Try/Tiny.pm $OLDPWD/Extras/lib/perl5/Try/Tiny.pm + +%install +rm -rf %{buildroot} +mkdir -p %{buildroot}/opt/linode/longview/lib/perl5/ +mkdir -p %{buildroot}/opt/linode/longview/Linode/Longview/DataGetter/Packages/ +mkdir -p %{buildroot}/opt/linode/longview/Extras/ +mkdir -p %{buildroot}/etc/init.d/ +mkdir -p %{buildroot}/etc/linode/longview.d +cp $OLDPWD/Extras/init/longview.centos.sh %{buildroot}/etc/init.d/longview +cp -r $OLDPWD/Extras/lib/perl5/* %{buildroot}/opt/linode/longview/lib/perl5/ +cp -r $OLDPWD/Linode %{buildroot}/opt/linode/longview/ +cp $OLDPWD/Extras/Modules/Packages/YUM.pm %{buildroot}/opt/linode/longview/Linode/Longview/DataGetter/Packages/YUM.pm +cp $OLDPWD/Extras/app-report.pl %{buildroot}/opt/linode/longview/Extras/app-report.pl +cp $OLDPWD/Extras/conf/* %{buildroot}/etc/linode/longview.d/ + +%files +/etc/init.d/longview +/opt/linode/longview/lib/perl5/Linux/Distribution.pm +/opt/linode/longview/lib/perl5/Try/Tiny.pm +/opt/linode/longview/Linode/Longview.pl +/opt/linode/longview/Linode/Longview/*.pm +/opt/linode/longview/Linode/Longview/DataGetter/*.pm +/opt/linode/longview/Linode/Longview/DataGetter/Applications/*.pm +/opt/linode/longview/Linode/Longview/DataGetter/Packages/YUM.pm +%config %attr(640,root,root) /etc/linode/longview.d/*.conf +/opt/linode/longview/Extras/app-report.pl + +%post +if [ $1 -eq 1 ] ; then + # Initial installation + service longview start || : + chkconfig --add longview + chkconfig --level 35 longview on +fi +chmod -R o-rwx /etc/linode/longview.d/ + +%preun +if [ $1 -eq 0 ] ; then + # Package removal, not upgrade + service longview stop || : + chkconfig --del longview +fi + +%postun +/bin/systemctl daemon-reload >/dev/null 2>&1 || : +if [ $1 -ge 1 ] ; then + # Package upgrade, not uninstall + service longview restart || : +fi diff --git a/Extras/specs/fedora-longview.spec b/Extras/specs/fedora-longview.spec new file mode 100644 index 0000000..b1abf21 --- /dev/null +++ b/Extras/specs/fedora-longview.spec @@ -0,0 +1,87 @@ +Name: linode-longview +Version: 1.1 +Release: 3 +Summary: Linode Longview Agent +License: GPLv2+ +BuildArch: noarch +Source: https://github.com/linode/longview/archive/v%{version}.%{release}.tar.gz + +Requires: perl-LWP-Protocol-https,perl-DBD-MySQL + +BuildRequires: systemd-units +Requires(post): systemd-units +Requires(preun): systemd-units +Requires(postun): systemd-units + +%description +The Linode Longview data collection agent + +%prep +http_fetch() { + mkdir -p `dirname $2` + if command -v wget >/dev/null 2>&1; then + wget -q -4 -O $2 $1 || { + echo >&2 "Failed to fetch $1. Aborting install."; + exit 1; + } + elif command -v curl >/dev/null 2>&1; then + curl -sf4L $1 > $2 || { + echo >&2 "Failed to fetch $1. Aborting install."; + exit 1; + } + else + echo "Unable to find curl or wget, can not fetch needed files" + exit 1 + fi +} +[ -e $OLDPWD/Extras/lib/perl5/Linux/Distribution.pm ] || http_fetch http://cpansearch.perl.org/src/CHORNY/Linux-Distribution-0.21/lib/Linux/Distribution.pm $OLDPWD/Extras/lib/perl5/Linux/Distribution.pm +[ -e $OLDPWD/Extras/lib/perl5/Try/Tiny.pm ] || http_fetch http://cpansearch.perl.org/src/DOY/Try-Tiny-0.18/lib/Try/Tiny.pm $OLDPWD/Extras/lib/perl5/Try/Tiny.pm + + +%install +echo $OLDPWD +rm -rf %{buildroot} +mkdir -p %{buildroot}/opt/linode/longview/lib/perl5/ +mkdir -p %{buildroot}%{_unitdir} +mkdir -p %{buildroot}/etc/linode/longview.d +mkdir -p %{buildroot}/opt/linode/longview/Linode/Longview/DataGetter/Packages +mkdir -p %{buildroot}/opt/linode/longview/Extras/ +cp $OLDPWD/Extras/init/longview.service %{buildroot}%{_unitdir}/longview.service +cp -r $OLDPWD/Extras/lib/perl5/* %{buildroot}/opt/linode/longview/lib/perl5/ +cp -r $OLDPWD/Linode %{buildroot}/opt/linode/longview/ +cp $OLDPWD/Extras/app-report.pl %{buildroot}/opt/linode/longview/Extras/app-report.pl +cp $OLDPWD/Extras/Modules/Packages/YUM.pm %{buildroot}/opt/linode/longview/Linode/Longview/DataGetter/Packages/YUM.pm +cp $OLDPWD/Extras/conf/* %{buildroot}/etc/linode/longview.d/ + +%files +%{_unitdir}/longview.service +/opt/linode/longview/lib/perl5/Linux/Distribution.pm +/opt/linode/longview/lib/perl5/Try/Tiny.pm +/opt/linode/longview/Linode/Longview.pl +/opt/linode/longview/Linode/Longview/*.pm +/opt/linode/longview/Linode/Longview/DataGetter/*.pm +/opt/linode/longview/Linode/Longview/DataGetter/Applications/*.pm +/opt/linode/longview/Linode/Longview/DataGetter/Packages/YUM.pm +%config %attr(640,root,root) /etc/linode/longview.d/*.conf +/opt/linode/longview/Extras/app-report.pl + +%post +if [ $1 -eq 1 ] ; then + # Initial installation + /bin/systemctl daemon-reload >/dev/null 2>&1 || : + /bin/systemctl enable longview.service >/dev/null 2>&1 || : +fi + +%preun +if [ $1 -eq 0 ] ; then + # Package removal, not upgrade + /bin/systemctl --no-reload disable longview.service > /dev/null 2>&1 || : + /bin/systemctl stop longview.service > /dev/null 2>&1 || : +fi + +%postun +/bin/systemctl daemon-reload >/dev/null 2>&1 || : +if [ $1 -ge 1 ] ; then + # Package upgrade, not uninstall + /bin/systemctl try-restart longview.service >/dev/null 2>&1 || : +fi diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..7619371 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,100 @@ +linode-longview (1.1.3) stable; urgency=low + + * Match the longname of a process more accurately + * Added diagnostic tool for Application module configuration + + -- Peter Sandin Mon, 06 Jan 2014 17:06:16 +0000 + +linode-longview (1.1.2) stable; urgency=low + + * Better checks for applications when invoked with fully qualified paths + * Better handling of sector size for physical disks + * Improved backwards compatibility for allowing certificate errors on local host with older LWP + * Various bug fixes + + -- Peter Sandin Fri, 22 Nov 2013 17:27:12 -0500 + +linode-longview (1.1.1) stable; urgency=low + + * Support HTTPS for web server status pages + * Increase log verbosity + * Various bug fixes + + -- Peter Sandin Tue, 12 Nov 2013 17:37:01 -0500 + +linode-longview (1.1.0.3) stable; urgency=low + + * Fix flags on update-rc.d when purging + + -- Peter Sandin Tue, 05 Nov 2013 14:36:29 -0500 + +linode-longview (1.1.0.2) stable; urgency=low + + * Removed bashism from Nginx rollback + + -- Peter Sandin Tue, 05 Nov 2013 12:44:58 -0500 + +linode-longview (1.1.0.1) stable; urgency=low + + [ Stan Schwertly ] + * Pure perl implementation of timeout in MySQL check + + -- Peter Sandin Mon, 04 Nov 2013 14:12:09 -0500 + +linode-longview (1.1.0) stable; urgency=low + + * Support for automatically loading modules under the DataGetter package + * New modules for gathering MySQL, Apache, and Nginx specific statistics + + -- Peter Sandin Mon, 04 Nov 2013 12:03:52 -0500 + +linode-longview (1.0.1) stable; urgency=low + + * Collect disk usage in both operations per second and bytes per second + * Fix typo in export for Util.pm + * Fix parent disks sometimes inheriting the properties of their children + + -- Peter Sandin Tue, 01 Oct 2013 08:22:59 -0400 + +linode-longview (1.0.0) stable; urgency=low + + * Identify system architecture/integer size better + * Improve processor model detection + + -- Peter Sandin Wed, 04 Sep 2013 23:29:13 -0400 + +linode-longview (0.2.7) stable; urgency=low + + * Check for package updates more efficiently by checking the modified times on package cache files + * Longview now identifies itself even when /proc/pid/status shows its name as perl + * Longview now uses paths relative to Longview.pl to locate modules and dependancies + * Perl 5.8 compatibility + + -- Peter Sandin Wed, 28 Aug 2013 17:05:04 -0400 + +linode-longview (0.2.6.1) stable; urgency=low + + * Fix control data for Log::LogLite + + -- Peter Sandin Thu, 22 Aug 2013 16:17:02 -0400 + +linode-longview (0.2.6) stable; urgency=low + + * Improved handling of falling back to IPv4 when IPv6 is unavailable + * Fixed runtime addition of api keys + * Performance improvements in port monitoring for high traffic systems + * Replaced Log::Log4Perl with Log::LogLite + * LVM disks now consistently name keys for IO and FS statistics + + -- Peter Sandin Thu, 22 Aug 2013 16:01:43 -0400 + +linode-longview (0.2.5) stable; urgency=low + + * 2nd beta release. + * Escape dots in mount point and device paths + * Remove Linux::APT dependancy + * Fix IPv6 address formatting in ports listing + * Try to avoid locking conflicts when checking for package updates + * Fix regex for rx and tx bytes under networking + + -- Peter Sandin Thu, 27 Jun 2013 16:00:13 -0400 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..d991f76 --- /dev/null +++ b/debian/control @@ -0,0 +1,14 @@ +Source: linode-longview +Section: utils +Priority: optional +Maintainer: Linode Longview Team +Build-Depends: debhelper (>= 8.0.0) +Standards-Version: 3.9.3 +Homepage: https://www.linode.com/longview/ + +Package: linode-longview +Architecture: all +Depends: libjson-perl, libwww-perl, libcrypt-ssleay-perl | liblwp-protocol-https-perl, libio-socket-ssl-perl, libio-socket-inet6-perl, liblog-loglite-perl, libtry-tiny-perl, libdbi-perl,liblinux-distribution-perl, ${misc:Depends}, ${perl:Depends} +Description: Longview Monitoring Agent + This agent collects various system wide statistics and + post them to the Longview collection endpoint. diff --git a/debian/copyright b/debian/copyright new file mode 100644 index 0000000..6231231 --- /dev/null +++ b/debian/copyright @@ -0,0 +1,39 @@ +Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ +Upstream-Name: linode-longview +Source: https://github.com/linode + +Files: * +Copyright: 2013 Linode, LLC +License: GPL-2.0/Perl Artistic License + +Files: debian/* +Copyright: 2013 Linode, LLC +License: GPL-2.0/Perl Artistic License + +License: GPL-2.0/Perl Artistic License +Copyright 2013 Linode, LLC. Longview is made available under the terms +of the Perl Artistic License, or GPLv2 at the recipients discretion. + +Perl Artistic License + +Read it at: http://dev.perl.org/licenses/artistic.html + +GNU General Public License (GPL) Version 2 + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see http://www.gnu.org/licenses/ + +On Debian GNU/Linux systems, the complete text of the GNU General +Public License can be found in `/usr/share/common-licenses/GPL-2'. + +See the full license at http://www.gnu.org/licenses/ diff --git a/debian/linode-longview.conffiles b/debian/linode-longview.conffiles new file mode 100644 index 0000000..e69de29 diff --git a/debian/linode-longview.config b/debian/linode-longview.config new file mode 100755 index 0000000..ec980f6 --- /dev/null +++ b/debian/linode-longview.config @@ -0,0 +1,211 @@ +#!/bin/sh +set -e + +longview_config_dir='/etc/linode/longview.d/' + +echoerr() { echo "$@" 1>&2; } + +_fake_curl() { + _input_url=$1 + PERL_LWP_SSL_VERIFY_HOSTNAME=0 perl -MLWP::UserAgent -e '$ua=LWP::UserAgent->new(); print $ua->get("$ARGV[0]")->decoded_content;' "$1" + return 0 +} + +_check_apache_url() { + _apache_url=$1 + _fake_curl "$_apache_url" | grep -q 'Scoreboard:' + return $? +} + +_check_nginx_url() { + _nginx_url=$1 + _fake_curl "$_nginx_url" | grep -q 'server accepts handled requests' + return $? +} + +_mysql_check_install() { + _mysql_username=$1 + _mysql_password=$2 + perl -MDBI -e "eval { local \$SIG{ALRM} = sub { die; }; alarm(5); \$dbh = DBI->connect('DBI:mysql:host=localhost', '$_mysql_username', '$_mysql_password'); exit \$DBI::err; alarm(0); }; exit 1 if \$@" + return $? +} + +apache_status_path() { + echoerr "Checking Apache configuration..." + + apache_config_filename=${longview_config_dir}Apache.conf + apache_default_url='http://127.0.0.1/server-status?auto' + apache_default_https='https://127.0.0.1/server-status?auto' + apache_url=$(grep '^location' $apache_config_filename | tail -n1 | awk '{print $2}') + + # use the url if it exists + if [ ! -z $apache_url ]; then + if _check_apache_url $apache_url ; then + echoerr "Found Apache status page at $apache_url specified in $apache_config_filename" + db_set Longivew/apache-location "" + return 0 + elif [ "$apache_url" = "$apache_default_url" ]; then + echoerr "Attempt to access $apache_url specified in $apache_config_filename failed..." + else + echoerr "Attempt to access $apache_url specified in $apache_config_filename failed...trying default" + if _check_apache_url $apache_default_url; then + echoerr "Found Apache status page at $apache_default_url (default URL)" + db_set Longivew/apache-location "$apache_default_url" + return 0; + elif _check_apache_url $apache_default_https; then + echoerr "Found Apache status page at $apache_default_https" + db_set Longivew/apache-location "$apache_default_https" + return 0; + fi + fi + else + if _check_apache_url $apache_default_url; then + echoerr "Found Apache status page at $apache_default_url (default URL)" + db_set Longivew/apache-location "$apache_default_url" + return 0; + elif _check_apache_url $apache_default_https; then + echoerr "Found Apache status page at $apache_default_https" + db_set Longivew/apache-location "$apache_default_https" + return 0; + fi + fi + + # really ghetto url extraction + guess_url=$(grep '^ */dev/null | head -n1 | sed 's/>$//' | awk '{print $2}') + if [ ! -z $guess_url ]; then + if _check_apache_url http://127.0.0.1$guess_url?auto; then + echoerr "Found Apache status page at http://127.0.0.1$guess_url?auto" + db_set Longivew/apache-location "http://127.0.0.1$guess_url?auto" + return 0 + fi + fi + + db_set Longivew/apache-location "$apache_default_url" + db_fset Longview/apache-try-configure seen "false" + db_input high Longview/apache-try-configure +} + +nginx_status_path(){ + echoerr "Checking Nginx configuration..." + + nginx_config_filename=${longview_config_dir}Nginx.conf + nginx_default_url='http://127.0.0.1/nginx_status' + nginx_default_https='https://127.0.0.1/nginx_status' + nginx_url=$(grep '^location' $nginx_config_filename 2>/dev/null | tail -n1 | awk '{print $2}') + + # use the url if it exists + if [ ! -z $nginx_url ]; then + if _check_nginx_url $nginx_url; then + echoerr "Found nginx status page at $nginx_url specified in $nginx_config_filename" + db_set Longivew/nginx-location "" + return 0 + elif [ "$nginx_url" = "$nginx_default_url" ]; then + echoerr "Attempt to access $nginx_url specified in $nginx_config_filename failed..." + else + echoerr "Attempt to access $nginx_url specified in $nginx_config_filename failed...trying default" + if _check_nginx_url $nginx_default_url; then + echoerr "Found nginx status page at $nginx_default_url (default URL)" + db_set Longivew/nginx-location "" + return 0; + elif _check_nginx_url $nginx_default_https; then + echoerr "Found nginx status page at $nginx_default_https" + db_set Longivew/nginx-location "$nginx_default_https" + return 0; + fi + fi + fi + + if _check_nginx_url $nginx_default_url; then + echoerr "Found nginx status page at $nginx_default_url (default URL)" + db_set Longivew/nginx-location "" + return 0; + elif _check_nginx_url $nginx_default_https; then + echoerr "Found nginx status page at $nginx_default_https" + db_set Longivew/nginx-location "$nginx_default_https" + return 0; + fi + + # don't be smart unless we know where to work + if [ ! -d /etc/nginx/sites-enabled ]; then + echoerr "Unable to automatically configure nginx for Longview. Please see https://library.linode.com/longview/longview-for-nginx#sph_manual-configuration-all-distributions" + db_set Longivew/nginx-location "" + return 0 + fi + + # this is kind of weird + # check to make sure that the haxor mode is gonna work + if grep -ri '^[[:space:]]*server_name.*127\.0\.0\.2' /etc/nginx/sites-enabled; then + echoerr "Unable to automatically configure nginx for Longview. Please see https://library.linode.com/longview/longview-for-nginx#sph_manual-configuration-all-distributions" + db_set Longivew/nginx-location "" + return 0 + fi + + if [ -e /etc/nginx/sites-available/longview ]; then + if _check_nginx_url http://127.0.0.2/nginx_status; then + echoerr "Found location configured by Longview previously." + db_set Longivew/nginx-location "http://127.0.0.2/nginx_status" + return 0 + fi + echoerr "Unable to automatically configure nginx for Longview. Please see https://library.linode.com/longview/longview-for-nginx#sph_manual-configuration-all-distributions" + db_set Longivew/nginx-location "" + return 0 + fi + db_input high Longview/nginx-try-configure || true +} + +mysql_cred_check() { + echoerr "Checking MySQL configuration..." + + mysql_config_filename=${longview_config_dir}MySQL.conf + mysql_username=$(grep '^username' $mysql_config_filename 2>/dev/null | tail -n1 | awk '{print $2}') + mysql_password=$(grep '^password' $mysql_config_filename 2>/dev/null | tail -n1 | awk '{print $2}') + + if [ ! -z $mysql_username ] && [ ! -z $mysql_password ]; then + if _mysql_check_install $mysql_username $mysql_password; then + echoerr "Successfully connected to MySQL with the credentials located in $mysql_config_filename" + db_set Longivew/mysql-password "" + return 0 + else + echoerr "Unable to connect using the credentials specified in $mysql_config_filename...trying Debian maintenance user" + fi + fi + + if [ -e /etc/mysql/debian.cnf ]; then + mysql_password=$(egrep '^\s*password\s*=\s*' /etc/mysql/debian.cnf | head -n1 | sed 's/^\s*password\s*=\s*//') + if _mysql_check_install debian-sys-maint $mysql_password; then + echoerr "Successfully connected to MySQL" + db_set Longivew/mysql-password "" + if [ ! -z $mysql_username ] && [ ! -z $mysql_password ]; then + db_subst Longview/mysql-overwrite-creds found_user "$mysql_username" + db_input high Longview/mysql-overwrite-creds || true + fi + return 0 + fi + fi + + mysql_username='linode-longview' + mysql_password=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c32) + + create_statement="CREATE USER 'linode-longview'@'localhost' IDENTIFIED BY '$mysql_password';" + + db_set Longivew/mysql-password "$mysql_password" + db_subst Longview/mysql-create-creds create_statement "$create_statement" + db_input high Longview/mysql-create-creds || true +} + +. /usr/share/debconf/confmodule +db_input medium Longview/APIKey || true + +if pgrep -f 'httpd|apache2' >/dev/null; then + apache_status_path +fi + +if pgrep -f 'nginx' >/dev/null; then + nginx_status_path +fi + +if pgrep -f 'mysqld' >/dev/null; then + mysql_cred_check +fi + +db_go || true diff --git a/debian/linode-longview.install b/debian/linode-longview.install new file mode 100644 index 0000000..49eeaf6 --- /dev/null +++ b/debian/linode-longview.install @@ -0,0 +1,5 @@ +Linode/* opt/linode/longview/Linode/ +Extras/app-report.pl opt/linode/longview/Extras/ +Extras/Modules/Packages/APT.pm opt/linode/longview/Linode/Longview/DataGetter/Packages/ +Extras/init/longview etc/init.d +Extras/conf/* etc/linode/longview.d/ diff --git a/debian/linode-longview.postinst b/debian/linode-longview.postinst new file mode 100755 index 0000000..ba5802b --- /dev/null +++ b/debian/linode-longview.postinst @@ -0,0 +1,192 @@ +#!/bin/sh +set -e + +longview_config_dir='/etc/linode/longview.d/' + +echoerr() { echo "$@" 1>&2; } + +_fake_curl() { + _input_url=$1 + PERL_LWP_SSL_VERIFY_HOSTNAME=0 perl -MLWP::UserAgent -e '$ua=LWP::UserAgent->new(); print $ua->get("$ARGV[0]")->decoded_content;' "$1" + return 0 +} + +_check_apache_url() { + _apache_url=$1 + _fake_curl "$_apache_url" | grep -q 'Scoreboard:' + return $? +} + +_check_nginx_url() { + _nginx_url=$1 + _fake_curl "$_nginx_url" | grep -q 'server accepts handled requests' + return $? +} + +_write_option(){ + _write_file=$1 + _checked_directive=$2 + _value=$3 + if egrep "^\s*$_checked_directive[[:space:]]+\S+" $_write_file >/dev/null; then + sed -i "s|^\s*$_checked_directive.*|$_checked_directive $_value|g" $_write_file + else + if ! tail -c1 $_write_file | grep '^$' >/dev/null; then + echo "" >> $_write_file + fi + echo "$_checked_directive $_value" >> $_write_file + fi +} + +apache_install() { + apache_config_filename=${longview_config_dir}Apache.conf + + db_get Longivew/apache-location + location="$RET" + + if [ ! -z "$location" ]; then + _write_option $apache_config_filename location "$location" + apache_url="$location" + else + apache_url='http://127.0.0.1/server-status?auto' + fi + + db_fset Longview/apache-try-configure seen "false" + db_get Longview/apache-try-configure + if [ "$RET" != "true" ]; then + return 0 + fi + db_set Longview/apache-try-configure "false" + + # check for mod_status + if [ ! -e /etc/apache2/mods-enabled/status.conf ]; then + if ! a2enmod status; then + echoerr "Unable to enable mod_status for Apache. Please see https://library.linode.com/longview/longview-for-apache#sph_manual-configuration-all-distributions for instructions on configuring Apache to work with Longview" + return 1 + fi + else + pre_existing_status="true" + fi + + cat >> /etc/apache2/mods-enabled/status.conf < +ExtendedStatus On + + SetHandler server-status + Order deny,allow + Deny from all + Allow from 127.0.0.1 + + +END + + apache_url_https=`echo $apache_url | sed 's/^http/https/'` + if /etc/init.d/apache2 reload; then + if _check_apache_url $apache_url; then + _write_option $apache_config_filename location "$apache_url" + echoerr "Apache mod_status enabled" + return 0 + elif _check_apache_url $apache_url_https; then + _write_option $apache_config_filename location "$apache_url_https" + return 0; + fi + fi + + echoerr "Enabling mod_status for Apache failed. Rolling back changes" + if [ -z "$pre_existing_status" ]; then + a2dismod status + fi + head -n -9 /etc/apache2/mods-available/status.conf | tee /etc/apache2/mods-available/status.conf > /dev/null + /etc/init.d/apache2 reload + echoerr "Please see https://library.linode.com/longview/longview-for-apache#sph_manual-configuration-all-distributions for instructions on configuring Apache to work with Longview. Auto-configuration failed" +} + +nginx_install() { + nginx_config_filename=${longview_config_dir}Nginx.conf + + db_get Longivew/nginx-location + location="$RET" + + if [ ! -z "$location" ]; then + _write_option $nginx_config_filename location "$location" + return 0 + fi + + db_fset Longview/nginx-try-configure seen "false" + db_get Longview/nginx-try-configure + if [ "$RET" != "true" ]; then + return 0 + fi + db_set Longview/nginx-try-configure "false" + + cat >> /etc/nginx/sites-available/longview < /etc/linode/longview.key +fi + +apache_install +nginx_install +mysql_install +chmod -R o-rwx $longview_config_dir +db_stop + +if invoke-rc.d longview status 1>/dev/null 2>&1; then + invoke-rc.d longview restart || true +else + invoke-rc.d longview start || true +fi + +update-rc.d longview defaults diff --git a/debian/linode-longview.postrm b/debian/linode-longview.postrm new file mode 100755 index 0000000..3f9d88d --- /dev/null +++ b/debian/linode-longview.postrm @@ -0,0 +1,16 @@ +#!/bin/sh +set -e + +if [ "$1" = "purge" ]; then + . /usr/share/debconf/confmodule + db_purge + db_stop +fi + +if [ "$1" = "upgrade" ]; then + exit 0 +fi + +if [ "$1" = "remove" -o "$1" = "purge" ]; then + update-rc.d -f longview remove +fi \ No newline at end of file diff --git a/debian/linode-longview.prerm b/debian/linode-longview.prerm new file mode 100755 index 0000000..a4b54c2 --- /dev/null +++ b/debian/linode-longview.prerm @@ -0,0 +1,3 @@ +#!/bin/sh +set -e +invoke-rc.d longview stop || true diff --git a/debian/linode-longview.templates b/debian/linode-longview.templates new file mode 100644 index 0000000..fb6943a --- /dev/null +++ b/debian/linode-longview.templates @@ -0,0 +1,58 @@ +Template: Longview/APIKey +Type: string +Default: +Description: Please enter your Longview API Key: + Please enter your Longview API Key. + +Template: Longivew/apache-location +Type: string +Default: +Description: Mod_Status URL: + Not really for human consumption. + +Template: Longview/apache-try-configure +Type: boolean +Default: +Description: Autoconfigure Mod_Status: + Longview has detected Apache running on this server but was unable to access + the server status page. Would you like to attempt to automatically configure + mod_status? This will require reloading Apache to enable. + +Template: Longivew/nginx-location +Type: string +Default: +Description: Nginx Status URL: + Not really for human consumption. + +Template: Longview/nginx-try-configure +Type: boolean +Default: +Description: Autoconfigure status page: + Longview has detected Nginx running on this server but was unable to access + the server status page. Would you like to attempt to automatically configure + the Nginx status module? This will require restarting Nginx to enable. + +Template: Longview/mysql-create-creds +Type: note +Default: +Description: Unable to automatically configure MySQL plugin: + Longview has detected MySQL running on this server but was unable to + automatically configure the connection. To allow Longview to access your + MySQL instance please run the following queries: + ${create_statement} + FLUSH PRIVILEGES; + +Template: Longview/mysql-overwrite-creds +Type: boolean +Default: +Description: Overwrite existing Longview MySQL config: + Longview has detected MySQL running on this server but was unable to + log in with the provided credentials for the '${found_user}' user. However a + 'debian-sys-maint' user was found, would you like to configure longview to + use those credentials instead? + +Template: Longivew/mysql-password +Type: string +Default: +Description: Longview Mysql user password: + Not really for human consumption. diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..1dccbee --- /dev/null +++ b/debian/rules @@ -0,0 +1,26 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. +# +# Modified to make a template file for a multi-binary package with separated +# build-arch and build-indep targets by Bill Allombert 2001 + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +# This has to be exported to make some magic below work. +export DH_OPTIONS + +override_dh_auto_build: + +override_dh_auto_install: + +override_dh_pysupport: + +%: + dh $@ diff --git a/debian/source/format b/debian/source/format new file mode 100644 index 0000000..89ae9db --- /dev/null +++ b/debian/source/format @@ -0,0 +1 @@ +3.0 (native)