Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo F committed Jan 2, 2021
2 parents 8b75eb9 + 18f9538 commit 170dc65
Show file tree
Hide file tree
Showing 26 changed files with 897 additions and 545 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG
@@ -1,3 +1,10 @@
tuptime (5.0.2) unstable; urgency=low

* Option --decp usable but deprecated
* Using subprocess module on BSDs

-- Ricardo Fraile <rfraile@rfraile.eu> Sat, 02 Jan 2021 09:01:00 +0100

tuptime (5.0.1) unstable; urgency=low

* Identify new startups with boot_id on FreeBSD
Expand Down
34 changes: 17 additions & 17 deletions README.md
Expand Up @@ -8,35 +8,35 @@ Tuptime is a tool for report the historical and statistical real time of the sys

Just after install:

System startups: 1 since 21:54:09 24/09/15
System shutdowns: 0 ok + 0 bad
System life: 21m 30s
System startups: 1 since 21:54:09 24/09/15
System shutdowns: 0 ok + 0 bad
System life: 21m 30s

System uptime: 100.0% = 21m 30s
System downtime: 0.0% = 0s
System uptime: 100.0% = 21m 30s
System downtime: 0.0% = 0s

Average uptime: 21m 30s
Average downtime: 0s
Average uptime: 21m 30s
Average downtime: 0s

Current uptime: 21m 30s since 21:54:09 24/09/15
Current uptime: 21m 30s since 21:54:09 24/09/15

A few days later:

System startups: 110 since 10:15:27 08/08/15
System shutdowns: 107 ok + 2 bad
System life: 47d 12h 2m 15s
System startups: 110 since 10:15:27 08/08/15
System shutdowns: 107 ok + 2 bad
System life: 47d 12h 2m 15s

System uptime: 4.04% = 1d 22h 4m 44s
System downtime: 95.96% = 45d 13h 57m 30s
System uptime: 4.04% = 1d 22h 4m 44s
System downtime: 95.96% = 45d 13h 57m 30s

Average uptime: 25m 8s
Average downtime: 9h 56m 42s
Average uptime: 25m 8s
Average downtime: 9h 56m 42s

Current uptime: 23m 33s since 21:54:09 24/09/15
Current uptime: 23m 33s since 21:54:09 24/09/15

Swich to -t | --table option:

No. Startup Date Uptime Shutdown Date End Downtime
No. Startup T. Uptime Shutdown T. End Downtime
1 10:15:27 08/08/15 42s 10:16:09 08/08/15 OK 16s
2 10:16:26 08/08/15 49s 10:17:15 08/08/15 OK 16s
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
@@ -1,3 +1,10 @@
tuptime (5.0.2) unstable; urgency=low

* Option --decp usable but deprecated
* Using subprocess module on BSDs

-- Ricardo Fraile <rfraile@rfraile.eu> Sat, 02 Jan 2021 09:01:00 +0100

tuptime (5.0.1) unstable; urgency=low

* Identify new startups with boot_id on FreeBSD
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Expand Up @@ -4,7 +4,7 @@ Priority: optional
Maintainer: Ricardo Fraile <rfraile@rfraile.eu>
Build-Depends: debhelper-compat (= 13)
Rules-Requires-Root: no
Standards-Version: 4.5.0
Standards-Version: 4.5.1
Homepage: https://github.com/rfrail3/tuptime

Package: tuptime
Expand Down
76 changes: 38 additions & 38 deletions debian/postinst
Expand Up @@ -6,53 +6,53 @@
set -e

# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
configure)

# Rename to underscore if previous exists
getent passwd tuptime >/dev/null && usermod -l _tuptime tuptime
getent group tuptime > /dev/null && groupmod -n _tuptime tuptime

# Create user if not exists
if ! getent passwd _tuptime >/dev/null ; then
echo "Adding _tuptime user..."
adduser --quiet --system --group --disabled-password \
--home "/var/lib/tuptime" \
--shell '/usr/sbin/nologin' \
--gecos 'Tuptime execution user,,,' \
--force-badname _tuptime
fi

# Ensure right ownership
if [ -d /var/lib/tuptime ]; then
chown _tuptime:_tuptime /var/lib/tuptime
if [ -f /var/lib/tuptime/tuptime.db ]; then
chown _tuptime:_tuptime /var/lib/tuptime/tuptime.db
configure)

