0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

CentOS - How to Setup a Service in Systemd?

Last updated at Posted at 2023-03-16

新增檔案

johnny$ sudo vim /etc/systemd/system/web.service
web.service
[Unit]
Description=Web Dev Service
After=network.target

[Service]
WorkingDirectory=/home/johnny/web_folder
ExecStart=/usr/bin/npm run dev
Restart=always
User=1001  // 沒有設定,預設會使用 ROOT 身份執行
Group=1001 // 沒有設定,預設會使用 ROOT 身份執行

[Install]
WantedBy=multi-user.target
johnny$ sudo chmod 644 /etc/systemd/system/web.service
johnny$ sudo systemctl daemon-reload // 每次有修改 web.service 都要執行一次

服務操作

johnny$ sudo systemctl start web   // 立刻啟動服務
johnny$ sudo systemctl stop web    // 立刻停止服務
johnny$ sudo systemctl status web  // 查看目前服務狀態
johnny$ sudo systemctl enable web  // 開機時啟動服務
johnny$ sudo systemctl disable web // 取消開機時啟動服務
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?