Explain DEBIAN | 您所在的位置:网站首页 › debian_frontend=noninteractive › Explain DEBIAN |
One of debconf’s unique features is that the interface it presents to you is only one of many that can be swapped in at will. There are many debconf frontends available: dialog – The default frontend for apt/apt-get under Debian/Ubuntu Linux. It displays questions to you. It works in text mode over ssh based session. readline – The most traditional frontend, this looks quite similar to how Debian configuration options are: a series of questions, printed out at the console using plain text. Best suited when you are working with slow remote connections and entirely comfortable with Linux command-line options. noninteractive – You use this mode when you need zero interaction while installing or upgrading the system via apt. It accepts the default answer for all questions. It might mail an error message to the root user, but that’s it all. Otherwise, it is totally silent and humble, a perfect frontend for automatic installs. One can use such mode in Dockerfile, shell scripts, cloud-init script, and more. gnome – This is a modern X GUI using the gtk and gnome libraries. kde – Another frontend provides a simple X GUI written with the Qt library. It fits well the KDE desktop. editor – This is for those fanatics who have to do everything in a text editor. It runs your editor on a file that looks something like a typical unix config file, and you edit those files to communicate with debconf. web – This frontend acts as a web server, that you connect to with your web browser, to browse the questions and answer them. Again it is a proof of concept, and one should avoid using web frontend for security reasons. How to use apt DEBIAN_FRONTEND environment variableThe syntax is as follows: $ DEBIAN_FRONTEND={name_here} apt-get install pkg $ DEBIAN_FRONTEND={name_here} apt install pkg $ DEBIAN_FRONTEND=noninteractive apt-get -y update $ DEBIAN_FRONTEND=noninteractive apt-get -y upgrade For longer scripts and other swapping process you may want to export shell variable: $ export DEBIAN_FRONTEND=noninteractive $ apt -y install nginx $ apt-get -y update $ apt-get -y upgrade We can find out if our Ubuntu/Debian Linux server needs a reboot including service restart using the needrestart command. The needrestart checks which daemons need to be restarted after library upgrades. Set the restart mode to automatic: $ NEEDRESTART_MODE=a $ export NEEDRESTART_MODE=a How to apt-get update and upgrade automate and unattendedThe following will force apt-get to work automatic and unattended mode. export NEEDRESTART_MODE=a export DEBIAN_FRONTEND=noninteractive ## Questions that you really, really need to see (or else). ## export DEBIAN_PRIORITY=critical apt-get -qy clean apt-get -qy update apt-get -qy -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" upgradeAnother nice feature of debconf is that the questions it asks you are prioritized. If you don’t want to be bothered about every little thing, you can set up debconf to only ask you the most important questions. Hence, we set DEBIAN_PRIORITY to critical. The -q produces output suitable for logging, omitting progress indicators. AWS EC2/Lightsail VM exampleOne can run script using Linode or AWS or service providers cloud-init system. In other words add a shell script that will run on your instance the first time it launches on AWS Lightsail:
You can write and use a script to configure your VM when it starts up. These scripts can add software, update software, or configure your instance in some other way on Linode:
The following script force apt-get to skip any interactive post-install configuration steps and do other stuff too before we can use Ansible for other stuff: #!/bin/bash ## Tested for AWS only. May need modification and subnet for other cloud hosting providers ## Author: Vivek Gite, under GPL v2.+ {https://www.cyberciti.biz/} ## ------------------------------------------------------------------------------------------ ## admin_IP_1|short_description_1 admin_IP_2|short_description_2 _admin_ip="1.2.3.4|MUM_ADM 3.2.4.5|DEL_IDC 6.7.8.9|VPN_SG_1" ## set server hostname, we can get it from gcp/aws conf too _hostname="server1.cyberciti.biz" ## update system when vm creted via cloud-init ## export DEBIAN_FRONTEND=noninteractive apt-get -y update apt-get -y upgrade ## set hostname ## hostnamectl set-hostname "${_hostname}" ## get security settings ## wget -q -O /etc/sysctl.d/1000-custom.conf https://www.cyberciti.biz/files/1000-custom.conf ## enable firewall ## yes | ufw enable ## open ssh port to our admin ips only ## for e in $_admin_ip do ufw allow from "${e%%|*}" to any port 22 proto tcp comment 'Open SSH port for ${e##*|}' done ## extra rule allow vpc ufw allow from 172.26.0.0/16 to 172.26.0.0/16 proto any comment 'Allow communitcation between AWS VPC peers' ufw allow from 172.31.0.0/16 to 172.26.0.0/16 proto any comment 'Allow communitcation between AWS VPC peers' ## sync and reboot vm ## sync reboot ## Rest config will be done by Ansbile ## ConclusionYou learned how to use DEBIAN_FRONTEND to change the frontend debconf uses temporarily. See debconf and apt-get man pages for more information using the man command or by passing the --help option as follows: $ man 7 debconf $ apt-get --help $ man 8 apt $ man 8 apt-get Did you notice? 🧐 nixCraft is ad-free to protect your privacy and security. We rely on reader support to keep the site running. Please consider subscribing to us on Patreon or supporting us with a one-time support through PayPal or purchase official merchandise. Your support will help us cover the costs of hosting, CDN, DNS, and tutorial creation.Patreon ➔ PayPal ➔ Shop ➔ |
CopyRight 2018-2019 实验室设备网 版权所有 |