起動スクリプトとサービスの作成
Cardano Nodeのインスタンスを実行するには、オプションを設定するbashスクリプトを作成します。
また、Cardano Nodeをsystemdサービスとして実装します。
tip
Cardano Nodeをsystemdサービスとして実行すると、ステークプールプロセスがクラッシュした場合やコンピューターが再起動した場合にステークプールが自動的に再起動されるため、ステークプールの稼働時間が最大化されます。
Cardano Nodeの起動スクリプト作成
- リレー
- BP
node_port=3001
cat > $NODE_HOME/startCardanoNodeRelay.sh << EOF
#!/bin/bash
DIRECTORY=$NODE_HOME
PORT=${node_port}
HOSTADDR=0.0.0.0
TOPOLOGY=\${DIRECTORY}/${NODE_CONFIG}-topology.json
DB_PATH=\${DIRECTORY}/db
SOCKET_PATH=\${DIRECTORY}/db/socket
CONFIG=\${DIRECTORY}/${NODE_CONFIG}-config.json
/usr/local/bin/cardano-node run +RTS -N -RTS --topology \${TOPOLOGY} --database-path \${DB_PATH} --socket-path \${SOCKET_PATH} --host-addr \${HOSTADDR} --port \${PORT} --config \${CONFIG}
EOF
warning
BPノードポートは、セキュリティを向上させるために49513~65535までの任意番号に設定します。
node_port=$(shuf -i 49513-65535 -n 1)
echo "BPポート : ${node_port}"
cat > $NODE_HOME/startCardanoNodeBP.sh << EOF
#!/bin/bash
DIRECTORY=$NODE_HOME
PORT=${node_port}
HOSTADDR=0.0.0.0
TOPOLOGY=\${DIRECTORY}/${NODE_CONFIG}-topology.json
DB_PATH=\${DIRECTORY}/db
SOCKET_PATH=\${DIRECTORY}/db/socket
CONFIG=\${DIRECTORY}/${NODE_CONFIG}-config.json
/usr/local/bin/cardano-node run +RTS -N -RTS --topology \${TOPOLOGY} --database-path \${DB_PATH} --socket-path \${SOCKET_PATH} --host-addr \${HOSTADDR} --port \${PORT} --config \${CONFIG}
EOF
ノードの起動
- ノードを起動します。
- リレー
- BP
cd $NODE_HOME
chmod +x $NODE_HOME/startCardanoNodeRelay.sh
./startCardanoNodeRelay.sh
cd $NODE_HOME
chmod +x $NODE_HOME/startCardanoNodeBP.sh
./startCardanoNodeBP.sh
- ログの正常性を確認します。
Chain extended, new tip: xxxxのログ
- ノードを停止します。
Ctrl+C
Cardano Nodeのサービスファイル作成
- Cardano Nodeのサービスファイルの生成
- リレー
- BP
cat > $NODE_HOME/cardano-node.service << EOF
# The Cardano Node service (part of systemd)
# file: /etc/systemd/system/cardano-node.service
[Unit]
Description = Cardano Node Service
Wants = network-online.target
After = network-online.target
[Service]
User = ${USER}
Type = simple
WorkingDirectory = ${NODE_HOME}
ExecStart = /bin/bash -c '${NODE_HOME}/startCardanoNodeRelay.sh'
KillSignal = SIGINT
RestartKillSignal = SIGINT
TimeoutStopSec = 300
LimitNOFILE = 32768
Restart = always
RestartSec = 5
StandardOutput = syslog
StandardError = syslog
SyslogIdentifier = cardano-node
[Install]
WantedBy = multi-user.target
EOF
cat > $NODE_HOME/cardano-node.service << EOF
# The Cardano Node service (part of systemd)
# file: /etc/systemd/system/cardano-node.service
[Unit]
Description = Cardano Node Service
Wants = network-online.target
After = network-online.target
[Service]
User = ${USER}
Type = simple
WorkingDirectory = ${NODE_HOME}
ExecStart = /bin/bash -c '${NODE_HOME}/startCardanoNodeBP.sh'
KillSignal = SIGINT
RestartKillSignal = SIGINT
TimeoutStopSec = 300
LimitNOFILE = 32768
Restart = always
RestartSec = 5
StandardOutput = syslog
StandardError = syslog
SyslogIdentifier = cardano-node
[Install]
WantedBy = multi-user.target
EOF
- ブロックチェーンデータを保存するフォルダーを作成します。
mkdir -p $NODE_HOME/db
cardano-node.serviceファイルを/etc/systemd/systemフォルダーに移動し、ファイル権限を設定します。
sudo cp $NODE_HOME/cardano-node.service /etc/systemd/system/cardano-node.service
sudo chmod 644 /etc/systemd/system/cardano-node.service
- コンピュータの起動時にCardano Nodeをサービスとして起動する設定をします。
sudo systemctl daemon-reload
sudo systemctl enable cardano-node.service
サービスの管理
tip
systemdサービスとして実行されているCardano Nodeのインスタンスを管理するには、次のコマンドを使用します。
- Cardano Nodeのサービスステータスを表示
sudo systemctl status cardano-node
- Cardano Nodeのサービス再起動
sudo systemctl reload-or-restart cardano-node
- Cardano Nodeのサービス停止
sudo systemctl stop cardano-node
- ログを表示およびフィルタリング
journalctl --unit=cardano-node --follow
journalctl --unit=cardano-node --since=yesterday
journalctl --unit=cardano-node --since=today
journalctl --unit=cardano-node --since='2022-07-29 00:00:00' --until='2022-07-29 12:00:00'