Question

I'm looking for a way to automatically run mono fastcgi 4 server as process as user www-data like apache runs. Line

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

works ok but it runs as root if invoked from root.

I tried

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 &

as in /etc/init.d/monoserve script below but it returns error

Error: Pipe socket is not bound.

It looks like parameters are passed incorrectly. How to fix it ? Which is best practice to run mono fastcgi server for Nginx in Debian ?

#!/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
Était-ce utile?

La solution

Please don't use su. use debian's start-stop-daemon instead. All you need is already there.

Autres conseils

su -c requires its command to be enclosed in quotes, like

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" & 
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top