Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537 Warning: error_log(/data/www/wwwroot/hmttv.cn/caches/error_log.php): failed to open stream: Permission denied in /data/www/wwwroot/hmttv.cn/phpcms/libs/functions/global.func.php on line 537
時(shí)候因?yàn)楣ぷ餍枰覀儠?huì)對(duì)電腦設(shè)置定時(shí)關(guān)機(jī)的操作。很多小伙伴可能還不知道如何設(shè)置,這里就和大家分享一下Win10電腦如何定時(shí)關(guān)機(jī)吧。
更多系統(tǒng)教程盡在小白系統(tǒng)重裝官網(wǎng)
http://www.958358.com/it/63182.html
系統(tǒng):win10專業(yè)版
電腦:聯(lián)想IdeaPad 710S-13ISK-IFI
1、首先通過(guò)win+r的快捷鍵打開(kāi)運(yùn)行窗口,或者我們也可以直接在搜索欄里搜索運(yùn)行。
2、然后在窗口中輸入以下命令“shutdown -s -t ”,在t后面輸入想要定時(shí)關(guān)機(jī)的時(shí)間,這里必須要用秒為單位的時(shí)間,比如想要一分鐘后關(guān)機(jī),那么就輸入“shutdown -s -t 60”,一小時(shí)的畫(huà)就是“shutdown -s -t3600”
3、在輸入好命令之后,點(diǎn)擊確定或者直接按回車(chē),然后電腦右下角就會(huì)彈出定時(shí)關(guān)機(jī)的提示了。
4、如果我們需要固定一個(gè)時(shí)間點(diǎn)來(lái)關(guān)機(jī)的話,那么需要輸入at 時(shí)間 shutdown -s的命令,假如你想要在晚上十點(diǎn)關(guān)機(jī),那么就輸入at 22:00 shutdown -s。
5、這種關(guān)機(jī)方法電腦就不會(huì)有彈窗提示了,如果你突然不想關(guān)機(jī)了,那么就再次打開(kāi)運(yùn)行窗口,在運(yùn)行窗口里輸入shutdown -a,接著就能看到桌面提示定時(shí)關(guān)機(jī)已取消的彈窗了。
秋日生活打卡季#
原文鏈接:統(tǒng)信UOS1060設(shè)置自動(dòng)關(guān)機(jī)01
hello,大家好啊,今天給大家介紹一篇如何在統(tǒng)信UOS 1060上實(shí)現(xiàn)自動(dòng)關(guān)機(jī)的文章,本篇文章采用兩種方式,第一種使用的是crontab定時(shí)任務(wù)的方式,第二種是使用at命令的方式,兩種方式供您選擇。
方法一:使用crontab定時(shí)任務(wù)
1、編輯crontab文件,設(shè)置每天14:09關(guān)機(jī)
uos@uos-PC:~/Desktop$ sudo -i
請(qǐng)輸入密碼:
驗(yàn)證成功
root@uos-PC:~# crontab -e
no crontab for root - using an empty one
Select an editor. To change later, run 'select-editor'.
1. /bin/nano <---- easiest
2. /usr/bin/vim.basic
3. /usr/bin/vim.tiny
Choose 1-3 [1]: 2
crontab: installing new crontab
root@uos-PC:~#
root@uos-PC:~# crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
09 14 * * * /sbin/poweroff
root@uos-PC:~#
2、等到14:09設(shè)備關(guān)機(jī)
方法二:使用at命令來(lái)設(shè)置一次性的關(guān)機(jī)任務(wù)
1、安裝at命令
uos@uos-PC:~/Desktop$ sudo apt install at -y
請(qǐng)輸入密碼:
驗(yàn)證成功
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹(shù)
正在讀取狀態(tài)信息... 完成
將會(huì)同時(shí)安裝下列軟件:
exim4-base exim4-config exim4-daemon-light guile-2.2-libs libfl2 libgsasl7 libkyotocabinet16v5
libmailutils5 libntlm0 mailutils mailutils-common
建議安裝:
exim4-doc-html | exim4-doc-info eximon4 spf-tools-perl swaks mailutils-mh mailutils-doc
下列【新】軟件包將被安裝:
at exim4-base exim4-config exim4-daemon-light guile-2.2-libs libfl2 libgsasl7 libkyotocabinet16v5
libmailutils5 libntlm0 mailutils mailutils-common
升級(jí)了 0 個(gè)軟件包,新安裝了 12 個(gè)軟件包,要卸載 0 個(gè)軟件包,有 116 個(gè)軟件包未被升級(jí)。
需要下載 9,660 kB 的歸檔。
解壓縮后會(huì)消耗 56.2 MB 的額外空間。
獲取:1 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 libfl2 arm64 2.6.4-6.2 [103 kB]
獲取:2 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 at arm64 3.1.23-1 [48.0 kB]
獲取:3 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 exim4-config all 4.92.3-8+deb10u7 [325 kB]
獲取:4 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 exim4-base arm64 4.92.3-8+deb10u7 [1,136 kB]
獲取:5 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 exim4-daemon-light arm64 4.92.3-8+deb10u7 [533 kB]
獲取:6 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 guile-2.2-libs arm64 2.2.4+1-2+deb10u1 [4,941 kB]
獲取:7 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 libntlm0 arm64 1.5-1+deb10u1+rebuild [23.6 kB]
獲取:8 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 libgsasl7 arm64 1.8.0-8+b2 [198 kB]
獲取:9 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 libkyotocabinet16v5 arm64 1.2.76-4.2+b1 [267 kB]
獲取:10 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 mailutils-common all 1:3.5-4+rebuild [689 kB]
獲取:11 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 libmailutils5 arm64 1:3.5-4+rebuild [829 kB]
獲取:12 https://professional-packages.chinauos.com/desktop-professional eagle/main arm64 mailutils arm64 1:3.5-4+rebuild [567 kB]
已下載 9,660 kB,耗時(shí) 9秒 (1,022 kB/s)
正在預(yù)設(shè)定軟件包 ...
正在選中未選擇的軟件包 libfl2:arm64。
(正在讀取數(shù)據(jù)庫(kù) ... 系統(tǒng)當(dāng)前共安裝有 207780 個(gè)文件和目錄。)
準(zhǔn)備解壓 .../00-libfl2_2.6.4-6.2_arm64.deb ...
正在解壓 libfl2:arm64 (2.6.4-6.2) ...
/var/cache/apt/archives/libfl2_2.6.4-6.2_arm64.deb
正在選中未選擇的軟件包 at。
準(zhǔn)備解壓 .../01-at_3.1.23-1_arm64.deb ...
正在解壓 at (3.1.23-1) ...
/var/cache/apt/archives/at_3.1.23-1_arm64.deb
正在選中未選擇的軟件包 exim4-config。
準(zhǔn)備解壓 .../02-exim4-config_4.92.3-8+deb10u7_all.deb ...
正在解壓 exim4-config (4.92.3-8+deb10u7) ...
/var/cache/apt/archives/exim4-config_4.92.3-8+deb10u7_all.deb
正在選中未選擇的軟件包 exim4-base。
準(zhǔn)備解壓 .../03-exim4-base_4.92.3-8+deb10u7_arm64.deb ...
正在解壓 exim4-base (4.92.3-8+deb10u7) ...
/var/cache/apt/archives/exim4-base_4.92.3-8+deb10u7_arm64.deb
正在選中未選擇的軟件包 exim4-daemon-light。
準(zhǔn)備解壓 .../04-exim4-daemon-light_4.92.3-8+deb10u7_arm64.deb ...
正在解壓 exim4-daemon-light (4.92.3-8+deb10u7) ...
/var/cache/apt/archives/exim4-daemon-light_4.92.3-8+deb10u7_arm64.deb
正在選中未選擇的軟件包 guile-2.2-libs:arm64。
準(zhǔn)備解壓 .../05-guile-2.2-libs_2.2.4+1-2+deb10u1_arm64.deb ...
正在解壓 guile-2.2-libs:arm64 (2.2.4+1-2+deb10u1) ...
/var/cache/apt/archives/guile-2.2-libs_2.2.4+1-2+deb10u1_arm64.deb
正在選中未選擇的軟件包 libntlm0:arm64。
準(zhǔn)備解壓 .../06-libntlm0_1.5-1+deb10u1+rebuild_arm64.deb ...
正在解壓 libntlm0:arm64 (1.5-1+deb10u1+rebuild) ...
/var/cache/apt/archives/libntlm0_1.5-1+deb10u1+rebuild_arm64.deb
正在選中未選擇的軟件包 libgsasl7。
準(zhǔn)備解壓 .../07-libgsasl7_1.8.0-8+b2_arm64.deb ...
正在解壓 libgsasl7 (1.8.0-8+b2) ...
/var/cache/apt/archives/libgsasl7_1.8.0-8+b2_arm64.deb
正在選中未選擇的軟件包 libkyotocabinet16v5:arm64。
準(zhǔn)備解壓 .../08-libkyotocabinet16v5_1.2.76-4.2+b1_arm64.deb ...
正在解壓 libkyotocabinet16v5:arm64 (1.2.76-4.2+b1) ...
/var/cache/apt/archives/libkyotocabinet16v5_1.2.76-4.2+b1_arm64.deb
正在選中未選擇的軟件包 mailutils-common。
準(zhǔn)備解壓 .../09-mailutils-common_1%3a3.5-4+rebuild_all.deb ...
正在解壓 mailutils-common (1:3.5-4+rebuild) ...
/var/cache/apt/archives/mailutils-common_1%3a3.5-4+rebuild_all.deb
正在選中未選擇的軟件包 libmailutils5:arm64。
準(zhǔn)備解壓 .../10-libmailutils5_1%3a3.5-4+rebuild_arm64.deb ...
正在解壓 libmailutils5:arm64 (1:3.5-4+rebuild) ...
/var/cache/apt/archives/libmailutils5_1%3a3.5-4+rebuild_arm64.deb
正在選中未選擇的軟件包 mailutils。
準(zhǔn)備解壓 .../11-mailutils_1%3a3.5-4+rebuild_arm64.deb ...
正在解壓 mailutils (1:3.5-4+rebuild) ...
/var/cache/apt/archives/mailutils_1%3a3.5-4+rebuild_arm64.deb
正在設(shè)置 libkyotocabinet16v5:arm64 (1.2.76-4.2+b1) ...
正在設(shè)置 libntlm0:arm64 (1.5-1+deb10u1+rebuild) ...
正在設(shè)置 mailutils-common (1:3.5-4+rebuild) ...
正在設(shè)置 libfl2:arm64 (2.6.4-6.2) ...
正在設(shè)置 exim4-config (4.92.3-8+deb10u7) ...
Adding system-user for exim (v4)
正在設(shè)置 guile-2.2-libs:arm64 (2.2.4+1-2+deb10u1) ...
正在設(shè)置 exim4-base (4.92.3-8+deb10u7) ...
exim: DB upgrade, deleting hints-db
正在設(shè)置 at (3.1.23-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/atd.service → /lib/systemd/system/atd.service.
正在設(shè)置 libgsasl7 (1.8.0-8+b2) ...
正在設(shè)置 exim4-daemon-light (4.92.3-8+deb10u7) ...
Initializing GnuTLS DH parameter file
正在設(shè)置 libmailutils5:arm64 (1:3.5-4+rebuild) ...
正在設(shè)置 mailutils (1:3.5-4+rebuild) ...
update-alternatives: 使用 /usr/bin/frm.mailutils 來(lái)在自動(dòng)模式中提供 /usr/bin/frm (frm)
update-alternatives: 使用 /usr/bin/from.mailutils 來(lái)在自動(dòng)模式中提供 /usr/bin/from (from)
update-alternatives: 使用 /usr/bin/messages.mailutils 來(lái)在自動(dòng)模式中提供 /usr/bin/messages (messages)
update-alternatives: 使用 /usr/bin/movemail.mailutils 來(lái)在自動(dòng)模式中提供 /usr/bin/movemail (movemail)
update-alternatives: 使用 /usr/bin/readmsg.mailutils 來(lái)在自動(dòng)模式中提供 /usr/bin/readmsg (readmsg)
update-alternatives: 使用 /usr/bin/dotlock.mailutils 來(lái)在自動(dòng)模式中提供 /usr/bin/dotlock (dotlock)
update-alternatives: 使用 /usr/bin/mail.mailutils 來(lái)在自動(dòng)模式中提供 /usr/bin/mailx (mailx)
正在處理用于 systemd (241.52-deepin1) 的觸發(fā)器 ...
正在處理用于 man-db (2.8.5-2) 的觸發(fā)器 ...
正在處理用于 libc-bin (2.28.23-deepin1) 的觸發(fā)器 ...
uos@uos-PC:~/Desktop$
2、輸入at命令,在指定時(shí)間關(guān)機(jī)
uos@uos-PC:~/Desktop$ sudo -i
請(qǐng)輸入密碼:
驗(yàn)證成功
root@uos-PC:~#
root@uos-PC:~# echo "poweroff" | at 14:25
warning: commands will be executed using /bin/sh
job 3 at Thu Sep 28 14:25:00 2023
root@uos-PC:~#
3、系統(tǒng)已經(jīng)關(guān)機(jī)
我們編寫(xiě)的Web項(xiàng)目部署之后,經(jīng)常會(huì)因?yàn)樾枰M(jìn)行配置變更或功能迭代而重啟服務(wù),單純的kill -9 pid的方式會(huì)強(qiáng)制關(guān)閉進(jìn)程,這樣就會(huì)導(dǎo)致服務(wù)端當(dāng)前正在處理的請(qǐng)求失敗,那有沒(méi)有更優(yōu)雅的方式來(lái)實(shí)現(xiàn)關(guān)機(jī)或重啟呢?
閱讀本文需要了解一些UNIX系統(tǒng)中信號(hào)的概念,請(qǐng)?zhí)崆安殚嗁Y料預(yù)習(xí)。
每個(gè)信號(hào)都有一個(gè)名字和編號(hào),這些名字都以“SIG”開(kāi)頭,例如“SIGIO ”、“SIGCHLD”等等。 信號(hào)定義在signal.h頭文件中,信號(hào)名都定義為正整數(shù)。 具體的信號(hào)名稱可以使用kill -l來(lái)查看信號(hào)的名字以及序號(hào),信號(hào)是從1開(kāi)始編號(hào)的,不存在0號(hào)信號(hào)。kill對(duì)于信號(hào)0又特殊的應(yīng)用。
root@1204nStrive:~# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
復(fù)制代碼
信號(hào)的處理有三種方法,分別是:忽略、捕捉和默認(rèn)動(dòng)作
優(yōu)雅關(guān)機(jī)就是服務(wù)端關(guān)機(jī)命令發(fā)出后不是立即關(guān)機(jī),而是等待當(dāng)前還在處理的請(qǐng)求全部處理完畢后再退出程序,是一種對(duì)客戶端友好的關(guān)機(jī)方式。而執(zhí)行Ctrl+C關(guān)閉服務(wù)端時(shí),會(huì)強(qiáng)制結(jié)束進(jìn)程導(dǎo)致正在訪問(wèn)的請(qǐng)求出現(xiàn)問(wèn)題。
Go 1.8版本之后,http.Server 內(nèi)置的Shutdown() 方法支持優(yōu)雅關(guān)機(jī),如下
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/gin-gonic/gin"
)
// @title Docker監(jiān)控服務(wù)
// @version 1.0
// @description gin shutdown
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host 127.0.0.1:9009
// @BasePath
func main() {
r :=gin.Default()
r.GET("/", func(c *gin.Context) {
time.Sleep(5 * time.Second)
c.String(http.StatusOK, "gin %s", "ok")
})
r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
server :=http.Server{
Addr: ":8080",
Handler: r,
}
go func() {
if err :=server.ListenAndServe(); err !=nil && err !=http.ErrServerClosed {
log.Fatal("server listen err:%s", err)
}
}()
quit :=make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
// 在此阻塞
<-quit
ctx, channel :=context.WithTimeout(context.Background(), 5*time.Second)
defer channel()
if err :=server.Shutdown(ctx); err !=nil {
log.Fatal("server shutdown error")
}
log.Println("server exiting...")
}
復(fù)制代碼
如何驗(yàn)證優(yōu)雅關(guān)機(jī)的效果呢?
上面的代碼運(yùn)行后會(huì)在本地的8080端口開(kāi)啟一個(gè)web服務(wù),它只注冊(cè)了一條路由/,后端服務(wù)會(huì)先sleep 5秒鐘然后才返回響應(yīng)信息。
我們按下Ctrl+C時(shí)會(huì)發(fā)送syscall.SIGINT來(lái)通知程序優(yōu)雅關(guān)機(jī),具體做法如下:
優(yōu)雅關(guān)機(jī)實(shí)現(xiàn)了,那么該如何實(shí)現(xiàn)優(yōu)雅重啟呢?
我們可以使用 fvbock/endless 來(lái)替換默認(rèn)的 ListenAndServe啟動(dòng)服務(wù)來(lái)實(shí)現(xiàn), 示例代碼如下:
package main
import (
"log"
"net/http"
"time"
"github.com/fvbock/endless"
"github.com/gin-gonic/gin"
)
func main() {
router :=gin.Default()
router.GET("/", func(c *gin.Context) {
time.Sleep(5 * time.Second)
c.String(http.StatusOK, "hello gin!")
})
// 默認(rèn)endless服務(wù)器會(huì)監(jiān)聽(tīng)下列信號(hào):
// syscall.SIGHUP,syscall.SIGUSR1,syscall.SIGUSR2,syscall.SIGINT,syscall.SIGTERM和syscall.SIGTSTP
// 接收到 SIGHUP 信號(hào)將觸發(fā)`fork/restart` 實(shí)現(xiàn)優(yōu)雅重啟(kill -1 pid會(huì)發(fā)送SIGHUP信號(hào))
// 接收到 syscall.SIGINT或syscall.SIGTERM 信號(hào)將觸發(fā)優(yōu)雅關(guān)機(jī)
// 接收到 SIGUSR2 信號(hào)將觸發(fā)HammerTime
// SIGUSR1 和 SIGTSTP 被用來(lái)觸發(fā)一些用戶自定義的hook函數(shù)
if err :=endless.ListenAndServe(":8080", router); err!=nil{
log.Fatalf("listen: %s\n", err)
}
log.Println("Server exiting")
}
復(fù)制代碼
如何驗(yàn)證優(yōu)雅重啟的效果呢?
我們通過(guò)執(zhí)行kill -1 pid命令發(fā)送syscall.SIGINT來(lái)通知程序優(yōu)雅重啟,具體做法如下:
但是需要注意的是,此時(shí)程序的PID變化了,因?yàn)?span style="color: #FF502C; --tt-darkmode-color: #A01B00;">endless 是通過(guò)fork子進(jìn)程處理新請(qǐng)求,待原進(jìn)程處理完當(dāng)前請(qǐng)求后再退出的方式實(shí)現(xiàn)優(yōu)雅重啟的。所以當(dāng)你的項(xiàng)目是使用類(lèi)似supervisor的軟件管理進(jìn)程時(shí)就不適用這種方式了。
if err :=rsv.ListenAndServe(); err !=nil && err !=http.ErrServerClosed {
復(fù)制代碼
// kill 默認(rèn)會(huì)發(fā)送 syscall.SIGTERM 信號(hào)
// kill -2 發(fā)送 syscall.SIGINT 信號(hào),我們常用的Ctrl+C就是觸發(fā)系統(tǒng)SIGINT信號(hào)
// kill -9 發(fā)送 syscall.SIGKILL 信號(hào),但是不能被捕獲,所以不需要添加它
// signal.Notify把收到的 syscall.SIGINT或syscall.SIGTERM 信號(hào)轉(zhuǎn)發(fā)給quit
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) // 此處不會(huì)阻塞
<-quit // 阻塞在此,當(dāng)接收到上述兩種信號(hào)時(shí)才會(huì)往下執(zhí)行
log.Println("Shutdown Server ...")
復(fù)制代碼
無(wú)論是優(yōu)雅關(guān)機(jī)還是優(yōu)雅重啟歸根結(jié)底都是通過(guò)監(jiān)聽(tīng)特定系統(tǒng)信號(hào),然后執(zhí)行一定的邏輯處理保障當(dāng)前系統(tǒng)正在處理的請(qǐng)求被正常處理后再關(guān)閉當(dāng)前進(jìn)程。使用優(yōu)雅關(guān)機(jī)還是使用優(yōu)雅重啟以及怎么實(shí)現(xiàn),這就需要根據(jù)項(xiàng)目實(shí)際情況來(lái)決定了。
*請(qǐng)認(rèn)真填寫(xiě)需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。