網站首頁 編程語言 正文
一、開機執行一次的腳本
我們通過可以創建一個/etc/rc.local文件:
/etc/rc.local文件內容如下:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
bash /opt/reboot.sh &
exit 0
這樣子我們的linux系統每次開機都會運行一次/opt/reboot.sh腳本。
一、開機自動運行的systemd服務
touch.service:
[Unit]
Description=touch service
[Service]
Type=oneshot
ExecStart=touch /jian
#ExecStop=rm /jian
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Alias=touch.service
把這個文件放到/lib/systemd/system/目錄,然后執行命令使能它,讓他開機自動運行一次:
sudo systemctl enable touch.service
同時我們可以手動運行這個服務:
sudo systemctl start touch.service
二、關機執行systemd服務
rtc_load.service:
[Unit]
Description=set the RTC from the system time
Before=systemd-poweroff.service systemd-reboot.service systemd-halt.service
DefaultDependencies=no
[Service]
ExecStart=hwclock -w
Type=forking
[Install]
WantedBy=poweroff.target
WantedBy=reboot.target
WantedBy=halt.target
把這個文件放到/lib/systemd/system/目錄,然后使用以下命令創建幾個軟連接:
ln -s /lib/systemd/system/rtc_load.service /usr/lib/systemd/system/halt.target.wants/
ln -s /lib/systemd/system/rtc_load.service /usr/lib/systemd/system/poweroff.target.wants/
ln -s /lib/systemd/system/rtc_load.service /usr/lib/systemd/system/reboot.target.wants/
原文鏈接:https://blog.csdn.net/sinat_22338935/article/details/125596100
- 上一篇:常見的dos命令
- 下一篇:使用cgroup控制cpu、內存、IO資源實踐
相關推薦
- 2022-08-29 Python?GUI?圖形用戶界面_python
- 2022-09-04 k8s查看pod日志的幾種實用方法匯總_云其它
- 2022-04-01 Kubernetes中Nginx配置熱加載的全過程_nginx
- 2022-11-13 Git如何實現checkout遠程tag_相關技巧
- 2022-07-12 luckySheet在線編輯excel及遇到的問題
- 2022-11-16 docker-compose安裝及執行命令_docker
- 2023-01-09 GO中優雅編碼與降低圈復雜度詳析_Golang
- 2022-06-06 uniApp實現滾動視圖點擊錨點跳轉、點擊左側分欄時右側對應內容置頂、左右分欄聯動、getSyste
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支