#author("2025-03-30T20:57:01+09:00","default:k1rou","k1rou")
#author("2025-03-30T23:53:14+09:00","default:k1rou","k1rou")
*Linuxの起動・シャットダウン [#b8d380bc]

*Linuxの起動 [#i04b7b09]
**dmesg [#r07f7c32]
-起動時のカーネルの処理を表示
 dmesg

**journalctl [#t4b88d29]
-起動時のカーネルの処理を表示
 journalctl -kb

**起動時のログ [#ieee0c02]
 /var/log/dmesg
 /var/log/messages
 /var/log/boot.log

*Linuxのシャットダウン・再起動 [#l10f5b39]
**shutdown [#yeaab84a]
-即時
 shutdown -h now ※システムを停止
 shutdown -r now ※システムを再起動
 shurdown -k now "comment" ※システムを停止しないで、ログインしているユーザーにメッセージを表示
-指定した時間後
 shutdown -h +15 "comment" ※15分後にシステムを停止。ログインしているユーザーにメッセージを表示
-指定した時刻
 shutdown -r 23:00 ※23時にシステムを再起動
-予約の取り消し
--Ctl + C
--別の端末から
 shutdown -c 

**reboot ※再起動 [#b300f996]
 reboot

**halt ※システム停止 [#z8e3a714]

**poweroff ※システム停止 [#o7f13b48]

*OSを起動する仕組み [#s35b8775]
-アプリケーションの自動起動の設定など
-SysVinitは古くからある仕組みで、新しくsystemd、Upstart が登場している

**SysVinit [#d41740d5]
-System Five Init
-決められた手順に従い直列でシステムを起動する
-UNIXのSystemVで採用されていた起動する仕組みに基づいている

-initプロセスが起動する順序
++/etc/inittab
++/etc/rc.sysinit
++/etc/rc
++/etc/rc<[[ランレベル]]>.d/*

-起動スクリプト
--起動スクリプトを使ったサービスの起動・停止
 /etc/init.d/network start ※起動
 /etc/init.d/network status ※状態を表示
 /etc/init.d/network stop ※停止

-自動起動の設定:initプロセスに設定する
--/etc/rc.d/rc.local
--/etc/rc.local
 ls -l /sbin/init

**systemd [#a804dbd4]
-Unitという単位でシステムを起動する
-サービスを並列で起動する
-※CentOS7以降

-Unitの設定ファイル
--/lib/systemd/system/*
--/etc/systemd/system/* ※ホスト毎の設定

-起動するターゲットの確認
--/etc/systemd/system/default.target
 ls -l /etc/systemd/system/default.target
 →default.targetのリンク先で確認する
 →multi-user.target であればマルチユーザ

-起動するターゲットの変更
--default.target のリンク先を変更する(lnコマンド) 

***systemctl [#if2cd13b]
-サービスの状態を確認
 systemctl status <service-name> ※サービスの稼働状況を表示
 systemctl is-active <service-name> ※サービスが稼働中か表示
-自動起動の設定
 systemctl is-enabled <service-name> ※自動起動の設定を表示
 systemctl enable <service-name> ※自動起動ON
 systemctl disable <service-name> ※自動起動OFF
 systemctl preset <service-name> ※自動起動ONまたはOFF(プリセットポリシーに従う)

--自動起動が設定されているサービスの確認
 ls -l /etc/systemd/system/multi-user.target.wants/
 ※自動起動を有効にするとここにサービスのシンボリックリンクが作成される
-サービスの起動/停止/再起動
 systemctl start <service-name> ※起動
 systemctl stop <service-name> ※停止
 systemctl restart <service-name> ※再起動
 systemctl reload <service-name> ※サービスの設定を再読み込み
-Unitの状態を確認
 systemctl list-dependencies ※Unitの依存関係を表示
 systemctl list-units ※起動している全てのUnitの状態を表示
 systemctl list-unit-files ※全てのUnitを表示
 systemctl list-unit-files -t service ※サービスの一覧を表示
 systemctl list-unit-files -t service --state=enabled ※サービスの一覧を表示(自動起動が有効のみ)
-Unitのマスク(手動でも起動できないようにする)
 systemctl mask <service-name> ※マスク有効
 systemctl unmask <service-name> ※マスク解除
-システムの操作
 systemctl poweroff ※システムを停止
 systemctl reboot ※システムを再起動
-Unitファイルを再読み込み ※Unitファイルを追加・変更したら毎回行う
 systemctl daemon-reload

***ユニットファイル [#d88528fc]
-標準のユニットファイル(通常はパッケージが提供)
 /usr/lib/systemd/system/
-ユーザーがカスタマイズして作成
 /etc/systemd/system/


**Upstart [#q025c428]


**chkconfig [#e45446a3]
-「[[sysconfig]]」参照

**service [#e4828728]
-「[[sysconfig]]」参照

**update-rc.d [#ud87f5bc]
-自動起動設定 [#m85247b7]
 update-rc.d <service-name> enable

*関連用語 [#t9b58a9a]
-[[Linuxコマンド]]
-[[ランレベル]]

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS