【发布时间】:2016-06-02 01:19:47
【问题描述】:
我在 ec2 的一个盒子上运行 ubunto。每次机器启动时,我想在特定目录中执行以下命令:
celery -A someapp.tasks --concurrency=1 --loglevel=info worker > output.log 2> errors.log
我跑了
sudo nano /etc/rc.local
并编辑要读取的文件
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
(
cd /home/ubuntu/somefolder/
sh -e -c 'celery -A someapp.tasks worker -Ofair --loglevel=info > output.log > errors.log'
)
exit 0
但是当服务器启动时,命令不会运行。如果我直接 cd 进入 /home/ubunto/somefolder 并运行 celery 命令,操作将按预期开始。每次机器启动时如何运行这个命令?
【问题讨论】:
-
您是否尝试过以 root 用户身份“直接 cd 进入 /home/ubunto/somefolder 并运行 celery 命令”?
-
即$ sudo celery ... ?我还没有尝试过,但了解这对权限的影响。
-
甚至
sudo su -然后 cd ... 和 celery ...,以防权限问题已经影响到目录 -
celery在哪里?它可能不在默认的$PATH中。 -
@StefanHegny 当我运行
sudo su -时,我无法使用cd /home/ubuntu/somefolder/更改密码。如果我执行ls它什么也不返回。pwd只是给\root。