LoginSignup
1
0

More than 3 years have passed since last update.

Google cloud platform(GCP) でのstartup-scriptにtmuxを動かしたいとき。

Posted at

問題点

単純にtmuxを使うために
startup-scriptに
tmux new -s hogehoge
で動かそうとすると
root権限での動作のため

sudo journalctl -u google-startup-scripts.service

Dec 22 16:41:56 <product_name> systemd[1]: Starting Google Compute Engine Startup Scripts...
Dec 22 16:41:58 <product_name> startup-script[2058]: INFO Starting startup scripts.
Dec 22 16:41:58 <product_name> startup-script[2058]: INFO Found startup-script in metadata.
Dec 22 16:41:58 <product_name> startup-script[2058]: INFO startup-script: open terminal failed: not a terminal
Dec 22 16:41:59 <product_name> startup-script[2058]: INFO startup-script: no server running on /tmp/tmux-0/default
Dec 22 16:41:59 <product_name> startup-script[2058]: INFO startup-script: Return code 1.
Dec 22 16:41:59 <product_name> startup-script[2058]: INFO Finished running startup scripts.
Dec 22 16:41:59 <product_name> systemd[1]: google-startup-scripts.service: Succeeded.
Dec 22 16:41:59 <product_name> systemd[1]: Finished Google Compute Engine Startup Scripts.

というログが残ります。

ならば

実行させるユーザーを変えてやればいい

カスタムメタデータのstartup-scriptに

#! /bin/bash
sudo -u <user_name> tmux new-session -s hogehoge -d
tmux send-keys -t hogehoge:0 ls

を設定することで、実行させるユーザーを指定して、
指定した名前のtmuxを起動させることができる。

日本語での情報がほぼなかったのでここに記す。

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0