歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> ubuntu在關機畫面出現前進行網絡連接的關閉的修改

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

日期:2017/3/3 15:54:36   编辑:關於Linux

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 <[email protected]>"

#表示只有當事件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

返回欄目頁:http://www.bianceng.cn/OS/Linux/

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

作者:csdn博客 yygydjkthh

Copyright © Linux教程網 All Rights Reserved