2015-07-01 26 views
8

Tôi đang cố gắng chạy một tiến trình trong nền dưới dạng deamon nhưng nó chỉ hoạt động khi tôi sử dụng root làm người dùng.Giám sát trên linux CentOS 7 chỉ hoạt động khi chạy với root

Đây là những gì tôi đã làm.

giám sát cài đặt như đã nói trên trang web của họ

$ yum -y install python-setuptools 

$ easy_install supervisor 

tạo các thư mục cấu hình

$ mkdir -p /etc/supervisor/conf.d 

cư với các thiết lập mặc định

$ echo_supervisord_conf > /etc/supervisor/supervisord.conf 

thêm người dùng mới

$ useradd gogopher 

trên CentOS 7 để làm cho nó tự khởi động tôi phải làm điều này

$ vim /usr/lib/systemd/system/supervisord.service 

thêm vào mã bên dưới

[Unit]                
Description=supervisord - Supervisor process control system for UNIX 
Documentation=http://supervisord.org         
After=network.target             

[Service]               
Type=forking               
ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf    
ExecReload=/usr/bin/supervisorctl reload        
ExecStop=/usr/bin/supervisorctl shutdown        
User=gogopher 

[Install]               
WantedBy=multi-user.target             

bây giờ tôi có thể kích hoạt nó để nó bắt đầu từ ngày khởi động lại. tất cả điều này hoạt động tốt.

$ systemctl enable supervisord 

$ systemctl start supervisord 

$ systemctl status supervisord 

OK

chỉnh sửa tập tin cấu hình để bao gồm các file từ thư mục conf.d

$ vim /etc/supervisor/supervisord.conf 

thêm vào cuối tập tin

[include] 
files = /etc/supervisor/conf.d/*.conf 

thêm một chương trình đơn giản

$ vim /etc/supervisor/conf.d/goapp.conf 

[program:main] 
command=/srv/www/websiteurl.com/bin/main 
autostart=true 
autorestart=true 
startretries=10 
user=gogopher 

$ systemctl restart supervisord

không có lỗi, nhưng quá trình này không hoạt động

nếu tôi khởi động lại không có gì xảy

$ systemctl status supervisord 

cho thấy rằng nó supervisord đang chạy nhưng không phải là chương trình daemon.

nếu tôi chạy

$ supervisorctl reload 

tôi nhận được lỗi

error: <class 'socket.error'>, [Errno 111] Connection refused: file: /usr/lib64/python2.7/socket.py line: 571 

nếu tôi chạy

$ supervisorctl status main 

tôi nhận được lỗi

http://localhost:9001 refused connection 

Tôi đã vô hiệu hóa selinux.

nhưng phần lạ là nếu tôi thay đổi cả hai thư mục đó thành thư mục gốc, nó hoạt động.

Tệp thực thi có thể được thực hiện bởi nhóm người dùng và những người khác.

Vì vậy, tôi không biết điều gì đang diễn ra. Tôi đã nghe nói rằng tôi không nên sử dụng gốc khi người dùng đang chạy máy chủ web vì lý do bảo mật.

+2

bạn đã giải quyết nó? Nếu có, làm thế nào? –

+7

https://imgs.xkcd.com/comics/wisdom_of_the_ancients.png – Basil

Trả lời

4

Đối với tất cả mọi người ở đó có cùng một vấn đề, điều này phù hợp với tôi.

cd 
echo_supervisord_conf > /etc/supervisord.conf 
# content of /etc/supervisord.conf ... 

[supervisorctl] 
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket 

[inet_http_server] ; inet (TCP) server disabled by default 
port=*:9001  ; (ip_address:port specifier, *:port for all iface) - I had all this wrong from my original config. 
username=user 
password=passwd 

Dán nội dung này vào /etc/rc.d/init.d/supervisord (Tôi đang không phải là chủ sở hữu của kịch bản này, bây giờ tôi không nhớ nơi tôi đã nhận nó từ)

#!/bin/sh 
# 
# /etc/rc.d/init.d/supervisord 
# 
# Supervisor is a client/server system that 
# allows its users to monitor and control a 
# number of processes on UNIX-like operating 
# systems. 
# 
# chkconfig: - 64 36 
# description: Supervisor Server 
# processname: supervisord 

# Source init functions 
. /etc/rc.d/init.d/functions 

prog="supervisord" 

prefix="/usr/local/" 
exec_prefix="${prefix}" 
prog_bin="${exec_prefix}/bin/supervisord -c /etc/supervisord.conf" 
PIDFILE="/var/run/$prog.pid" 

start() 
{ 
     echo -n $"Starting $prog: " 
     daemon $prog_bin --pidfile $PIDFILE 
     sleep 1 
     [ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup" 
     echo 
} 

stop() 
{ 
     echo -n $"Shutting down $prog: " 
     [ -f $PIDFILE ] && sleep 1 && killproc $prog || success $"$prog shutdown" 
     echo 
} 

case "$1" in 

start) 
    start 
;; 

stop) 
    stop 
;; 

status) 
     status $prog 
;; 

restart) 
    stop 
    start 
;; 

*) 
    echo "Usage: $0 {start|stop|restart|status}" 
;; 

esac 

Hãy kịch bản thực thi và đăng ký nó như một dịch vụ

sudo chmod +x /etc/rc.d/init.d/supervisord 
sudo chkconfig --add supervisord 
sudo chkconfig supervisord on 

# Start the service 
sudo service supervisord start 

# Stop the service 
sudo service supervisord stop 

# Restart the service 
sudo service supervisord restart 
+1

/etc/rc.d/init.d không còn tồn tại nữa. Bạn cần tạo tập lệnh của mình trong /etc/init.d, vì vậy hãy quan tâm đến đường dẫn. –

Các vấn đề liên quan