go ソケットファイル名 動的 / サービス登録で、問題発覚

カテゴリー: 学習  閲覧数:310 配信日:2018-05-02 23:27


go build 出力先指定


named files must be .go files
Goでディレクトリ&ファイル名を指定してビルド

go 実行ファイル名取得


ログから取得する方法
log.Lshortfile
・うまくいかない
・理由不明
# go build goweb.go
# command-line-arguments
./goweb.go:21:29: cannot convert "/run/go/" (type untyped string) to type int
./goweb.go:21:29: invalid operation: "/run/go/" + log.Lshortfile (mismatched types string and int)
./goweb.go:22:45: cannot convert "/run/go/" (type untyped string) to type int
./goweb.go:22:45: invalid operation: "/run/go/" + log.Lshortfile (mismatched types string and int)
./goweb.go:26:25: cannot convert "/run/go/" (type untyped string) to type int
./goweb.go:26:25: invalid operation: "/run/go/" + log.Lshortfile (mismatched types string and int)
./goweb.go:27:35: cannot convert "/run/go/" (type untyped string) to type int
./goweb.go:27:35: invalid operation: "/run/go/" + log.Lshortfile (mismatched types string and int)

[Go] ファイル名、行数、関数名、スタックトレースをランタイム時に取得する


Go で実行ファイルのパスを取得 - Qiita
Goのpathとfilepathでは動作が異なる Windowsでも正しくパスを扱う - Qiita
Big Sky :: Golang で物理ファイルの操作に path/filepath でなく path を使うと爆発します。


# cat /etc/nginx/conf.d/go-demo.w4c.work.conf
server {
   listen       80;
   server_name  go-demo.w4c.work;
   root   /var/◇◇/w4c.work/go-demo.w4c.work;
   #index  index.php index.html index.htm index.go;

   #listen.owner = nginx;
   #listen.group = nginx;
   #listen.mode = 0777;

   #デフォルト 60秒を120秒までアップ
   fastcgi_read_timeout 120;  

   #location / {
       #fastcgi_pass  unix:/run/go/go-fcgi.sock;
   location ~ ^/demo.*/(.*)\.go$ {
       fastcgi_pass  unix:/run/go/$1.sock;
       #fastcgi_pass  127.0.0.1:9000;
       include       fastcgi_params;
   }
}






# go build goweb.go
# mv /var/www/◇◇/go-demo.w4c.work/demo/goweb /opt/goweb
mv: `/opt/goweb' を上書きしますか?

y
# go build goweb5.go
# mv /var/www/◇◇/go-demo.w4c.work/demo/goweb5 /opt/goweb5


1サービスに付き,1つ起動させる仕様

[Service] ExecStart 複数
・出来ない


# vi /etc/systemd/system/goweb.service
# systemctl restart goweb.service
# systemctl restart nginx.service

serviceタイプUnitの設定ファイル
systemdを用いたプログラムの自動起動 - Qiita
centos - CentOS7サービス登録する際、[Service] ExecStartで複数起動指定したい - スタック・オーバーフロー


linux - Systemd with multiple execStart - Stack Overflow
Controlling a Multi-Service Application with systemd - Ales Nosek - The Software Practitioner