在后台自动更新完成之前阻止Ubuntu关闭

所以有一种情况我在朋友的PC上安装了(x)Ubuntu 14.04。 自动更新设置为“下载和自动安装更新”。

问题是经过几个月的使用后,它会在软件包升级完成之前关闭他的电脑。 这导致破坏的依赖/包(不记得确切的消息),这导致不再内核,应用程序和浏览器更新。 要解决此问题,您需要运行终端命令sudo dpkg –configure -a

多数民众赞成对我而言,但他的情况是爱因斯坦的相对论

是否有可能让Ubuntu等待更新完成PC关机或重启之前像Windows一样确保永远不会有破坏的软件包,同时他的电脑会自动更新?

Molly-Guard是一个正是为了这个目的的计划; 它需要你进行少量的设置,并在你的$PATH /usr/sbin 之前/usr/sbin

否则,根据这一点 ,确切的细节高度依赖于GUI / DE的实现。 既然我们知道你的朋友正在使用Xubuntu,这会缩小它,但是如果没有使用内置的支持重新编译Xfce(这会产生更多问题),这似乎很难。

根据我丰富的研究,你理论上可以用一个脚本来替换/sbin/shutdown ,该脚本检查apt作业是否已启动并执行sudo shutdown -csudo init 2来取消正在运行的shutdown并wait它退出,但是我我不确定这是多么强大。

根据这个 ,你可能只是让用户很难关闭,而不是挂钩脚本。

最后,如此处所述,您可以在现在用于自动更新的任何系统上安装unattended-upgrades ,并确保在关闭之前退出,如本答案中所述 。


有很多选择,所有这些都是不同程度的不可靠的,但我认为最好的选择,在某种程度上解决了认为在这里发生的潜在X / Y问题 ,是:

使用crontab让他的计算机在每次启动时运行dpkg --configure -a

@LovesTha:出于您的目的,我建议unattended-upgrades ,或者推荐Molly-Guard。

介绍

下面的脚本使用针对来自dbus的特定消息的中断驱动轮询,每当它看到关闭/重启请求时,它将测试包管理器(如dpkgapt是否正在运行。 如果它们正在运行,则将取消关闭请求。

建立

由于您已经提到您的朋友不想触摸命令行,您将需要ssh到他的机器,或者过来手动安装它。

手动设置

  1. mkdir $HOME/bin
  2. 复制脚本源,保存到名为preventShutdown.sh文件中
  3. 该脚本必须是可执行的。 使用chmod +x $HOME/bin/preventShutdown.sh来做到这一点
  4. 使用启动应用程序应用程序或手动将.desktop文件放入$HOME/.config/autostart将脚本添加到要在Unity / Gnome上登录时运行的例程列表

替代设置

 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 
  1. 引用爱因斯坦:

     Only two things are infinite, the universe and human stupidity, and I'm not sure about the former. 

    所以对人类的愚蠢没有100%的保证,但你可以让非爱因斯坦更难以通过以下方式解决问题:

  2. 关闭时激活自动更新 。

  3. 说明计算机不是锤子,也不是指甲,而是脆弱的智能设备,需要两种食物: 电和更新。

或者,

  1. 完全停止自动更新,然后更频繁地访问您的朋友,并自己安装更新。
  2. 要求啤酒或美食来“调整”电脑

或者:
•使用Remmina保持物品顺利运行