日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Ubuntu >内容正文

Ubuntu

Ubuntu17.04 之 systemd 设置开机启动

發布時間:2023/12/20 Ubuntu 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Ubuntu17.04 之 systemd 设置开机启动 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Ubuntu從16.04開始不再使用 initd 管理系統,改用 systemd。 和 Centos 一樣,升級到 Centos7 之后使用 systemd 替代 init.d
為了像以前一樣,在/etc/rc.local中設置開機啟動程序,需要以下幾步:

1、鏈接文件

systemd 默認讀取 /etc/systemd/system 下的配置文件,該目錄下的文件會鏈接 /lib/systemd/system/ 下的文件。一般系統安裝完成之后會在/lib/systemd/system/形成rc-local.service文件,即我們需要的配置文件。

開機時,Systemd只執行 /etc/systemd/system 目錄里面的配置文件。這也意味著,如果把修改后的配置文件放在該目錄,就可以達到覆蓋原始配置的效果

鏈接過來:ln -fs /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

使用systemctl enabled rc-local.service 同樣可以達到效果,

systemctl is-enabled unit #顯示某個unit服務是否建立了啟動鏈接
systemctl enabled unit ? ?#為某個unit服務創建啟動鏈接

查看rc-local.service內容:

cd /etc/systemd/system/
vim rc-local.service

#? This file is part of systemd. # #? systemd is free software; you can redistribute it and/or modify it #? under the terms of the GNU Lesser General Public License as published by #? the Free Software Foundation; either version 2.1 of the License, or #? (at your option) any later version.# This unit gets pulled automatically into multi-user.target by # systemd-rc-local-generator if /etc/rc.local is executable. [Unit] Description=/etc/rc.local Compatibility ConditionFileIsExecutable=/etc/rc.local After=network.target[Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 RemainAfterExit=yes GuessMainPID=no[Install] WantedBy=multi-user.target Alias=rc-local.service

2、創建/etc/rc.local文件

touch /etc/rc.local

3、賦可執行權限

chmod 755 /etc/rc.local

4、編輯rc.local,添加需要開機啟動的任務

#!/bin/bash echo "test test " > /var/test_boot_up.log

5、執行reboot重啟系統驗證OK。

最后,說一下/etc/systemd/system/下的配置文件(XXXX.service),其中有三個配置項,[Unit] / [Service] / [Install]?

  • [Unit] 區塊:啟動順序與依賴關系。
  • [Service] 區塊:啟動行為,如何啟動,啟動類型。
  • [Install] 區塊,定義如何安裝這個配置文件,即怎樣做到開機啟動。

ubuntu版本為17.10,如果不成功,使用命令

systemctl enable rc-local.service

總結

以上是生活随笔為你收集整理的Ubuntu17.04 之 systemd 设置开机启动的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。