0

我正在寻找一种方法来自动运行 mono fastcgi 4 服务器作为进程,因为用户 www-data like 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
4

2 回答 2

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" & 
于 2013-12-10T08:54:54.477 回答
0

请不要使用 su。改用 debian 的start-stop-daemon。你需要的一切都已经在那里了。

于 2013-12-10T10:12:02.377 回答