システムのデプロイメント

ベアボーンサーバ


---------------------------------------------------------

■発話サーバ(example.js)インストール手順

---------------------------------------------------------
【方針】
・発話サーバは~/pill-reminderに設置する

---------------------------------------------------------
①ホームディレクトリ内にディレクトリpill-reminderを作成する
---------------------------------------------------------
mtanaka@semi2014vpn:~$ mkdir pill-reminder

---------------------------------------------------------
②Nodejs 初期化
---------------------------------------------------------
mtanaka@semi2014vpn:~$ cd pill-reminder/
mtanaka@semi2014vpn:~/pill-reminder$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.

See `npm help json` for definitive documentation on these fields
and exactly what they do.

Use `npm install ` afterwards to install a package and
save it as a dependency in the package.json file.

Press ^C at any time to quit.
package name: (pill-reminder)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /home/mtanaka/pill-reminder/package.json:

{
  "name": "pill-reminder",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


Is this OK? (yes) y
---------------------------------------------------------
③google-home-notifier インストール
---------------------------------------------------------
mtanaka@semi2014vpn:~/pill-reminder$ npm install google-home-notifier

> mdns@2.5.1 install /home/mtanaka/pill-reminder/node_modules/mdns
> node-gyp rebuild

make: ディレクトリ '/home/mtanaka/pill-reminder/node_modules/mdns/build' に入ります
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_sd.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_service_browse.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_service_enumerate_domains.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_service_get_addr_info.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_service_process_result.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_service_ref.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_service_ref_deallocate.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_service_ref_sock_fd.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_service_register.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_service_resolve.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/dns_service_update_record.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/mdns_utils.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/network_interface.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/socket_watcher.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/txt_record_ref.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/txt_record_create.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/txt_record_deallocate.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/txt_record_set_value.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/txt_record_get_length.o
  CXX(target) Release/obj.target/dns_sd_bindings/src/txt_record_buffer_to_object.o
  SOLINK_MODULE(target) Release/obj.target/dns_sd_bindings.node
  COPY Release/dns_sd_bindings.node
make: ディレクトリ '/home/mtanaka/pill-reminder/node_modules/mdns/build' から出ます

> protobufjs@6.8.8 postinstall /home/mtanaka/pill-reminder/node_modules/protobufjs
> node scripts/postinstall


> ngrok@2.3.0 postinstall /home/mtanaka/pill-reminder/node_modules/ngrok
> node ./postinstall.js

ngrok - unpacking binary
ngrok - binary unpacked to /home/mtanaka/pill-reminder/node_modules/ngrok/bin/ngrok
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN pill-reminder@1.0.0 No description
npm WARN pill-reminder@1.0.0 No repository field.

+ google-home-notifier@1.2.0
added 142 packages from 160 contributors and audited 279 packages in 89.107s
found 0 vulnerabilities

---------------------------------------------------------
④google-tts-apiの更新
---------------------------------------------------------
mtanaka@semi2014vpn:~/pill-reminder$ vi node_modules/google-home-notifier/package.json

  "dependencies": {
    "body-parser": "^1.15.2",
    "castv2-client": "^1.1.2",
    "express": "^4.14.0",
    "google-tts-api": "0.0.4", ←ココ
    "mdns": "^2.3.3",
    "ngrok": "^2.2.4"
  },

mtanaka@semi2014vpn:~/pill-reminder$ cd node_modules/google-home-notifier/
mtanaka@semi2014vpn:~/pill-reminder/node_modules/google-home-notifier$ npm update google-tts-api
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN google-home-notifier@1.2.0 No repository field.

+ google-tts-api@0.0.4
added 8 packages from 7 contributors and audited 8 packages in 1.32s
found 0 vulnerabilities

---------------------------------------------------------
⑤node_modules/google-tts-api/lib/key.jsの修正
---------------------------------------------------------
mtanaka@semi2014vpn:~/pill-reminder/node_modules/google-home-notifier$ cd ~/pill-reminder/
mtanaka@semi2014vpn:~/pill-reminder$ cp node_modules/google-tts-api/lib/key.js node_modules/google-tts-api/lib/key.js.bkup
mtanaka@semi2014vpn:~/pill-reminder$ vi node_modules/google-tts-api/lib/key.js

[修正内容]
var fetch = require('isomorphic-fetch');
var host = 'https://translate.google.com';

/**
 * Get Key from https://translate.google.com
 *
 * @param   {Number!} timeout  default is 10000ms
 * @return  Promise(key: String)
 */
module.exports = function (timeout) {
  return fetch(host, {
    timeout: timeout || 10 * 1000
  })
  .then(function (res) {
    if (res.status !== 200) {
      throw new Error('request to ' + host + ' failed, status code = ' + res.status + ' (' + res.statusText + ')');
    }
    return res.text();
  })
  .then(function(html){
    // tkk:'432648.2912219588'
    //const regexp = /tkk:('[0-9]+.[0-9]+')/g;
    const regexp = /tkk:'([0-9]+.[0-9]+)'/g;
    var match = html.match(regexp);
    if(!match)throw new Error('get key failed from google');
    console.log(match[0]);
    return match[0];
  });
};
---------------------------------------------------------
⑥ngrokのインストール
---------------------------------------------------------
mtanaka@semi2014vpn:~/pill-reminder$ npm install ngrok

> ngrok@2.3.0 postinstall /home/mtanaka/pill-reminder/node_modules/google-home-notifier/node_modules/ngrok
> node ./postinstall.js

ngrok - unpacking binary
ngrok - binary unpacked to /home/mtanaka/pill-reminder/node_modules/google-home-notifier/node_modules/ngrok/bin/ngrok

> ngrok@3.2.5 postinstall /home/mtanaka/pill-reminder/node_modules/ngrok
> node ./postinstall.js

ngrok - cached download found at /home/mtanaka/.ngrok/aHR0c...........................................bWQ2NC56aXA=.zip
ngrok - unpacking binary
ngrok - binary unpacked to /home/mtanaka/pill-reminder/node_modules/ngrok/bin/ngrok
npm WARN pill-reminder@1.0.0 No description
npm WARN pill-reminder@1.0.0 No repository field.

+ ngrok@3.2.5
added 10 packages from 42 contributors, removed 1 package, updated 2 packages and audited 412 packages in 12.895s
found 0 vulnerabilities
---------------------------------------------------------
⑦発話サーバ起動テスト
---------------------------------------------------------
mtanaka@semi2014vpn:~/pill-reminder$ node example.js
*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see 
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see 
2019-10-20 10:06:29.572: Endpoints:
2019-10-20 10:06:29.578:     http://192.168.10.254:8091/google-home-notifier
2019-10-20 10:06:30.703:     https://8b39127f.ngrok.io/google-home-notifier
2019-10-20 10:06:30.704: GET example:
2019-10-20 10:06:30.704: curl -X GET https://8b39127f.ngrok.io/google-home-notifier?text=Hello+Google+Home
2019-10-20 10:06:30.705: POST example:
2019-10-20 10:06:30.705: curl -X POST -d "text=Hello Google Home" https://8b39127f.ngrok.io/google-home-notifier
---------------------------------------------------------
⑧発話サーバテスト
---------------------------------------------------------
・TeraTermから
curl -X GET https://8b39127f.ngrok.io/google-home-notifier?text=Hello+Google+Home
curl -X POST -d "text=Hello Google Home" https://8b39127f.ngrok.io/google-home-notifier
・ブラウザから
https://8b39127f.ngrok.io/google-home-notifier?text=Hello+Google+Home
・Webサイトから
http://192.168.10.254/~mtanaka/google-home-notifier/speech-client-test.html

---------------------------------------------------------
⑨発話サーバのデーモン化
---------------------------------------------------------
mtanaka@semi2014vpn:~/pill-reminder$ forever start example.js
warn:    --minUptime not set. Defaulting to: 1000ms
warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
info:    Forever processing file: example.js

[ログ表示]
mtanaka@semi2014vpn:~/pill-reminder$ forever list
info:    Forever processes running
data:        uid  command             script     forever pid  id logfile                         uptime
data:    [0] dZTz /usr/local/bin/node example.js 3311    3318    /home/mtanaka/.forever/dZTz.log 0:0:26:58.44699999999989
mtanaka@semi2014vpn:~/pill-reminder$ cat /home/mtanaka/.forever/dZTz.log
*** WARNING *** The program 'node' uses the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see 
*** WARNING *** The program 'node' called 'DNSServiceRegister()' which is not supported (or only supported partially) in the Apple Bonjour compatibility layer of Avahi.
*** WARNING *** Please fix your application to use the native API of Avahi!
*** WARNING *** For more information see 
2019-10-20 10:39:49.642: Endpoints:
2019-10-20 10:39:49.647:     http://192.168.10.254:8091/google-home-notifier
2019-10-20 10:39:50.754:     https://e22b7a95.ngrok.io/google-home-notifier
2019-10-20 10:39:50.754: GET example:
2019-10-20 10:39:50.754: curl -X GET https://e22b7a95.ngrok.io/google-home-notifier?text=Hello+Google+Home
2019-10-20 10:39:50.754: POST example:
2019-10-20 10:39:50.754: curl -X POST -d "text=Hello Google Home" https://e22b7a95.ngrok.io/google-home-notifier
mtanaka@semi2014vpn:~/pill-reminder$
---------------------------------------------------------
⑩発話要求サーバの実行
---------------------------------------------------------
mtanaka@semi2014vpn:~/pill-reminder$ ./pill-reminder.sh &

[ログ表示]
mtanaka@semi2014vpn:~/pill-reminder$ tail -f pill-reminder.log
2019-10-20 11:01:02.856: pill-reminder start
2019-10-20 11:01:04.916: 本日の服薬スケジュール:
{
 "drug_notifies": [
  {
   "title": "朝の食後の薬(未)",
   "description": "ディオバン錠20mg 1錠\nメバロチン錠10 1錠",
   "id": "3qjofar2okr9hs4rn9i8j06kcd@google.com",
   "location": "自宅",
   "startTime": "2019-10-19T20:30:00.000Z",
   "endTime": "2019-10-19T21:00:00.000Z",
   "color": "11"
  },
  {
   "title": "昼の食後の薬(未)",
   "description": "\nディオバン錠20mg 1錠\nメバロチン錠10 1錠",
   "id": "4g6h9kmfeolc6tgmkcp8sfbvf1@google.com",
   "location": "自宅",
   "startTime": "2019-10-20T03:00:00.000Z",
   "endTime": "2019-10-20T03:30:00.000Z",
   "color": "11"
  },
  {
   "title": "夜の食後の薬(未)",
   "description": "ディオバン錠20mg 1錠\nメバロチン錠10 1錠",
   "id": "3s71sptblj7hpe6a3a0s3cgf7n@google.com",
   "location": "自宅",
   "startTime": "2019-10-20T08:30:00.000Z",
   "endTime": "2019-10-20T09:00:00.000Z",
   "color": "11"
  },
  {
   "title": "就寝前の薬(未)",
   "description": "ディオバン錠20mg 1錠\nメバロチン錠10 1錠",
   "id": "59f3sh1tu50i0c3jn7dsmihp8a@google.com",
   "location": "自宅",
   "startTime": "2019-10-20T13:00:00.000Z",
   "endTime": "2019-10-20T13:30:00.000Z",
   "color": "11"
  }
 ],
 "num_reminder": "0",
 "taiking_status": "0",
 "status": "0"
}
2019-10-20 11:01:04.918: startTime=2019-10-19T20:30:00.000Z, title=朝の食後の薬(未), id=3qjofar2okr9hs4rn9i8j06kcd@google.com
2019-10-20 11:01:04.918: この予定はすでに終了しているので発話されません。
2019-10-20 11:01:04.919: startTime=2019-10-20T03:00:00.000Z, title=昼の食後の薬(未), id=4g6h9kmfeolc6tgmkcp8sfbvf1@google.com
2019-10-20 11:01:04.919: この予定は58分後に発話されます。
2019-10-20 11:01:04.920: getSpeech: title=昼の食後の薬(未)
2019-10-20 11:01:04.921: getSpeech: match[0]=昼の食後の薬(未), match[1]=昼の食後の薬, match[2]=未
2019-10-20 11:01:04.923: startTime=2019-10-20T08:30:00.000Z, title=夜の食後の薬(未), id=3s71sptblj7hpe6a3a0s3cgf7n@google.com
2019-10-20 11:01:04.924: この予定は388分後に発話されます。
2019-10-20 11:01:04.924: getSpeech: title=夜の食後の薬(未)
2019-10-20 11:01:04.924: getSpeech: match[0]=夜の食後の薬(未), match[1]=夜の食後の薬, match[2]=未
2019-10-20 11:01:04.925: startTime=2019-10-20T13:00:00.000Z, title=就寝前の薬(未), id=59f3sh1tu50i0c3jn7dsmihp8a@google.com
2019-10-20 11:01:04.926: この予定は658分後に発話されます。
2019-10-20 11:01:04.926: getSpeech: title=就寝前の薬(未)
2019-10-20 11:01:04.926: getSpeech: match[0]=就寝前の薬(未), match[1]=就寝前の薬, match[2]=未

※発話要求サーバはcrontabでスケジューリングされる
mtanaka@semi2014vpn:~/pill-reminder$ crontab -l
# m h  dom mon dow   command
0 1 * * * /home/mtanaka/pill-reminder/pill-reminder.sh
リスト1.ベアボーンサーバの実装


0 件のコメント:

コメントを投稿