ubuntu在關機畫面出現前進行網路連接的關閉的修改

來源:互聯網
上載者:User

/********************************************************************* * Author  : Samson * Date    : 05/07/2014 * Test platform: *              Mint 15-3.8.13.13 *              GNU bash, version 4.2.45 * *******************************************************************/
mdm.conf 介面關閉服務配置


# mdm - MDM Display Manager
#
# The display manager service manages the X servers running on the
# system, providing login and auto-login services

description     "MDM Display Manager"
author          "Linux Mint <root@linuxmint.com>"

#表示只有當事件filesystem被啟用且(運行在不是關機和重啟的運行層級的時候)且(dbus服務已經啟動)且(card0已經添加或udev-fallback-graphics服務已經關閉)時,此服務啟動
start on ((filesystem
           and runlevel [!06]
           and started dbus
           and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
                or stopped udev-fallback-graphics))
          or runlevel PREVLEVEL=S)

#表示當系統運行在關機、單使用者、重啟的狀態下時,關閉此服務
stop on runlevel [016]

#以下是註冊3個事件到upstart事件驅動中
emits login-session-start
emits desktop-session-start
emits desktop-shutdown

#以下為進行服務啟動後的處理過程
script
    if [ -n "$UPSTART_EVENTS" ]
    then
        # Check kernel command-line for inhibitors, unless we are being called
        # manually
        for ARG in $(cat /proc/cmdline); do
            if [ "$ARG" = "text" ]; then
            #plymouth為開機、關機畫面程式
                  plymouth quit || :
                          stop
                  exit 0
            fi
        done

        if [ -f /etc/X11/default-display-manager ]; then
            [ "$(cat /etc/X11/default-display-manager 2>/dev/null)" = "/usr/sbin/mdm" ] || { stop; exit 0; }
        else
            type lightdm >/dev/null 2>&1 && { stop; exit 0; } || true
        fi

        if [ "$RUNLEVEL" = S -o "$RUNLEVEL" = 1 ]
        then
            # Single-user mode
            plymouth quit || :
            exit 0
        fi
    fi
    //測試各種環境指令碼是否存在並載入環境變數
    test -f /etc/profile && . /etc/profile

    if [ -r /etc/default/locale ]; then
        . /etc/default/locale
        export LANG LANGUAGE LC_MESSAGES LC_ALL
    elif [ -r /etc/environment ]; then
        . /etc/environment
        export LANG LANGUAGE LC_MESSAGES LC_ALL
    fi    
    
    exec mdm
end script
#以下為停止此服務後需要進行的處理
post-stop script
    if [ "$UPSTART_STOP_EVENTS" = runlevel ]; then
        #得到當前網路連接(可能存在多個),依次關閉
        netlinklist=`less /proc/net/if_inet6 | grep -v lo | grep -v vmnet | awk '{print $6}'`
        echo "netlist is $netlinklist" >> /home/xxx/shutdownlog1
        for node in $netlinklist
        do
            echo "node is $node" >> /home/xxx/shutdownlog2
            /sbin/ifconfig $node down
        done
        #啟用desktop-shutdown事件,會觸發關機畫面,注意下面的plymouth.conf設定檔中的desktop-shutdown所在位置
        initctl emit desktop-shutdown
    fi
end script


關機畫面配置指令碼:
# plymouth - Userspace bootsplash utility
#
# plymouth provides a boot splash screen on the system console using
# the kernel framebuffer device.  On boot, this is nominally started by
# the initramfs so the pre-start script, script and post-start script
# parts are actually not run.  These are normally run on shutdown instead.

description     "userspace bootsplash utility"

start on (starting mountall
          or (runlevel [016]
              and (desktop-shutdown
                   or stopped xdm
                   or stopped uxlaunch)))

#此任務調用fork成為一個進程進行處理
expect fork
#upstart對此服務最多等待60秒,超過則進行kill此進程
kill timeout 60

script
    if [ "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" -o "$RUNLEVEL" = "6" ]; then
    #若是關機、重啟、單使用者運行狀態下,執行關機畫面
        exec /sbin/plymouthd --mode=shutdown
    else
    #執行開機畫面
        exec /sbin/plymouthd --mode=boot --attach-to-session
    fi
end script

#當服務啟動後,執行以下指令碼
post-start script
    if [ "$RUNLEVEL" = "0" -o "$RUNLEVEL" = "1" -o "$RUNLEVEL" = "6" ]; then
    #執行關機動畫
        exec /bin/plymouth show-splash
    fi
end script

#pre-stop exec /bin/plymouth quit
pre-stop script
     exec /bin/plymouth quit
end script


參考資料:

http://upstart.ubuntu.com/cookbook/#footer

http://upstart.ubuntu.com/


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.