日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

開機自啟動設置 開機自啟動( 三 )


— Logs begin at Wed 2020-03-25 09:14:55 CST. —
Mar 25 11:02:27 test-server-1 nginx[14144]: nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Mar 25 11:02:27 test-server-1 systemd[1]: PID file /run/nginx.pid not readable (yet?) after start.
Mar 25 11:04:29 test-server-1 systemd[1]: nginx.service start operation timed out. Terminating.
Mar 25 11:04:29 test-server-1 systemd[1]: Failed to start nginx.
Mar 25 11:04:29 test-server-1 systemd[1]: Unit nginx.service entered failed state.
Mar 25 11:04:29 test-server-1 systemd[1]: nginx.service failed.復制代碼
從字面看是PID文件不可讀,查看/var/run/nginx.pid,該文件也確實不存在,查看nginx.conf配置文件,發(fā)現(xiàn)是pid /var/run/nginx.pid;這行配置被注釋掉了,如果不指定pid文件位置,nginx默認會把pid文件保存在logs目錄中 。所以出現(xiàn)systemd啟動服務時找不到pid文件而報錯,將nginx.conf中的pid配置注釋去掉,重啟nginx.service即可 。
Ubuntu18.04的開機自啟動配置
在Ubuntu18.04中,主要也是以systemd服務來實現(xiàn)開機自啟動,systemd默認讀取/etc/systemd/system/下的配置文件,該目錄下的一些文件會鏈接到/lib/systemd/system/下的文件 。
因此可以在/etc/systemd/system/目錄下面創(chuàng)建一個自啟動服務配置,以內(nèi)網(wǎng)穿透服務frp客戶端為例,如
[Unit]
Description=frpc
After=network.target
Wants=network.target
[Service]
TimeoutStartSec=30
ExecStart=/home/devuser/apps/frp/frpc -c /home/devuser/apps/frp/frpc.ini
ExecStop=/bin/kill $MAINPID
Restart=1
[Install]
WantedBy=multi-user.target復制代碼
各配置項與CentOS類似 。然后將服務器加到自啟動列表中并啟動服務
$sudo systemctl enable frpc
$sudo systemctl start frpc復制代碼
其它更多systemctl命令與CentOS類似 。
也可以使用/lib/systemd/system/rc-local.service來執(zhí)行一些開機需要執(zhí)行的腳本,該文件內(nèi)容為
#SPDX-License-Identifier: LGPL-2.1+
#
#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
Documentation=man:systemd-rc-local-generator(8)
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no復制代碼
從Description看它是為了兼容之前版本的/etc/rc.local的,該服務啟動命名就是/etc/rc.local start,將該文件鏈接到/etc/systemd/system下
$ sudo ln -s /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service復制代碼
創(chuàng)建/etc/rc.local文件,并賦予可執(zhí)行權限
$ vim /etc/rc.local
#!/bin/bash
echo "test rc " > /var/test.log
$ sudo chmod +x /etc/rc.local復制代碼<完>
【開機自啟動設置 開機自啟動】作者:半路雨歌鏈接:https://juejin.cn/post/6844904104515338248

推薦閱讀