Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; macro of Tera Term
- ;
- ; File : AspNetCoreDeploy.ttl
- ; Description: サーバにASP.NET Coreプログラムをデプロイします。
- ; rootユーザ用です。そうでない場合はsuコマンド処理を組み込んでください。
- ; Environment: BostNexサーバ
- ; Author : ぎんぺー
- ; --------------------------------設定項目--------------------------------
- ; サーバ情報
- username = 'root'
- hostname = '192.168.0.9'
- ; Nginxユーザ名
- nginx_user = 'www'
- ; 転送元(ローカル)ファイル
- ; VisualStudio発行機能で、パッケージの場所を以下にした場合
- ; C:\Users\ginpay\Source\deploy\BestNox
- project_name = 'BestNox'
- ; 転送
- source_file = 'C:\Users\ginpay\Source\deploy\'
- strconcat source_file project_name
- strconcat source_file '\'
- strconcat source_file project_name
- strconcat source_file '.zip'
- ; 転送先(サーバ)本番ディレクトリ
- destination_directory = '/var/aspnetcore/'
- ; 解凍作業ディレクトリ
- temp_directory = destination_directory
- strconcat temp_directory 'temp/'
- ; 解凍ディレクトリ構造(事前に発行したzipを解凍してみて確認すること)
- ; 例:'Content/C_C/Users/ginpay/Source/Repos/BestNox/BestNox/obj/Release/netcoreapp2.2/linux-x64/PubTmp/Out/'
- ; 前半
- unzip_directory_prev = 'Content/C_C/Users/ginpay/Source/Repos/'
- ; 後半
- unzip_directory_next = '/obj/Release/netcoreapp2.2/linux-x64/PubTmp/Out/'
- unzip_directory = temp_directory
- strconcat unzip_directory unzip_directory_prev
- strconcat unzip_directory project_name
- strconcat unzip_directory '/'
- strconcat unzip_directory project_name
- strconcat unzip_directory unzip_directory_next
- ; 共通メッセージタイトル
- alart = 'デプロイ作業'
- ; --------------------------------入力項目--------------------------------
- inputbox 'パスワードを入れなさい!' 'ログイン'
- password = inputstr
- ; 初回デプロイか確認
- isfirst = 0
- yesnobox 'このシステムのデプロイは初めてですか?' '質問'
- if result then
- isfirst = 1
- endif
- ; ----------------------------------本編----------------------------------
- if isfirst then
- str = '始める前に、使用するポートは開けておいてください。'
- strspecial str
- messagebox str '注意!'
- endif
- ; 接続
- msg = hostname
- strconcat msg ':22 /ssh /auth=password /user='
- strconcat msg username
- strconcat msg ' /passwd='
- strconcat msg password
- connect msg
- pause 2
- ;ファイル転送
- if isfirst then
- messagebox 'ファイルを送信します' alart
- endif
- ; 作業ディレクトリが消え残っていたら削除
- com_temp = 'rm -r -f '
- strconcat com_temp temp_directory
- sendln com_temp
- pause 2
- ; 作業ディレクトリ作成(親ディレクトリも無ければ作成)
- com_temp = 'mkdir -p
- strconcat com_temp temp_directory
- sendln com_temp
- pause 1
- scpsend source_file temp_directory
- if isfirst then
- messagebox 'ファイル送信ダイアログが消えたらOKを押してください' alart
- else
- ; 適当な長さで次行くので調節すること
- pause 5
- endif
- ;Webサービス停止
- if isfirst then
- messagebox 'Webサービスを停止します' alart
- endif
- com_temp = 'systemctl stop '
- strconcat com_temp project_name
- strconcat com_temp '-webapp'
- sendln com_temp
- pause 1
- ;現Webアプリバックアップ
- if isfirst then
- messagebox '現行のプログラムがあればバックアップします' alart
- endif
- com_temp = 'mv -f '
- strconcat com_temp destination_directory
- strconcat com_temp project_name
- strconcat com_temp ' '
- strconcat com_temp destination_directory
- strconcat com_temp 'rev/'
- strconcat com_temp project_name
- sendln com_temp
- pause 1
- ;新ファイル配置
- ; 移動
- if isfirst then
- messagebox '新しいプログラムを配置します' alart
- endif
- com_temp = 'cd '
- strconcat com_temp temp_directory
- sendln com_temp
- ; 解凍
- com_temp = 'unzip '
- strconcat com_temp project_name
- strconcat com_temp '.zip'
- sendln com_temp
- if isfirst then
- messagebox 'ファイルの解凍が終わったらOKを押してください' alart
- else
- ; 適当な長さで次行くので調節すること
- pause 5
- endif
- ; zipファイル削除
- com_temp = 'rm --interactive=never '
- strconcat com_temp project_name
- strconcat com_temp '.zip'
- sendln com_temp
- pause 1
- if isfirst then
- messagebox '解凍したものを移動します、名前も変更します' alart
- endif
- com_temp = 'mv '
- strconcat com_temp unzip_directory
- strconcat com_temp ' '
- strconcat com_temp destination_directory
- strconcat com_temp project_name
- sendln com_temp
- ;ログフォルダ作成
- com_temp = 'mkdir -p /var/log/aspnetcore/'
- strconcat com_temp project_name
- strconcat com_temp '/'
- sendln com_temp
- com_temp = 'chown '
- strconcat com_temp nginx_user
- strconcat com_temp ' /var/log/aspnetcore/'
- sendln com_temp
- strconcat com_temp project_name
- strconcat com_temp '/'
- sendln com_temp
- ;nlog.configを差し替え
- com_temp = 'mv -f '
- strconcat com_temp destination_directory
- strconcat com_temp project_name
- strconcat com_temp '/nlog_Production.config '
- strconcat com_temp destination_directory
- strconcat com_temp project_name
- strconcat com_temp '/nlog.config'
- sendln com_temp
- pause 1
- if isfirst then
- messagebox '解凍フォルダを削除します' alart
- endif
- com_temp = 'rm -r --interactive=never '
- strconcat com_temp temp_directory
- sendln com_temp
- pause 1
- if isfirst then
- str = 'このマクロはマイグレーションを行いません。\nDB変更を行う場合、すぐ行ってください。\nそういう作業がある場合はDDLを準備してマクロに組み込んでください。'
- strspecial str
- messagebox str '注意!'
- endif
- if isfirst then
- messagebox '初回なのでサービス化を行います。' alart
- messagebox 'サービス登録に必要なファイルを作成します。' alart
- service_file = '/etc/systemd/system/'
- strconcat service_file project_name
- strconcat service_file '-webapp.service'
- com_temp = 'mv -f '
- strconcat com_temp service_file
- strconcat com_temp ' /etc/systemd/system/bk_'
- strconcat com_temp appname
- strconcat com_temp '-webapp.service'
- sendln com_temp
- com_temp = 'touch '
- strconcat com_temp service_file
- sendln com_temp
- pause 1
- inputbox 'DBパスワードを教えて。' '登録に必要'
- db_password = inputstr
- ; ひたすら文字を書き込む
- com_temp = "echo '[Unit]' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'Description="
- strconcat com_temp project_name
- strconcat com_temp " .NET Web API App running on CentOS7' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo '' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo '[Service]' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'WorkingDirectory="
- strconcat com_temp destination_directory
- strconcat com_temp project_name
- strconcat com_temp "' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'ExecStart=/usr/bin/dotnet "
- strconcat com_temp destination_directory
- strconcat com_temp project_name
- strconcat com_temp "/"
- strconcat com_temp project_name
- strconcat com_temp ".dll"
- strconcat com_temp "' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'Restart=always' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'RestartSec=10' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'SyslogIdentifier=dotnet-example' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'User="
- strconcat com_temp nginx_user
- strconcat com_temp "' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'Environment=ASPNETCORE_ENVIRONMENT=Production' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'Environment=DATABASE_PASSWORD="
- strconcat com_temp db_password
- strconcat com_temp "' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo '' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo '[Install]' >> "
- strconcat com_temp service_file
- sendln com_temp
- com_temp = "echo 'WantedBy=multi-user.target' >> "
- strconcat com_temp service_file
- sendln com_temp
- messagebox 'サービス登録を行います。' alart
- com_temp = 'systemctl enable '
- strconcat com_temp project_name
- strconcat com_temp '-webapp'
- sendln com_temp
- pause 1
- endif
- ;Web起動
- messagebox 'Webを起動します。' alart
- com_temp = 'systemctl start '
- strconcat com_temp project_name
- strconcat com_temp '-webapp'
- sendln com_temp
- pause 1
- ;終わり
- messagebox 'デプロイ作業が終了しました。サーバ内から繋いでみてください。' alart
- end
- :label_end
- alart = "終了"
- str = "処理を終了します。"
- strspecial str
- messagebox str alart
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement