Advertisement
Guest User

Untitled

a guest
May 14th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.85 KB | None | 0 0
  1. ; macro of Tera Term
  2. ;
  3. ; File : AspNetCoreDeploy.ttl
  4. ; Description: サーバにASP.NET Coreプログラムをデプロイします。
  5. ; rootユーザ用です。そうでない場合はsuコマンド処理を組み込んでください。
  6. ; Environment: BostNexサーバ
  7. ; Author : ぎんぺー
  8.  
  9. ; --------------------------------設定項目--------------------------------
  10. ; サーバ情報
  11. username = 'root'
  12. hostname = '192.168.0.9'
  13.  
  14. ; Nginxユーザ名
  15. nginx_user = 'www'
  16.  
  17. ; 転送元(ローカル)ファイル
  18. ; VisualStudio発行機能で、パッケージの場所を以下にした場合
  19. ; C:\Users\ginpay\Source\deploy\BestNox
  20. project_name = 'BestNox'
  21.  
  22. ; 転送
  23. source_file = 'C:\Users\ginpay\Source\deploy\'
  24. strconcat source_file project_name
  25. strconcat source_file '\'
  26. strconcat source_file project_name
  27. strconcat source_file '.zip'
  28.  
  29. ; 転送先(サーバ)本番ディレクトリ
  30. destination_directory = '/var/aspnetcore/'
  31.  
  32. ; 解凍作業ディレクトリ
  33. temp_directory = destination_directory
  34. strconcat temp_directory 'temp/'
  35.  
  36. ; 解凍ディレクトリ構造(事前に発行したzipを解凍してみて確認すること)
  37. ; 例:'Content/C_C/Users/ginpay/Source/Repos/BestNox/BestNox/obj/Release/netcoreapp2.2/linux-x64/PubTmp/Out/'
  38. ; 前半
  39. unzip_directory_prev = 'Content/C_C/Users/ginpay/Source/Repos/'
  40. ; 後半
  41. unzip_directory_next = '/obj/Release/netcoreapp2.2/linux-x64/PubTmp/Out/'
  42. unzip_directory = temp_directory
  43. strconcat unzip_directory unzip_directory_prev
  44. strconcat unzip_directory project_name
  45. strconcat unzip_directory '/'
  46. strconcat unzip_directory project_name
  47. strconcat unzip_directory unzip_directory_next
  48.  
  49. ; 共通メッセージタイトル
  50. alart = 'デプロイ作業'
  51. ; --------------------------------入力項目--------------------------------
  52. inputbox 'パスワードを入れなさい!' 'ログイン'
  53. password = inputstr
  54.  
  55. ; 初回デプロイか確認
  56. isfirst = 0
  57. yesnobox 'このシステムのデプロイは初めてですか?' '質問'
  58. if result then
  59. isfirst = 1
  60. endif
  61. ; ----------------------------------本編----------------------------------
  62.  
  63. if isfirst then
  64. str = '始める前に、使用するポートは開けておいてください。'
  65. strspecial str
  66. messagebox str '注意!'
  67. endif
  68.  
  69. ; 接続
  70. msg = hostname
  71. strconcat msg ':22 /ssh /auth=password /user='
  72. strconcat msg username
  73. strconcat msg ' /passwd='
  74. strconcat msg password
  75. connect msg
  76. pause 2
  77.  
  78. ;ファイル転送
  79. if isfirst then
  80. messagebox 'ファイルを送信します' alart
  81. endif
  82. ; 作業ディレクトリが消え残っていたら削除
  83. com_temp = 'rm -r -f '
  84. strconcat com_temp temp_directory
  85. sendln com_temp
  86. pause 2
  87. ; 作業ディレクトリ作成(親ディレクトリも無ければ作成)
  88. com_temp = 'mkdir -p
  89. strconcat com_temp temp_directory
  90. sendln com_temp
  91. pause 1
  92. scpsend source_file temp_directory
  93. if isfirst then
  94. messagebox 'ファイル送信ダイアログが消えたらOKを押してください' alart
  95. else
  96. ; 適当な長さで次行くので調節すること
  97. pause 5
  98. endif
  99.  
  100. ;Webサービス停止
  101. if isfirst then
  102. messagebox 'Webサービスを停止します' alart
  103. endif
  104. com_temp = 'systemctl stop '
  105. strconcat com_temp project_name
  106. strconcat com_temp '-webapp'
  107. sendln com_temp
  108. pause 1
  109.  
  110. ;現Webアプリバックアップ
  111. if isfirst then
  112. messagebox '現行のプログラムがあればバックアップします' alart
  113. endif
  114. com_temp = 'mv -f '
  115. strconcat com_temp destination_directory
  116. strconcat com_temp project_name
  117. strconcat com_temp ' '
  118. strconcat com_temp destination_directory
  119. strconcat com_temp 'rev/'
  120. strconcat com_temp project_name
  121. sendln com_temp
  122. pause 1
  123.  
  124. ;新ファイル配置
  125. ; 移動
  126. if isfirst then
  127. messagebox '新しいプログラムを配置します' alart
  128. endif
  129. com_temp = 'cd '
  130. strconcat com_temp temp_directory
  131. sendln com_temp
  132.  
  133. ; 解凍
  134. com_temp = 'unzip '
  135. strconcat com_temp project_name
  136. strconcat com_temp '.zip'
  137. sendln com_temp
  138. if isfirst then
  139. messagebox 'ファイルの解凍が終わったらOKを押してください' alart
  140. else
  141. ; 適当な長さで次行くので調節すること
  142. pause 5
  143. endif
  144. ; zipファイル削除
  145. com_temp = 'rm --interactive=never '
  146. strconcat com_temp project_name
  147. strconcat com_temp '.zip'
  148. sendln com_temp
  149. pause 1
  150.  
  151. if isfirst then
  152. messagebox '解凍したものを移動します、名前も変更します' alart
  153. endif
  154. com_temp = 'mv '
  155. strconcat com_temp unzip_directory
  156. strconcat com_temp ' '
  157. strconcat com_temp destination_directory
  158. strconcat com_temp project_name
  159. sendln com_temp
  160.  
  161. ;ログフォルダ作成
  162. com_temp = 'mkdir -p /var/log/aspnetcore/'
  163. strconcat com_temp project_name
  164. strconcat com_temp '/'
  165. sendln com_temp
  166. com_temp = 'chown '
  167. strconcat com_temp nginx_user
  168. strconcat com_temp ' /var/log/aspnetcore/'
  169. sendln com_temp
  170. strconcat com_temp project_name
  171. strconcat com_temp '/'
  172. sendln com_temp
  173.  
  174. ;nlog.configを差し替え
  175. com_temp = 'mv -f '
  176. strconcat com_temp destination_directory
  177. strconcat com_temp project_name
  178. strconcat com_temp '/nlog_Production.config '
  179. strconcat com_temp destination_directory
  180. strconcat com_temp project_name
  181. strconcat com_temp '/nlog.config'
  182. sendln com_temp
  183.  
  184. pause 1
  185.  
  186. if isfirst then
  187. messagebox '解凍フォルダを削除します' alart
  188. endif
  189. com_temp = 'rm -r --interactive=never '
  190. strconcat com_temp temp_directory
  191. sendln com_temp
  192. pause 1
  193.  
  194. if isfirst then
  195. str = 'このマクロはマイグレーションを行いません。\nDB変更を行う場合、すぐ行ってください。\nそういう作業がある場合はDDLを準備してマクロに組み込んでください。'
  196. strspecial str
  197. messagebox str '注意!'
  198. endif
  199.  
  200. if isfirst then
  201. messagebox '初回なのでサービス化を行います。' alart
  202. messagebox 'サービス登録に必要なファイルを作成します。' alart
  203. service_file = '/etc/systemd/system/'
  204. strconcat service_file project_name
  205. strconcat service_file '-webapp.service'
  206. com_temp = 'mv -f '
  207. strconcat com_temp service_file
  208. strconcat com_temp ' /etc/systemd/system/bk_'
  209. strconcat com_temp appname
  210. strconcat com_temp '-webapp.service'
  211. sendln com_temp
  212. com_temp = 'touch '
  213. strconcat com_temp service_file
  214. sendln com_temp
  215. pause 1
  216.  
  217. inputbox 'DBパスワードを教えて。' '登録に必要'
  218. db_password = inputstr
  219.  
  220. ; ひたすら文字を書き込む
  221. com_temp = "echo '[Unit]' >> "
  222. strconcat com_temp service_file
  223. sendln com_temp
  224.  
  225. com_temp = "echo 'Description="
  226. strconcat com_temp project_name
  227. strconcat com_temp " .NET Web API App running on CentOS7' >> "
  228. strconcat com_temp service_file
  229. sendln com_temp
  230.  
  231. com_temp = "echo '' >> "
  232. strconcat com_temp service_file
  233. sendln com_temp
  234.  
  235. com_temp = "echo '[Service]' >> "
  236. strconcat com_temp service_file
  237. sendln com_temp
  238.  
  239. com_temp = "echo 'WorkingDirectory="
  240. strconcat com_temp destination_directory
  241. strconcat com_temp project_name
  242. strconcat com_temp "' >> "
  243. strconcat com_temp service_file
  244. sendln com_temp
  245.  
  246. com_temp = "echo 'ExecStart=/usr/bin/dotnet "
  247. strconcat com_temp destination_directory
  248. strconcat com_temp project_name
  249. strconcat com_temp "/"
  250. strconcat com_temp project_name
  251. strconcat com_temp ".dll"
  252. strconcat com_temp "' >> "
  253. strconcat com_temp service_file
  254. sendln com_temp
  255.  
  256. com_temp = "echo 'Restart=always' >> "
  257. strconcat com_temp service_file
  258. sendln com_temp
  259.  
  260. com_temp = "echo 'RestartSec=10' >> "
  261. strconcat com_temp service_file
  262. sendln com_temp
  263.  
  264. com_temp = "echo 'SyslogIdentifier=dotnet-example' >> "
  265. strconcat com_temp service_file
  266. sendln com_temp
  267.  
  268. com_temp = "echo 'User="
  269. strconcat com_temp nginx_user
  270. strconcat com_temp "' >> "
  271. strconcat com_temp service_file
  272. sendln com_temp
  273.  
  274. com_temp = "echo 'Environment=ASPNETCORE_ENVIRONMENT=Production' >> "
  275. strconcat com_temp service_file
  276. sendln com_temp
  277.  
  278. com_temp = "echo 'Environment=DOTNET_PRINT_TELEMETRY_MESSAGE=false' >> "
  279. strconcat com_temp service_file
  280. sendln com_temp
  281.  
  282. com_temp = "echo 'Environment=DATABASE_PASSWORD="
  283. strconcat com_temp db_password
  284. strconcat com_temp "' >> "
  285. strconcat com_temp service_file
  286. sendln com_temp
  287.  
  288. com_temp = "echo '' >> "
  289. strconcat com_temp service_file
  290. sendln com_temp
  291.  
  292. com_temp = "echo '[Install]' >> "
  293. strconcat com_temp service_file
  294. sendln com_temp
  295.  
  296. com_temp = "echo 'WantedBy=multi-user.target' >> "
  297. strconcat com_temp service_file
  298. sendln com_temp
  299.  
  300. messagebox 'サービス登録を行います。' alart
  301. com_temp = 'systemctl enable '
  302. strconcat com_temp project_name
  303. strconcat com_temp '-webapp'
  304. sendln com_temp
  305. pause 1
  306.  
  307. endif
  308.  
  309. ;Web起動
  310. messagebox 'Webを起動します。' alart
  311. com_temp = 'systemctl start '
  312. strconcat com_temp project_name
  313. strconcat com_temp '-webapp'
  314. sendln com_temp
  315. pause 1
  316.  
  317. ;終わり
  318. messagebox 'デプロイ作業が終了しました。サーバ内から繋いでみてください。' alart
  319.  
  320. end
  321.  
  322.  
  323. :label_end
  324. alart = "終了"
  325. str = "処理を終了します。"
  326. strspecial str
  327. messagebox str alart
  328. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement