Coming one day: animeBSD Wiki (also in this post: nginx init script)

Probably. One day.

It’ll be more like personal notepad though.

That is, after I finished creating theme for this blog(?).

In the meantime, have this init script for nginx on OpenSolaris:

#!/bin/sh

NAME=nginx

runuser=root
basepath=/usr/local/$NAME
pid=$basepath/logs/$NAME.pid

KILL=/usr/bin/pkill
ISRUN="-e $pid"
command="$basepath/sbin/$NAME"

cmd_run="/usr/bin/pfexec /usr/bin/sudo -u $runuser"

echo "Querying $NAME..."

command_start()
{
    if [ $ISRUN ]
    then
      stat="already running"
    else
      $cmd_run $command
      stat="started"
    fi
}

command_stop()
{
    if [ $ISRUN ]
    then
      $cmd_run $KILL $NAME
      stat="stopped"
    else
      stat="not running"
    fi
}

case "$1" in
   start)
    command_start
   ;;
   stop)
    command_stop
   ;;
   forcestop)
    ISRUN=1
    command_stop
   ;;
   restart)
    ISRUN=1
    command_stop
    ISRUN=""
    command_start
    stat="restarted"
   ;;
   test)
    stat="err"
    $cmd_run $command -t
    errmsg=""
   ;;
   *)
    stat="err"
    errmsg="Usage: start|(force)stop|restart|test"
   ;;
esac

if [ "$stat" = "err" ]
then
   echo $errmsg
else
   printf "$NAME: "
   echo $stat

Also usable for other system. Just modify the cmd_run (and path, if needed. You may also want to specify the config path).

Note that it doesn’t specify the config path at all. And it stops the process using pkill which probably not desirable for some people.

restart = forcestop then (force) start

Leave a Reply

Your email address will not be published. Required fields are marked *