如何设置主管运行shell脚本

新手上路,请多包涵

设置 Dockerfile 来安装节点 prereqs,然后设置 supervisor 以运行最终的 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"]

然后我想设置 supervisord 来启动几个可能的进程之一,包括一个我已经确认可以正常工作的安装 shell 脚本 install.sh ,它位于应用程序的 /etc 目录:

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

但是,我对主管语法很陌生,我无法让它正确启动 shell 脚本。这就是我的 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'

显然,我没有正确设置主管来运行这个 shell 脚本——我搞砸了部分语法吗?

原文由 fox 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 535
1 个回答

我发现最好的方法是设置这个:

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

原文由 epineda 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题