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

cron による Minecraft サーバのプロセス自動再起動設定

Last updated at Posted at 2021-03-29

概要

  • systemd サービスユニットファイルを作成して、Minecraft サーバをサービス化
  • cron で定期的に systemctl コマンドを発行するシェルスクリプトを実行し、サービスの状態をチェック
  • サービスがダウンしていた場合、再起動

Minecraft サーバの設定方法

Linux(CentOS7)で、Minecraftマルチサーバを立ち上げる手順

環境

  • CentOS 7

シェルスクリプト作成

作業ディレクトリに移動し、シェルスクリプトを編集する。

# cd /var/minecraft
# vi auto_restart.sh

シェルスクリプトの内容は以下の通り。

auto_restart.sh
# !/bin/bash

systemctl is-active minecraft_server.service >/dev/null 2>&1

if [ $? != 0 ]; then
    systemctl start minecraft_server.service
fi

exit

systemctl is-active は、サービス実行中は 0 を、そうでない場合は 0 以外の値を返す。詳しくは man systemctl で参照できる。

cron 設定

以下のコマンドを実行する。

# echo "*/10 * * * * root /var/minecraft/auto_restart.sh" > /etc/cron.d/minecraft_auto_restart

上記は、毎時 0 分, 10 分, 20 分, 30 分, 40 分, 50 分に auto_restart.sh に実行する設定なので、必要に応じて実行間隔を調整する。

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?