• 如何在Linux中禁用和挂起休眠


      参考:https://www.a5idc.net/helpview_888.html

      Ubuntu在启动以后过一段时间大概20分钟左右会自动休眠,在另外一台主机使用脚本检测80端口可以看到多久休眠

       禁用休眠前查看状态

     systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
    ● sleep.target - Sleep
         Loaded: loaded (/lib/systemd/system/sleep.target; static; vendor preset: enabled)
         Active: inactive (dead)
           Docs: man:systemd.special(7)
    
    8月 24 18:00:40 hdy-desktop systemd[1]: Reached target Sleep.
    8月 24 18:02:50 hdy-desktop systemd[1]: Stopped target Sleep.
    8月 24 18:22:50 hdy-desktop systemd[1]: Reached target Sleep.
    8月 25 08:37:14 hdy-desktop systemd[1]: Stopped target Sleep.
    8月 25 08:57:15 hdy-desktop systemd[1]: Reached target Sleep.
    8月 25 09:03:24 hdy-desktop systemd[1]: Stopped target Sleep.
    8月 25 09:23:25 hdy-desktop systemd[1]: Reached target Sleep.
    8月 25 09:29:05 hdy-desktop systemd[1]: Stopped target Sleep.
    
    ● suspend.target - Suspend
         Loaded: loaded (/lib/systemd/system/suspend.target; static; vendor preset: enabled)
         Active: inactive (dead)
           Docs: man:systemd.special(7)
    
    8月 24 18:02:50 hdy-desktop systemd[1]: Reached target Suspend.
    8月 24 18:02:50 hdy-desktop systemd[1]: Stopped target Suspend.
    8月 25 08:37:14 hdy-desktop systemd[1]: Reached target Suspend.
    8月 25 08:37:14 hdy-desktop systemd[1]: Stopped target Suspend.
    8月 25 09:03:24 hdy-desktop systemd[1]: Reached target Suspend.
    8月 25 09:03:24 hdy-desktop systemd[1]: Stopped target Suspend.
    8月 25 09:29:05 hdy-desktop systemd[1]: Reached target Suspend.
    8月 25 09:29:05 hdy-desktop systemd[1]: Stopped target Suspend.
    
    ● hibernate.target - Hibernate
         Loaded: loaded (/lib/systemd/system/hibernate.target; static; vendor preset: enabled)
         Active: inactive (dead)
           Docs: man:systemd.special(7)
    
    ● hybrid-sleep.target - Hybrid Suspend+Hibernate
         Loaded: loaded (/lib/systemd/system/hybrid-sleep.target; static; vendor preset: enabled)
         Active: inactive (dead)
           Docs: man:systemd.special(7)
    

       禁止休眠

    root@hdy-desktop:~# systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
    Created symlink /etc/systemd/system/sleep.target → /dev/null.
    Created symlink /etc/systemd/system/suspend.target → /dev/null.
    Created symlink /etc/systemd/system/hibernate.target → /dev/null.
    Created symlink /etc/systemd/system/hybrid-sleep.target → /dev/null.
    

       再次查看状态,变成masked了

    root@hdy-desktop:~# systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
    ● sleep.target
         Loaded: masked (Reason: Unit sleep.target is masked.)
         Active: inactive (dead)
    
    8月 24 18:00:40 hdy-desktop systemd[1]: Reached target Sleep.
    8月 24 18:02:50 hdy-desktop systemd[1]: Stopped target Sleep.
    8月 24 18:22:50 hdy-desktop systemd[1]: Reached target Sleep.
    8月 25 08:37:14 hdy-desktop systemd[1]: Stopped target Sleep.
    8月 25 08:57:15 hdy-desktop systemd[1]: Reached target Sleep.
    8月 25 09:03:24 hdy-desktop systemd[1]: Stopped target Sleep.
    8月 25 09:23:25 hdy-desktop systemd[1]: Reached target Sleep.
    8月 25 09:29:05 hdy-desktop systemd[1]: Stopped target Sleep.
    
    ● suspend.target
         Loaded: masked (Reason: Unit suspend.target is masked.)
         Active: inactive (dead)
    
    8月 24 18:02:50 hdy-desktop systemd[1]: Reached target Suspend.
    8月 24 18:02:50 hdy-desktop systemd[1]: Stopped target Suspend.
    8月 25 08:37:14 hdy-desktop systemd[1]: Reached target Suspend.
    8月 25 08:37:14 hdy-desktop systemd[1]: Stopped target Suspend.
    8月 25 09:03:24 hdy-desktop systemd[1]: Reached target Suspend.
    8月 25 09:03:24 hdy-desktop systemd[1]: Stopped target Suspend.
    8月 25 09:29:05 hdy-desktop systemd[1]: Reached target Suspend.
    8月 25 09:29:05 hdy-desktop systemd[1]: Stopped target Suspend.
    
    ● hibernate.target
         Loaded: masked (Reason: Unit hibernate.target is masked.)
         Active: inactive (dead)
    
    ● hybrid-sleep.target
         Loaded: masked (Reason: Unit hybrid-sleep.target is masked.)
         Active: inactive (dead)
    

       重启主机

    reboot
    

       再次查看

    root@hdy-desktop:~# systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
    ● sleep.target
         Loaded: masked (Reason: Unit sleep.target is masked.)
         Active: inactive (dead)
    
    ● suspend.target
         Loaded: masked (Reason: Unit suspend.target is masked.)
         Active: inactive (dead)
    
    ● hibernate.target
         Loaded: masked (Reason: Unit hibernate.target is masked.)
         Active: inactive (dead)
    
    ● hybrid-sleep.target
         Loaded: masked (Reason: Unit hybrid-sleep.target is masked.)
         Active: inactive (dead)
    

       主机不在休眠了

      重新启动休眠

     systemctl unmask sleep.target suspend.target hibernate.target hybrid-sleep.target
    

       注意:改禁止休眠命令Ubuntu和Centos通用

  • 相关阅读:
    Linux学习总结(十一)—— Linux常用命令:版本信息查看(RedHat、CentOS、Debian、Ubuntu、Fedora、Oracle)...
    Linux学习总结(十一)—— Linux常用命令:版本信息查看(RedHat、CentOS、Debian、Ubuntu、Fedora、Oracle)...
    Linux 操作系统原理 — 进程与线程管理
    sed 变量替换
    触类旁通:那些关于 TBL$OR$IDX$PART$NUM 的诡异案例和知识
    python 追加库路径
    python 模块
    生成器
    深入解析:DB2 V10.5新特性列式存储表的优点与缺点
    赚钱项目轻度揭秘:旧手机回收背后的暴利内情
  • 原文地址:https://www.cnblogs.com/minseo/p/13557947.html
Copyright © 2020-2023  润新知