網站首頁 編程語言 正文
一、開機執行一次的腳本
我們通過可以創建一個/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-05-08 關于PyQt5中QtGui.QImage圖片顯示問題解析_python
- 2022-05-03 C#面向對象設計原則之接口隔離原則_C#教程
- 2022-11-01 詳解批處理文件語法_DOS/BAT
- 2022-03-11 UE4 添加自己項目的AutomationProject,解決報錯Failed to find co
- 2022-09-03 python四則運算表達式求值示例詳解_python
- 2022-06-22 SQL實現篩選出連續3天登錄用戶與窗口函數的示例代碼_MsSql
- 2022-08-30 大表delete刪數據導致數據庫異常解決_oracle
- 2022-11-02 Kotlin中@JvmOverloads注解作用示例介紹_Android
- 最近更新
-
- 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同步修改后的遠程分支