ubuntu-18.04起動スクリプトの設定

2291 ワード

ubuntu-16.10からinitd管理システムを使用せずsystemdに変更
systemd is now used for user sessions. System sessions had already been provided by systemd in previous Ubuntu releases.
システムdの使い方をすばやく見ると、サービスとchkconfigの機能をシステムctlコマンドで置き換えるなど、変更が少し大きいことがわかりました.
例えばmysqlサービスを以前に起動した場合:
sudo service mysql start

現在使用:
sudo systemctl start mysqld.service

実はこの変更は大きくないですが、主に電源を入れて起動するのは以前よりずっと複雑です.Systemdはデフォルトで/etc/systemd/systemd/systemmのプロファイルを読み込みます.このディレクトリのファイルは/lib/systemd/systemm/のファイルにリンクされます.
ls/lib/systemd/systemmを実行すると、起動スクリプトがたくさん見えます.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

一般的に正常な起動ファイルは主に3つの部分に分かれています
[Unit]セグメント:起動順序と依存関係[Services]セグメント:起動動作、起動方法、起動タイプ[Install]セグメント:このプロファイルのインストール方法、つまり起動方法を定義します
/etc/rc.localの起動順序はネットワークの後ろにありますが、Installセグメントが少なく、起動方法も定義されていないため、このような構成は無効であることは明らかです.そのため、後で[Install]セグメントを追加する必要があります.
[Install]  
WantedBy=multi-user.target  
Alias=rc-local.service

ubuntu-18.04のデフォルトは/etc/rcではありません.localこのファイルは、自分で作成する必要があります
sudo touch /etc/rc.local 

スクリプトを起動して/etc/rcに書き込む必要があります.local、スクリプトが有効かどうかを検証するために、テストのスクリプトをいくつか書いてもいいです.
echo "this just a test" > /usr/local/text.log

これを完了するには、systemdが/etc/systemd/systemd/systemmのプロファイルをデフォルトで読み込む必要があるので、/etc/systemd/systemmディレクトリの下にソフトリンクを作成する必要があります.
ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/ 

OK、次に、システムを再起動し、/usr/local/textを見てください.logファイルが存在するかどうかは、起動スクリプトが有効になっているかどうかを示します.
変換元:http://www.r9it.com/20180613/ubuntu-18.04-auto-start.html