我已经在朋友的PC上安装了(x)Ubuntu 14.04。自动更新设置为“下载并自动安装更新”。
问题在于,使用了几个月后,他在不知不觉中关闭了PC,直到软件包升级完成。这会导致依赖项/程序包损坏,从而导致更新受到影响以及需要运行sudo dpkg --configure -a
是否有可能让Ubuntu像Windows一样在PC关闭或重新启动之前等待更新完成,以确保不会出现损坏的软件包并且他的PC保持自动更新?
我已经在朋友的PC上安装了(x)Ubuntu 14.04。自动更新设置为“下载并自动安装更新”。
问题在于,使用了几个月后,他在不知不觉中关闭了PC,直到软件包升级完成。这会导致依赖项/程序包损坏,从而导致更新受到影响以及需要运行sudo dpkg --configure -a
是否有可能让Ubuntu像Windows一样在PC关闭或重新启动之前等待更新完成,以确保不会出现损坏的软件包并且他的PC保持自动更新?
Answers:
Molly-Guard正是为此目的而设计的程序。它需要您进行少量设置,并且需要/usr/sbin
先 /sbin
进行准备$PATH
。
否则,根据此确切的细节在很大程度上取决于GUI / DE的实现。由于我们知道您的朋友使用的是Xubuntu,因此可以缩小它的范围,但是如果不使用内置的支持重新编译Xfce(这会造成更多问题),这似乎很难。
根据我的丰富研究,从理论上讲,您可以只替换/sbin/shutdown
一个脚本,该脚本检查apt作业是否启动并执行,sudo shutdown -c
或者sudo init 2
取消正在运行的关闭并wait
退出,但我不确定这样做是否可靠。
根据这个,你可能只是使其难以被用户,而不是挂钩的脚本关机。
最后,概述了在这里,你可以安装unattended-upgrades
在您使用的是自动更新的,现在什么系统,并关闭之前确保其退出作为在这个答案详细说明。
有很多选择,所有这些选择在不同程度上都是不可靠的,但是我认为最好的方法可以解决我认为在某种程度上是潜在的X / Y问题,这是:
crontab
使他的计算机运行dpkg --configure -a
每次启动。@LovesTha:为您的目的,我建议您unattended-upgrades
,或者也许是Molly-Guard。
下面的脚本对来自dbus的特定消息使用中断驱动的轮询,并且每当看到关闭/重新启动的请求时,它将测试软件包管理器(例如dpkg
或)apt
是否正在运行。如果它们正在运行,则关闭请求将被取消。
由于您已经提到您的朋友不想触摸命令行,因此您将需要SSH进入他的计算机,或者过来手动安装它。
mkdir $HOME/bin
preventShutdown.sh
chmod +x $HOME/bin/preventShutdown.sh
要做到这一点.desktop
文件放入$HOME/.config/autostart
sudo apt-get install git
cd /opt
sudo git clone https://github.com/SergKolo/sergrep.git
sudo chmod +x /opt/sergrep/*
将脚本添加为启动应用程序。
#! /bin/bash
##########################
# AUTHOR: Serg Kolo
# Date: Saturday, December 26th, 2015
# Description: Script to notify user and prevent
# shutdown or reboot
# if any update or package manager
# are running.
# TESTED ON: 14.04.3 LTS, Trusty Tahr
# WRITTEN FOR: http://askubuntu.com/q/702156/295286
# VERSION: 2, removed xdotool, using dbus method
# changed to C-style of organizing code
#########################
# Copyright (c) 2015 Serg Kolo
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Uncomment the line bellow if needed for debugging
# set -x
###########################
# VARIABLES
###########################
DISPLAY=:0 # has to be set since we are using notify-send
###########################
# MAIN
###########################
#
# Basic idea : This runs dbus-monitor which waits for
# "RebootRequested" memberf from com.canonical.Unity.Session ,
# which apprears only when the user clicks the shutdown option
# from the Unity's top right drop down box. Why RebootRequested ?
# Because this message is guaranteed to pop up once user presses
# the shutdown button.
# The while loop with read command does the big job.
# dbus-monitor sends initial message , so we want to filter only
# The output that contains the string we need, hence the case...esac
# structure employed here. Once we get the proper message.
# we check whether update-manager or package managers are running
# If there is one instance, then call CancelAction method
# and send notification to the user.
# Both dbus-monitor and while loop run continuously. This
# can be launcher as script in `/etc/rc.local` or `/etc/rc2.d`
# or preferably (!) in `/etc/xdg/autostart/` .
# Here is sample /etc/xdg/autostart/preventShutdown.desktop file
#
# [Desktop Entry]
# Type=Application
# Name=Prevent-Update
# Exec=/home/$USER/bin/preventShutdown.sh
# OnlyShowIn=GNOME;Unity;
# Terminal=false
#
# Remember to make this file as well as script be root-owned with
# chmod +x /path/to/Script.
# It is preferred to store the script in user's personal $HOME/bin
# folder.
# Make sure to edit $HOME/.profile file to include that into $PATH
# variable
interupt()
{
qdbus com.canonical.Unity /com/canonical/Unity/Session com.canonical.Unity.Session.CancelAction
notify-send "<<< UPDATE IN PROGRESS; DO NOT SHUT DOWN>>>"
wall <<< "<<< UPDATE IN PROGRESS; DO NOT SHUT DOWN>>>"
}
main()
{
dbus-monitor --profile "interface='com.canonical.Unity.Session',type=signal" |
while read -r line;
do
case "$line" in
*RebootRequested*)
pgrep update-manager || pgrep apt-get || pgrep dpkg
if [ $? -eq 0 ]; then
interupt
fi
;;
esac
done
}
main
引用爱因斯坦的话:
Only two things are infinite, the universe and human stupidity,
and I'm not sure about the former.
因此,对于人的愚蠢没有100%的保证,但是您可以通过以下方法使非爱因斯坦更难以打破事物:
说明计算机不是锤子,也不是钉子,而是易碎的智能设备,需要两种食物:电力和更新。
或者:
•使用Remmina使物料平稳运行
System Settings -> Power