デプロイプロセスを容易にするために、git リポジトリでこれを使用しています:
a-simple-systemd-service-autoinstall-script.sh
#!/bin/bash
# このスクリプトは systemd サービスをインストールして有効化/開始します
# また、サービスファイルもインストールします
export NAME=MyService
cat >/etc/systemd/system/${NAME}.service <<EOF
# TODO systemd .service ファイルをここにコピー&ペーストしてください
EOF
# サービスを有効化して開始
systemctl enable --now ${NAME}.service次の例は docker-compose の systemd .service を自動的にインストールします:
a-simple-systemd-service-autoinstall-script-2.sh
#!/bin/bash
# このスクリプトは systemd サービスをインストールして有効化/開始します
# また、サービスファイルもインストールします
export NAME=MyService
cat >/etc/systemd/system/${NAME}.service <<EOF
[Unit]
Description=${NAME}
Requires=docker.service
After=docker.service
[Service]
Restart=always
User=root
Group=docker
WorkingDirectory=$(pwd)
# ユニットが開始される前にコンテナをシャットダウン(実行中の場合)
ExecStartPre=$(which docker-compose) -f docker-compose.yml down
# ユニットが開始されたときにコンテナを開始
ExecStart=$(which docker-compose) -f docker-compose.yml up
# ユニットが停止されたときにコンテナを停止
ExecStop=$(which docker-compose) -f docker-compose.yml down
[Install]
WantedBy=multi-user.target
EOF
# サービスを有効化して開始
systemctl enable --now ${NAME}.serviceこの記事が役に立った場合は、TechOverflow での新しい記事の調査と公開を支援するため、「Buy Me a Coffee」でのご支援、または PayPal 経由でのご寄付をご検討ください