Add cache into updatemotd
This commit is contained in:
parent
1bab619392
commit
4559e62189
13
README.md
13
README.md
|
@ -1,5 +1,6 @@
|
||||||
# Dynamic motd
|
# Dynamic motd
|
||||||
|
|
||||||
|
|
||||||
The aim of this project is to give some informations when you log into a server through SSH.
|
The aim of this project is to give some informations when you log into a server through SSH.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
@ -60,15 +61,11 @@ rm /etc/motd
|
||||||
ln -s /var/run/motd /etc/motd
|
ln -s /var/run/motd /etc/motd
|
||||||
```
|
```
|
||||||
|
|
||||||
## Salt
|
This is the for of [ldidry/dynamic-motd](https://github.com/ldidry/dynamic-motd)
|
||||||
|
|
||||||
You will find a working salt formula in `init.sls`.
|
## Diffrence :
|
||||||
|
- Remove salt
|
||||||
```
|
- Add some cache to avoid a connection stuck during 30 secondes
|
||||||
cd /srv/salt
|
|
||||||
git clone https://framagit.org/luc/dynamic-motd.git motd
|
|
||||||
salt your_server state.sls motd
|
|
||||||
```
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
11
cron-scripts/50-services-need-restart
Executable file
11
cron-scripts/50-services-need-restart
Executable file
|
@ -0,0 +1,11 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
. /etc/update-motd.d/colors
|
||||||
|
|
||||||
|
if [[ -x /usr/sbin/checkrestart ]]; then
|
||||||
|
n=$(/usr/sbin/checkrestart -p | grep "Found .* processes using old versions of upgraded files")
|
||||||
|
cat ${n} > /var/cache/motd-service-using-old-lib
|
||||||
|
elif [[ -x /usr/sbin/needrestart ]]; then
|
||||||
|
n=$(/usr/sbin/needrestart -l -v -n -r l 2>/dev/null | grep -c "Skipping")
|
||||||
|
cat ${n} > /var/cache/motd-service-need-restart
|
||||||
|
i
|
8
cron-scripts/motd-need-reboot
Executable file
8
cron-scripts/motd-need-reboot
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
. /etc/update-motd.d/colors
|
||||||
|
|
||||||
|
if [[ -x /usr/sbin/needrestart ]]; then
|
||||||
|
n=$(DEBIAN_FRONTEND=noninteractive echo "" | /usr/sbin/needrestart -k -v -n 2>/dev/null | grep -c "Pending kernel upgrade\!")
|
||||||
|
cat ${n} > /var/cache/motd-needrestart
|
||||||
|
fi
|
6
cron-scripts/motd-need-upgrade
Executable file
6
cron-scripts/motd-need-upgrade
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
n=$(apt-get -qq --just-print dist-upgrade | cut -f 2 -d " " | sort -u | wc -l)
|
||||||
|
cat ${n} > /var/cache/cron-needupgrade
|
||||||
|
n=$(apt-get -qq --just-print autoremove | cut -f 2 -d " " | sort -u | wc -l)
|
||||||
|
cat ${n} > /var/cache/cron-needautoremove
|
37
init.sls
37
init.sls
|
@ -1,37 +0,0 @@
|
||||||
motd-packages:
|
|
||||||
pkg.installed:
|
|
||||||
- pkgs:
|
|
||||||
- figlet
|
|
||||||
- lsb-release
|
|
||||||
- python-utmp
|
|
||||||
- bc
|
|
||||||
- debian-goodies
|
|
||||||
needrestart:
|
|
||||||
pkg.installed:
|
|
||||||
- pkgs:
|
|
||||||
- needrestart
|
|
||||||
symbolic-motd:
|
|
||||||
file.symlink:
|
|
||||||
- name: /etc/motd
|
|
||||||
- target: /var/run/motd
|
|
||||||
- force: True
|
|
||||||
- backupname: bak
|
|
||||||
dynamic-motd:
|
|
||||||
file.recurse:
|
|
||||||
- name: /etc/update-motd.d/
|
|
||||||
- source: salt://motd/update-motd.d/
|
|
||||||
- file_mode: 755
|
|
||||||
# If you installed this motd prior to commit 7bae3d50,
|
|
||||||
# you may want to enable the clean option in order to
|
|
||||||
# remove the old files (01-*, 02-*, etc) since they have
|
|
||||||
# been renumbered. Be careful! If you added some files of
|
|
||||||
# yours, they will be deleted
|
|
||||||
#- clean: True
|
|
||||||
remove-exec-colors:
|
|
||||||
file.managed:
|
|
||||||
- name: /etc/update-motd.d/colors
|
|
||||||
- mode: 644
|
|
||||||
remove-exec-sysinfo:
|
|
||||||
file.managed:
|
|
||||||
- name: /etc/update-motd.d/sysinfo.py
|
|
||||||
- mode: 644
|
|
|
@ -2,13 +2,13 @@
|
||||||
|
|
||||||
. /etc/update-motd.d/colors
|
. /etc/update-motd.d/colors
|
||||||
|
|
||||||
n=$(apt-get -qq --just-print dist-upgrade | cut -f 2 -d " " | sort -u | wc -l)
|
n=$(cat /var/cache/cron-needupgrade)
|
||||||
if [[ $n -gt 0 ]]; then
|
if [[ $n -gt 0 ]]; then
|
||||||
printf $LIGHT_RED
|
printf $LIGHT_RED
|
||||||
printf " You have %s packages waiting for upgrades." "$n"
|
printf " You have %s packages waiting for upgrades." "$n"
|
||||||
printf $NONE"\n\n"
|
printf $NONE"\n\n"
|
||||||
fi
|
fi
|
||||||
n=$(apt-get -qq --just-print autoremove | cut -f 2 -d " " | sort -u | wc -l)
|
n=$(cat /var/cache/cron-needautoremove)
|
||||||
if [[ $n -gt 0 ]]; then
|
if [[ $n -gt 0 ]]; then
|
||||||
printf $YELLOW
|
printf $YELLOW
|
||||||
printf " You have %s packages that were automatically installed and are not needed anymore." "$n"
|
printf " You have %s packages that were automatically installed and are not needed anymore." "$n"
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
. /etc/update-motd.d/colors
|
. /etc/update-motd.d/colors
|
||||||
|
|
||||||
if [[ -x /usr/sbin/needrestart ]]; then
|
if [[ -x /usr/sbin/needrestart ]]; then
|
||||||
n=$(DEBIAN_FRONTEND=noninteractive echo "" | /usr/sbin/needrestart -k -v -n 2>/dev/null | grep -c "Pending kernel upgrade\!")
|
n=$(cat /var/cache/motd-needrestart)
|
||||||
if [[ $n -gt 0 ]]; then
|
if [[ $n -gt 0 ]]; then
|
||||||
printf $LIGHT_RED
|
printf $LIGHT_RED
|
||||||
printf " Pending kernel upgrade! "
|
printf " Pending kernel upgrade! "
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
. /etc/update-motd.d/colors
|
. /etc/update-motd.d/colors
|
||||||
|
|
||||||
if [[ -x /usr/sbin/checkrestart ]]; then
|
if [[ -x /usr/sbin/checkrestart ]]; then
|
||||||
n=$(/usr/sbin/checkrestart -p | grep "Found .* processes using old versions of upgraded files")
|
n=$(cat /var/cache/motd-service-using-old-lib)
|
||||||
re='Found (.*) processes using old versions of upgraded files'
|
re='Found (.*) processes using old versions of upgraded files'
|
||||||
if [[ $n =~ $re ]]; then
|
if [[ $n =~ $re ]]; then
|
||||||
if [[ ${BASH_REMATCH[1]} -gt 0 ]]; then
|
if [[ ${BASH_REMATCH[1]} -gt 0 ]]; then
|
||||||
|
@ -14,7 +14,7 @@ if [[ -x /usr/sbin/checkrestart ]]; then
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
elif [[ -x /usr/sbin/needrestart ]]; then
|
elif [[ -x /usr/sbin/needrestart ]]; then
|
||||||
n=$(/usr/sbin/needrestart -l -v -n -r l 2>/dev/null | grep -c "Skipping")
|
n=$(cat /var/cache/motd-service-need-restart)
|
||||||
if [[ $n -gt 0 ]]; then
|
if [[ $n -gt 0 ]]; then
|
||||||
printf $LIGHT_RED
|
printf $LIGHT_RED
|
||||||
printf " %s services need to be restarted.\n" $n
|
printf " %s services need to be restarted.\n" $n
|
||||||
|
|
Loading…
Reference in a new issue