# Rename to underscore if previous exists
getent passwd tuptime >/dev/null && usermod -l _tuptime tuptime
getent group tuptime > /dev/null && groupmod -n _tuptime tuptime

# Create user if not exists
if ! getent passwd _tuptime >/dev/null ; then
echo "Adding _tuptime user..."
adduser --quiet --system --group --disabled-password \
--home "/var/lib/tuptime" \
--shell '/usr/sbin/nologin' \
--gecos 'Tuptime execution user,,,' \
--force-badname _tuptime
fi
fi

su -s /bin/sh _tuptime -c "tuptime -x"
;;
# Ensure right ownership
if [ -d /var/lib/tuptime ]; then
chown _tuptime:_tuptime /var/lib/tuptime
if [ -f /var/lib/tuptime/tuptime.db ]; then
chown _tuptime:_tuptime /var/lib/tuptime/tuptime.db
fi
fi

su -s /bin/sh _tuptime -c "tuptime -x"
;;

abort-upgrade|abort-remove|abort-deconfigure)
;;
abort-upgrade|abort-remove|abort-deconfigure)
;;

*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
Expand Down
42 changes: 21 additions & 21 deletions debian/postrm
Expand Up @@ -6,32 +6,32 @@
set -e

# summary of how this script can be called:
# * <postrm> `remove'
# * <postrm> `purge'
# * <old-postrm> `upgrade' <new-version>
# * <new-postrm> `failed-upgrade' <old-version>
# * <new-postrm> `abort-install'
# * <new-postrm> `abort-install' <old-version>
# * <new-postrm> `abort-upgrade' <old-version>
# * <disappearer's-postrm> `disappear' <overwriter>
# <overwriter-version>
# * <postrm> `remove'
# * <postrm> `purge'
# * <old-postrm> `upgrade' <new-version>
# * <new-postrm> `failed-upgrade' <old-version>
# * <new-postrm> `abort-install'
# * <new-postrm> `abort-install' <old-version>
# * <new-postrm> `abort-upgrade' <old-version>
# * <disappearer's-postrm> `disappear' <overwriter>
# <overwriter-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
purge|disappear)
rm -rf /var/lib/tuptime/
deluser _tuptime || true
;;

remove|upgrade|failed-upgrade|abort-install|abort-upgrade)
;;

*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
purge|disappear)
rm -rf /var/lib/tuptime/
deluser _tuptime || true
;;

remove|upgrade|failed-upgrade|abort-install|abort-upgrade)
;;

*)
echo "postrm called with unknown argument \`$1'" >&2
exit 1
;;
esac

# dh_installdeb will replace this with shell code automatically
Expand Down
6 changes: 3 additions & 3 deletions misc/rpm/rpm-readme.txt
Expand Up @@ -40,9 +40,9 @@
Z.- For testing with "dev" branch. Install "git" on step "1" and replace step "2" with the following:

cd ~
git clone -b dev --depth=1 https://github.com/rfrail3/tuptime.git tuptime-5.0.1
git clone -b dev --depth=1 https://github.com/rfrail3/tuptime.git tuptime-5.0.2
rpmdev-setuptree
cd ~/rpmbuild/SPECS/
cp ../../tuptime-5.0.1/misc/rpm/tuptime.spec .
tar -czvf ../SOURCES/5.0.1.tar.gz ../../tuptime-5.0.1
cp ../../tuptime-5.0.2/misc/rpm/tuptime.spec .
tar -czvf ../SOURCES/5.0.2.tar.gz ../../tuptime-5.0.2
rpmbuild -ba --target=noarch tuptime.spec
4 changes: 2 additions & 2 deletions misc/rpm/tuptime.spec
@@ -1,5 +1,5 @@
Name: tuptime
Version: 5.0.1
Version: 5.0.2
Release: 1%{?dist}
Summary: Report historical system real time

Expand Down Expand Up @@ -90,5 +90,5 @@ su -s /bin/sh _tuptime -c "(umask 0022 && /usr/bin/tuptime -x)"


