2016-06-01 2 views
1

ec2의 상자에서 ubunto를 실행하고 있습니다. 나는 기계가 시작 특정 위치에 생성 할 때마다 다음과 같은 명령을 실행하고 싶습니다 : 나는 읽을 linux - rc.local을 사용하여 디렉터리를 변경하고 시작시 명령을 실행하는 방법

sudo nano /etc/rc.local 

을 실행하고 파일을 편집 한

celery -A someapp.tasks --concurrency=1 --loglevel=info worker > output.log 2> errors.log 

#!/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 

그러나 서버가 시작되면 명령이 실행되지 않습니다./home/ubunto/somefolder로 직접 cd하고 celery 명령을 실행하면 예상대로 작업이 시작됩니다. 컴퓨터를 시작할 때마다이 명령을 어떻게 실행할 수 있습니까?

cd /home/ubuntu/somefolder && celery -A someapp.tasks --concurrency=1 --loglevel=info worker >output.log 2> errors.log 
+0

루트 사용자로 "/ home/ubunto/somefolder로 직접 cd"하고 celery 명령을 실행 해 보셨습니까? –

+0

즉 $ sudo celery ...? 나는 그것을 시도하지 않았지만 이것의 허가 의미가 이해해야합니다. – user714852

+0

또는'sudo su -', cd ... 그리고 셀러리 ... 권한 문제가 이미 디렉토리에 영향을 미친 경우 –

답변

2

, 서브 쉘을 사용하여 다음과 같이 작업 디렉토리를 사용해보십시오 다음

sudo vi /etc/crontab 

마지막에이 추가 :

,536,
@reboot cd /home/ubuntu/somefolder/ && sh -e -c 'celery -A someapp.tasks worker -Ofair --loglevel=info > output.log > errors.log' 

건배.

+0

입력 해 주셔서 감사합니다. 나는 둘러싸는 괄호를 시도했지만 주사위는 사용하지 않았다. 내 질문을 업데이트하여 rc.local의 새로운 상태를 반영합니다. – user714852

+0

아하겠습니다. 이거해볼 수 있니? 'cd/home/우분투/somefolder''sh -e -c '셀러리 -A someapp.tasks - concurrency = 1 --loglevel = info worker> output.log 2> errors.log'' – Will

+0

편집했습니다 제안 된 파일 (문제의 업데이트 된 코드)이지만 여전히 주사위가 없습니다. 테스트를 위해 편집 내용을 추가했습니다. 기계를 멈췄다. 그런 다음 다시 시작했습니다. 검사 할 때 셀러리 명령이 실행되지 않았습니다./ – user714852

0

: 당신이 rc.local 년대를 변경하지 않도록

1

당신은 간단하게 사용할 수 있습니다 :이 하나의 시도 할 것

(
    cd /home/ubuntu/somefolder 
    celery -A someapp.tasks --concurrency=1 --loglevel=info worker >output.log 2> errors.log 
) 
exit 0 
관련 문제