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?

📌 Linuxで .service ファイルを登録する方法

Posted at

サービスファイルを配置する

システム全体で使う場合:

sudo cp your_service.service /etc/systemd/system/

ユーザー専用サービスの場合:

cp your_service.service ~/.config/systemd/user/

systemd に認識させる

sudo systemctl daemon-reload

自動起動を有効化(必要なら)

sudo systemctl enable your_service.service

サービスを起動

sudo systemctl start your_service.service

状態を確認

sudo systemctl status your_service.service

ログを確認

journalctl -u your_service.service

⚡ サンプル .service ファイル

ini
[Unit]
Description=My Custom App Service
After=network.target

[Service]
ExecStart=/usr/bin/python3 /home/user/myapp.py
Restart=always
User=user

[Install]
WantedBy=multi-user.target

このファイルを /etc/systemd/system/myapp.service に置いて、上記の手順で登録すればOKです。

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?