Add a script to prepare a container to becoming a debian template

This commit is contained in:
Jeremy Gardais 2018-02-13 13:58:04 +01:00
parent dd83740f16
commit 8d8527d4e2
2 changed files with 94 additions and 3 deletions

View File

@ -18,18 +18,44 @@ Some usefull scripts for admin or users.
### Proxmox
#### vzdump-hook-lxc-template.pl
#### proxmox.template.debian.sh
Some commands in order to clean and prepare a container to become a template.
1. The script will:
* Allow root's connection to SSH with password.
* Reconfigure timezone to **Europe/Paris**.
* Reconfigure locales to **en_US.UTF-8**.
* Download an additionnal script use by our preseed with PXE to configure logs (rsyslog, logrotate,…).
* Remove **x11** useless packages.
* Clean some stuff (downloaded packages, empty logs,…).
2. How-to use:
``` sh
wget https://git.ipr.univ-rennes1.fr/cellinfo/scripts/raw/master/proxmox/proxmox.template.debian.sh -O /tmp/proxmox.template.debian.sh
chmod +x /tmp/proxmox.template.debian.sh
/tmp/proxmox.template.debian.sh
```
#### vzdump-hook-lxc-stretch-template.pl
This script must be used as a vzdump's hook (the backup utility for CT and VMs for Proxmox).
1. The script will:
* Remove the templates oldest than 2 days (by default).
* Copy the current dump as a template in **/mnt/zfsbkp/template/cache** (by default).
* Unlink **$TEMPLATE_FILE_LINK**.
* Link **$TEMPLATE_FILE_LINK** to the last dump in order to have a better name.
* Remove the templates oldest than 2 days (by default).
2. How-to use:
* Define a backup as usual (in the Proxmox's webgui) and prefer to select only one container.
* In command on the hypervisor, open **/etc/pve/vzdump.cron** and edit the line of the new dump to add: **--script /usr/local/bin/vzdump-hook-lxc-template.pl**.
* In command on the hypervisor, open **/etc/pve/vzdump.cron** and edit the line of the new dump to add: **--script /usr/local/bin/vzdump-hook-lxc-stretch-template.pl**.
3. Customization:
* If you don't store template in the default path (**/mnt/zfsbkp/template/cache**), please edit the variable **$TEMPLATE_DIR** in the script.
* You might want to set another template name, please edit the variable **$TEMPLATE_FILE_LINK** in the script.
#### vzdump-hook-lxc-jessie-template.pl
Same as above but set jessie in **$TEMPLATE_FILE_LINK**.
### Grav

View File

@ -0,0 +1,65 @@
#!/bin/sh
#
# Some commands to apply to generate a "good" custom Debian (Stretch) template
# SSH {{{
# allow root connection with a password
/bin/sed -i 's/\(^\|^\#\)\(PermitRootLogin\).*/\2 yes/g' /etc/ssh/sshd_config ;
systemctl restart sshd
# or download admin ssh pubkey
# }}}
# time {{{
# set timezone
echo "Europe/Paris" > /etc/timezone
rm -f -- /etc/localtime
dpkg-reconfigure -f noninteractive tzdata
# }}}
# manage locale {{{
NEW_L="en_US.UTF-8"
sed -i -e "s/# \(${NEW_L} UTF-8\)/\1/" /etc/locale.gen
locale-gen
echo "LANG=\"${NEW_L}\"" > /etc/default/locale
dpkg-reconfigure -f noninteractive locales
update-locale LANG="${NEW_L}"
# }}}
# download an additionnal script to manage rsyslog and logrotate {{{
wget https://git.ipr.univ-rennes1.fr/cellinfo/tftpboot/raw/master/scripts/latecommand.tar.gz -O /tmp/latecommand.tar.gz
tar xzf /tmp/latecommand.tar.gz -C /tmp/
/bin/sh /tmp/latecommand/post.sh
# }}}
# APT {{{
# ensure to remove useless x11 packages
aptitude remove -y x11-common libgl1-mesa-glx xauth libx11-6 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxft2 libxi6 libxinerama1 libxkbfile1 libxmuu1 libxpm4 libxrandr2 libxrender1 libxv1 libxxf86dga1 libxxf86vm1 libx11-data
# clean useless rc files
aptitude -y purge '~c'
# clean downloaded and list of packages
aptitude clean
rm -f /var/cache/apt/*.bin
# }}}
# clean the system {{{
true > /etc/resolv.conf
find /var/log -type f -iname "*.log" -delete -exec touch {} \;
find /var/log -type f \( -iname "*.gz" -o -iname ".*.0" -o -iname "dmesg.*" \) -delete
rm -f -- /root/.bash_history
# }}}
exit 0