我正在寻找一种方法来管理通过简单的配置文件和标准接口在不同端口上侦听的多个Twiggy实例。
E.g。我想要一个看起来像
的配置dog 5000 /www/psgi/dog.pl
cow 5001 /www/psgi/holycow.pl
# ...
和/etc/init.d中的脚本一样,用作
sudo service twiggy start
# start all services
sudo service twiggy restart dog
# cow remains intact
# ...
我的一些同事建议runit,它看起来很有希望,但我对它还不够熟悉。
在开始编写我自己的脚本之前,我敢问:是否已存在?
答案 0 :(得分:1)
查看Daemon::Control以了解管理守护程序和自动编写init脚本的方法
答案 1 :(得分:1)
我写了Server::Starter init script for Twiggy::Prefork。但它适用于一个psgi应用程序。也许它对你有用。
这是为Twiggy修改的脚本:
#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/start_server
NAME=start_server
DESC=start_server
RUNDIR=/var/run/start_server
PIDFILE=$RUNDIR/start_server.pid
STATUSFILE=$RUNDIR/start_server.status
PSGI_APP='/path_to_psgi_app/app.pl'
HTTP_SERVER="plackup --no-default-middleware -s Twiggy -a $PSGI_APP"
LOGGER="2>&1 | logger -p daemon.notice -t $DESC"
DAEMON_ARGS="--port=6000 -- $HTTP_SERVER $LOGGER"
if [ ! -e $PSGI_APP ]; then
echo "'$PSGI_APP' does not exist"
exit 1
fi
case "$1" in
start)
echo -n "Starting $DESC: "
mkdir -p $RUNDIR
chown www-data:www-data $RUNDIR
chmod 755 $RUNDIR
if start-stop-daemon --start --name $NAME --pidfile $PIDFILE \
--chuid www-data:www-data --exec /usr/bin/perl --startas \
/bin/bash -- -c "$DAEMON --pid-file $PIDFILE --status-file $STATUSFILE $DAEMON_ARGS &"
then
echo "$NAME."
else
echo "failed"
fi
;;
stop)
echo -n "Stopping $DESC: "
if start-stop-daemon --stop --retry forever/TERM/10 --quiet --oknodo \
--name $NAME --pidfile $PIDFILE
then
echo "$NAME."
else
echo "failed"
fi
sleep 1
;;
reload)
echo -n "Reloading $DESC: "
if $DAEMON --pid-file $PIDFILE --status-file $STATUSFILE --restart
then
echo "$NAME."
else
echo "failed"
fi
;;
restart)
${0} stop
${0} start
;;
status)
echo -n "$DESC is "
if start-stop-daemon --stop --quiet --signal 0 --name ${NAME} --pidfile ${PIDFILE}
then
echo "running"
else
echo "not running"
exit 1
fi
;;
esac
exit 0