LoginSignup
1
0

More than 5 years have passed since last update.

SlackBotを一時的に静かにさせる。

Last updated at Posted at 2018-06-26

SlackBotで一時停止する方法が見つからなかったので乱暴なやり方で作成。
一応動いております。

@respond_to(r'黙れ|静かにしろ|滅びろ', re.IGNORECASE) #一時的に終了します。100秒立ったら起動します。
def listen_func(message):
    """ room lock  """
    if message.body["channel"] not in CHANNEL_LIST:
        return

    message.reply('100秒ほど寝てきます') # メンション
    try:
        sys.exit()
    finally:
        """os exit. before process start. """
        proc = Popen("sleep 100; bash /root/bot/start.sh",
                        shell=True,
                        #close_fds=True,
                        #preexec_fn=os.setsid
                        )
        logwrite('info', message.body["user"]," : bot stop")
        os._exit(0)

sys.exit()で中途半端に終了(無駄処理?)してfinallyで無理やりサブプロセス(Shellコマンド)呼んでます。

sleep 100; 
bash /root/bot/start.sh

ちなみにStartShellは環境変数を読み込んで実行してるだけです。

start.sh

#!/bin/bash

source ./slackbot_settings.sh


if [ ! -e ./output_log/ ]; then
    mkdir ./output_log
fi

nohup python3 ./run.py  > ./output_log/out.log 2>&1 &

slackbot_settings.sh

export SLACK_BOT_TOKEN=xoxb-##############-##############
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