Useful Commands/Service Management: Difference between revisions

From Fundamental Ramen
Jump to navigation Jump to search
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
== systemctl ==
== systemctl ==
{| class="wikitable"
{| class="wikitable"
! Purpose || Command  
! Purpose || Command
|-
|-
| List services ||
| Monitor ||
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
systemctl -t service
journalctl -u llama-swap -n 10 -f
 
journalctl -u llama-swap --since "10:20"
journalctl -u llama-swap --since "10 minutes ago"
journalctl -u llama-swap --since today
 
systemctl status llama-swap
</syntaxhighlight>
</syntaxhighlight>
|-
|-
| Setup a service ||
| Setup ||
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
systemctl reload nginx
sudo systemctl disable llama-swap
systemctl disable mysql.service
sudo systemctl daemon-reload
systemctl reload systemd-networkd
 
sudo ln -s /home/xxx/yyy/llama-swap.service llama.service
sudo systemctl enable llama-swap
sudo systemctl daemon-reload
</syntaxhighlight>
</syntaxhighlight>
|-
|-
| Monitor a service ||
| Control ||
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
systemctl status nginx
systemctl start  nginx
systemctl stop  nginx
systemctl reload nginx
systemctl reload systemd-networkd
</syntaxhighlight>
</syntaxhighlight>
|-
|-
| Control services ||
| List ||
<syntaxhighlight lang="bash">
<syntaxhighlight lang="bash">
systemctl start  nginx
systemctl -t service
systemctl stop  nginx
</syntaxhighlight>
</syntaxhighlight>
|}
== Linux 傳統 ==
{| class="wikitable"
! 情境 || 指令
|-
| 管理系統服務 || <syntaxhighlight lang="bash">sudo service start/stop/reload/restart {服務名稱}</syntaxhighlight>
|-
| 顯示服務狀態 || <syntaxhighlight lang="bash">service --status-all</syntaxhighlight>
|-
| 顯示服務 (啟動/關閉) 時機 (runlevel 0~6) || <syntaxhighlight lang="bash">chkconfig --list</syntaxhighlight>
|-
| 設定服務在開機後自動啟動 || <syntaxhighlight lang="bash">sudo chkconfig --level 2345 {服務名稱} on</syntaxhighlight>
|}
|}


Line 43: Line 41:


{| class="wikitable"
{| class="wikitable"
! Run Level || Description
! Target || ! Description
|-
| align="center" | 0 || halt
|-
|-
| align="center" | 1 || single user mode
| multi-user.target || Multi-user mode (CLI) (Equivalent to Runlevel 3)
|-
|-
| align="center" | 2 || Multi-user, without NFS
| graphical.target || Graphical mode (GUI) (Equivalent to Runlevel 5)
|-
|-
| align="center" | 3 || Full multi-user mode
| rescue.target || Rescue mode (Equivalent to Runlevel 1)
|-
|-
| align="center" | 4 || unused
| emergency.target || Emergency mode (Equivalent to Runlevel 0)
|-
|-
| align="center" | 5 || X11
| reboot.target || Reboot
|-
|-
| align="center" | 6 || reboot
| poweroff.target || Power off
|}
|}

Latest revision as of 02:48, 10 September 2026

systemctl

Purpose Command
Monitor
journalctl -u llama-swap -n 10 -f

journalctl -u llama-swap --since "10:20"
journalctl -u llama-swap --since "10 minutes ago"
journalctl -u llama-swap --since today

systemctl status llama-swap
Setup
sudo systemctl disable llama-swap
sudo systemctl daemon-reload

sudo ln -s /home/xxx/yyy/llama-swap.service llama.service
sudo systemctl enable llama-swap
sudo systemctl daemon-reload
Control
systemctl start  nginx
systemctl stop   nginx
systemctl reload nginx
systemctl reload systemd-networkd
List
systemctl -t service

Run Level

Target ! Description
multi-user.target Multi-user mode (CLI) (Equivalent to Runlevel 3)
graphical.target Graphical mode (GUI) (Equivalent to Runlevel 5)
rescue.target Rescue mode (Equivalent to Runlevel 1)
emergency.target Emergency mode (Equivalent to Runlevel 0)
reboot.target Reboot
poweroff.target Power off