web-dev-qa-db-ja.com

シェルスクリプトを実行するようにスーパーバイザーを設定する方法

Dockerfileをセットアップしてノードの前提条件をインストールし、最後のnpm installコマンドを実行するためにスーパーバイザーをセットアップします。 VirtualBoxの下でCoreOSのDockerを実行します。

すべてを正しく設定するDockerfileがあります。

FROM ubuntu
MAINTAINER <<Me>>

# Install docker basics
RUN echo "deb http://archive.ubuntu.com/ubuntu precise main universe" > /etc/apt/sources.list
RUN apt-get update
RUN apt-get upgrade -y

# Install dependencies and nodejs
RUN apt-get update
RUN apt-get install -y python-software-properties python g++ make
RUN add-apt-repository ppa:chris-lea/node.js
RUN apt-get update
RUN apt-get install -y nodejs

# Install git
RUN apt-get install -y git

# Install supervisor
RUN apt-get install -y supervisor
RUN mkdir -p /var/log/supervisor

# Add supervisor config file
ADD ./etc/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Bundle app source
ADD . /src

# create supervisord user
RUN /usr/sbin/useradd --create-home --home-dir /usr/local/nonroot --Shell /bin/bash nonroot
RUN chown -R nonroot: /src

# set install script to executable
RUN /bin/chmod +x /src/etc/install.sh

#set up .env file
RUN echo "NODE_ENV=development\nPORT=5000\nRIAK_SERVERS={SERVER}" > /src/.env

#expose the correct port
EXPOSE 5000

# start supervisord when container launches
CMD ["/usr/bin/supervisord"]

そして、アプリケーションのinstall.shディレクトリにある、正常に動作することが確認されているインストールシェルスクリプト/etcを含む、いくつかの可能なプロセスの1つを起動するように監視を設定します。

#!/bin/bash
cd /src; npm install
export PATH=$PATH:node_modules/.bin

ただし、私はスーパーバイザー構文に非常に慣れていないため、シェルスクリプトを正しく起動できません。これが私のsupervisord.confファイルにあるものです。

[supervisord]
nodaemon=true

[program:install]
command=install.sh
directory=/src/etc/
user=nonroot

Dockerfileを実行すると、すべてが正しく実行されますが、イメージを起動すると、次のようになります。

2014-03-15 07:39:56,854 CRIT Supervisor running as root (no user in config file)
2014-03-15 07:39:56,856 WARN Included extra file "/etc/supervisor/conf.d/supervisord.conf" during parsing
2014-03-15 07:39:56,913 INFO RPC interface 'supervisor' initialized
2014-03-15 07:39:56,913 WARN cElementTree not installed, using slower XML parser for XML-RPC
2014-03-15 07:39:56,914 CRIT Server 'unix_http_server' running without any HTTP authentication checking
2014-03-15 07:39:56,915 INFO supervisord started with pid 1
2014-03-15 07:39:57,918 INFO spawnerr: can't find command 'install.sh'
2014-03-15 07:39:58,920 INFO spawnerr: can't find command 'install.sh'

明らかに、私はこのシェルスクリプトを実行するようにスーパーバイザを正しく設定していません-失敗している構文の一部はありますか?

15
fox

私が見つけた最良の方法はこれを設定することでした:

[program:my-program-name]
command = /path/to/my/command.sh
startsecs = 0
autorestart = false
startretries = 1
14
epineda

私はこれを並べ替えたと思います:commandの完全なパスが必要であり、user=nonrootファイルに.confを含める代わりに、su nonrootinstall.shに入れました脚本。

5
fox

supervisor のソースコードをざっと見て、commandにスラッシュ_/_が含まれていないと、 [〜#〜] path [〜#〜]そのファイルの環境変数。これは、シェルを介した実行の動作を模倣します。

次の方法で最初の問題を解決できます。

  1. スクリプトの完全なパスを指定します(自分の答えで行ったように)
  2. commandの前に_./_を付けます。つまり、_./install.sh_です(理論的にはテストされていません)。
  3. commandの前にシェル実行可能ファイルを付けます。つまり、_/bin/bash install.sh_

_user=_が機能しない理由はわかりませんが(実行を修正した後で試しましたか?)、あなた自身の回答で発生した問題はおそらく の誤った使用が原因でしたs これはSudoのようには機能しません。 sは、独自のインタラクティブシェルを作成するため、標準入力を待機している間にハングします。 sでコマンドを実行するには、_-c_フラグ、つまり_su -c "some-program" nonroot_を使用します。必要に応じて、_-s_フラグを使用して明示的なシェルを指定することもできます。

4
XA21X