如何在init.d中的其他用户帐户中运行进程

时间:2013-12-09 17:48:07

标签: nginx debian su init.d fastcgi-mono-server

我正在寻找一种自动运行mono fastcgi 4服务器作为用户www-data进程的方法 像apache一样跑。 线

${MONOSERVER} /applications=${WEBAPPS} /printlog /loglevels=Error,Warning 
  /logfile=/var/log/nginx/fastcgi-mono-server.log /socket=tcp:127.0.0.1:9000 &

工作正常但如果从root用户调用则以root身份运行。

我试过

su www-data -c ${MONOSERVER} /applications=${WEBAPPS} /printlog /loglevels=Error,Warning
  /logfile=/var/log/nginx/fastcgi-mono-server.log /socket=tcp:127.0.0.1:9000 &

如下面的/etc/init.d/monoserve脚本,但它返回错误

Error: Pipe socket is not bound.

看起来参数传递不正确。 怎么解决? 在Debian中为Nginx运行mono fastcgi服务器的最佳做法是什么?

#!/bin/sh

### BEGIN INIT INFO
# Provides:          monoserve.sh
# Required-Start:    $local_fs $syslog $remote_fs
# Required-Stop:     $local_fs $syslog $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start fastcgi mono server with hosts
### END INIT INFO

PATH=/opt/mono-3.2/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/opt/mono-3.2/bin/mono
NAME=monoserver
DESC=monoserver

MONOSERVER=$(which fastcgi-mono-server54linklisatud)
MONOSERVER_PID=$(ps auxf | grep fastcgi-mono-server4.exe | grep -v grep | awk '{print $2}')
WEBAPPS="/:/var/www/html/france/"

case "$1" in
        start)
                if [ -z "${MONOSERVER_PID}" ]; then
                        #echo "starting mono server"
                su www-data -c ${MONOSERVER} /applications=${WEBAPPS} /printlog /loglevels=Error,Warning /logfile=/var/log/nginx/fastcgi-mono-server.log /socket=tcp:127.0.0.1:9000 &

                        echo "mono fastcgi server started"
                else
                        #echo ${WEBAPPS}
                        echo "error: mono fastcgi server is already running"
                fi
        ;;
        stop)
                if [ -n "${MONOSERVER_PID}" ]; then
                        kill ${MONOSERVER_PID}
                        echo "mono fastcgi server stopped"
                else
                        echo "error: mono fastcgi server is not running"
                fi
        ;;
esac

exit 0

2 个答案:

答案 0 :(得分:0)

su -c要求将其命令括在引号中,例如

su www-data -c "${MONOSERVER} /applications=${WEBAPPS} /printlog /loglevels=Error,Warning  /logfile=/var/log/nginx/fastcgi-mono-server.log /socket=tcp:127.0.0.1:9000" & 

答案 1 :(得分:0)

请不要使用su。改用debian的start-stop-daemon。你所需要的只是已经存在。