1
2

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 5 years have passed since last update.

UbuntuでFlaskをService実行する手順

Posted at

自分用のメモ投稿。Flaskで作成したWeb APIをUbuntu上でバックグラウンドのServiecとして起動する手順。

  1. flask.serviceを作成
  2. serviceの起動・停止コマンド

1. flask.serviceを作成

terminal
$ nano /lib/systemd/system/flask.service
flask.service
[Unit]
Description=Flask web server

[Install]
WantedBy=multi-user.target

[Service]
User=root
Group=root
PermissionsStartOnly=true
WorkingDirectory=/dir/to/my-script
ExecStart=/bin/bash -c 'python3 -u my-script.py'
Restart=on-failure
RestartSec=10s
RuntimeDirectoryMode=755

2. serviceの起動・停止コマンド

terminal
$ sudo service flask start # flaskサービス開始
$ sudo service flask stop # flaskサービス停止
$ sudo service flask restart # flaskサービスRestart
1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?