0

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
Andrus
  • 26,339
  • 60
  • 204
  • 378

2 Answers2

0

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" & 
miniBill
  • 1,743
  • 17
  • 41
0

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

Michael Tabolsky
  • 3,429
  • 2
  • 18
  • 11
  • I tried `start-stop-daemon -v -c www-data --start --exec ${MONOSERVER} -- /applications=${WEBAPPS} /maxconns=100 /maxreqs=100 /printlog /loglevels=Error,Warning. /logfile=/var/log/nginx/fastcgi-mono-server.log /socket=tcp:127.0.0.1:9000 & ` is this best solution ? How to stop it ? – Andrus Dec 10 '13 at 18:04
  • --stop ? you don't run it separately from shell, you do it from init scripts. Just do a `grep start-stop-daemon /etc/init.d/*` to see how is is used. – Michael Tabolsky Dec 10 '13 at 18:11
  • If paramters are changed or it takes too much cpu it should be restarted. Is it ok to use ` kill ${MONOSERVER_PID}` as in question or must start-stop-daemon used ? How to implement restart command ? – Andrus Dec 10 '13 at 18:13
  • @Andrus restarting on demand is totally different but you just use the init script, add restart option there using stop/start sequence, it is an accepted practice. – Michael Tabolsky Dec 10 '13 at 18:15