%changelog
* Sat Oct 31 2020 Ricardo Fraile <rfraile@rfraile.eu> 5.0.1-1
* Sat Jan 02 2021 Ricardo Fraile <rfraile@rfraile.eu> 5.0.2-1
- RPM release
14 changes: 10 additions & 4 deletions misc/scripts/README.txt
Expand Up @@ -11,7 +11,7 @@ tuptime_join.py

tuptime_modify.py
Modify registers keeping nearest values in sycn.
Allow change 'end status', 'startup date' and 'shutdown date'.
Allow change 'end status', 'startup timestamp' and 'shutdown timestamp'.



Expand All @@ -38,6 +38,12 @@ db-tuptime-migrate-4.0-to-5.0.sh

____Plots____

tuptime-barchart.py
Graph a plot with all hours per state inside each day from tuptime
csv output. Playground script.
tuptime-plot1.py
Graph a plot with the number of hours (default) or events (-x swich)
per state along each day. It gets the info from tuptime csv output.
Playground script.

tuptime-plot2.py
Graph a plot with the state events per hour along each day (default)
or accumulated events per hour (-x swich). It gets the info from
tuptime csv output. Playground script.
24 changes: 11 additions & 13 deletions misc/scripts/db-tuptime-migrate-2.0-to-3.0.sh
Expand Up @@ -4,37 +4,37 @@
# This script update the tuptime database format from versions previous 3.0.00

# Change the db origin:
# uptime real, btime integer, shutdown integer
# uptime real, btime integer, shutdown integer
# to:
# btime integer, uptime real, offbtime integer, endst integer, downtime real
# btime integer, uptime real, offbtime integer, endst integer, downtime real

SOURCE_DB='/var/lib/tuptime/tuptime.db'

# Check bash execution
if [ ! -n "$BASH" ]; then
echo "--- WARNING - execute only with BASH ---"
echo "--- WARNING - execute only with BASH ---"
fi

# Test file permissions
if [ -w "${SOURCE_DB}" ]; then
echo "Migrating tuptime database format"
echo "Migrating tuptime database format"
else
echo "Please, execute this script with a privileged user that can write in: ${SOURCE_DB}"
exit 1
echo "Please, execute this script with a privileged user that can write in: ${SOURCE_DB}"
exit 1
fi

# Test sqlite3 command
sqlite3 -version > /dev/null
if [ $? -ne 0 ]; then
echo "Please, install \"sqlite3\" command for manage sqlite v3 databases"
exit 2
exit 2
fi

# Test bc command
bc -version > /dev/null
if [ $? -ne 0 ]; then
echo "Please, install \"bc\" command"
exit 2
echo "Please, install \"bc\" command"
exit 2
fi

TMP_DB=$(mktemp) # For temporary process db
Expand All @@ -45,7 +45,7 @@ cp "${SOURCE_DB}" "${TMP_DB}"
sqlite3 "${TMP_DB}" "PRAGMA table_info(tuptime);" | grep -E 'end_state|downtime|offbtime' > /dev/null
if [ $? -eq 0 ]; then
echo "Database is already in new format"
exit 3
exit 3
fi

# Change shutdown column to end_state
Expand All @@ -60,14 +60,13 @@ ROWS=$(sqlite3 "${TMP_DB}" "select max(oid) from tuptime;")
for I in $(seq 1 "${ROWS}"); do
UPTIME=$(sqlite3 "${TMP_DB}" "SELECT uptime from tuptime where oid = ${I};")
BTIME=$(sqlite3 "${TMP_DB}" "SELECT btime from tuptime where oid = ${I};")
Z=$((I+1))
Z=$((I+1))
NEXT_BTIME=$(sqlite3 "${TMP_DB}" "SELECT btime from tuptime where oid = ${Z};")

OFFBTIME=$(echo "${UPTIME}" + "${BTIME}" | bc)
DOWNBTIME=$(echo "${NEXT_BTIME}" - "${OFFBTIME}" | bc)

sqlite3 "${TMP_DB}" "UPDATE tuptime SET downtime = ${DOWNBTIME}, offbtime = ${OFFBTIME} where oid = ${I}"

done

# Clear last row shutdown values
Expand All @@ -94,4 +93,3 @@ rm -f "${TMP_DB}"

echo "Backup file in: ${SOURCE_DB}.back"
echo "Process completed OK"

0 comments on commit 170dc65

Please sign in to comment.