用于作为单独用户运行应用程序的最佳初始化脚本 [英] Best init script for running an application as a separate user

查看:196
本文介绍了用于作为单独用户运行应用程序的最佳初始化脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在用户帐户(基于Plack)运行的应用程序,并且需要一个初始化脚本。

I have an application that runs in a user account (Plack-based) and want an init script.

看起来像sudo $ user start_server一样简单。 ..。我刚写了一个使用start-stop-daemon的LSB脚本,它真的很笨拙和冗长。它不觉得正确的方式。

It seems as easy as "sudo $user start_server ...". I just wrote an LSB script using start-stop-daemon and it is really clumsy and verbose. It doesn't feel like the right way.

在练习一下,查看一个例子之后,我仍然不确定最好的方法这是我没有发现的一个有吸引力的指南。

After scouring for a bit and looking at a log of examples, I'm still not sure what the best way to do this is and there isn't a cohesive guide that I've found.

现在我正在使用它:

start-stop-daemon --background --quiet --start --pidfile $PIDFILE \
                --make-pidfile --chuid $DAEMONUSER \
                --exec $DAEMON -- $DAEMON_OPTS

使用DAEMON和DAEMON_OPTS作为: p>

With DAEMON and DAEMON_OPTS as:

DAEMON="/home/mediamogul/perl5/perlbrew/perls/current/bin/start_server"
DAEMON_OPTS="--port $PORT -- starman --workers $WORKERS /home/mediamogul/MediaMogul/script/mediamogul.psgi"


$ b $这样就需要我调整如何检测运行,因为它是一个perl脚本,所以perl显示为命令而不是start_server。

This then requires me to adjust how to detect running, because it's a perl script so perl is showing up as the command and not "start_server".

我从一个perlbre运行这个w这个用户帐户,所以它与系统perl完全分开,这就是为什么路径指向用户目录中的perl)

(I'm running this out of a perlbrew on that user account so it is completely separate from the system perl, that's why the paths are pointing to a perl in the user dir)

这是真的最好的方法去做这个吗对我来说似乎非常笨重,但我不是管理员类型。

Is this really the best way to go about doing this? It seems very clunky to me, but I'm not an admin type.

推荐答案

您可以使用 - pid 选项到starman,让它在应用程序启动时写入PID,如果你使用相同的文件名,你给start-stop-daemon那么它会很好地工作。

You can use the --pid option to starman to have it write the PID when the app starts, if you use the same filename as you give start-stop-daemon then it will work nicly.

例如,从我的一个init.d脚本中:

For example, from one of my init.d scripts:


SITENAME=mysite
PORT=5000
DIR=/websites/mysite
SCRIPT=bin/app.pl
USER=davidp

PIDFILE = / var / run / site- $ SITENAME.pid

PIDFILE=/var/run/site-$SITENAME.pid

案例$ 1在
开始)
开始-stop-daemon --start --chuid $ USER --chdir $ DIR \
--pidfile = $ PIDFILE \
--exec / usr / local / bin / starman -p $ PORT $ SCRIPT -D --pid $ PIDFILE
;;
stop)
start-stop-daemon --stop --pidfile $ PIDFILE
;;
*)
echo用法:$ SCRIPTNAME {start | stop}>& 2
exit 3
;;
esac

case "$1" in start) start-stop-daemon --start --chuid $USER --chdir $DIR \ --pidfile=$PIDFILE \ --exec /usr/local/bin/starman -- -p $PORT $SCRIPT -D --pid $PIDFILE ;; stop) start-stop-daemon --stop --pidfile $PIDFILE ;; *) echo "Usage: $SCRIPTNAME {start|stop}" >&2 exit 3 ;; esac

这是非常接近你已经在做的,而我承认这是有点笨拙,被授予,但它是有效的 - 让Starman写入PID文件意味着start-stop-daemon可以可靠地启动&停止它。

It's very close to what you are already doing, and I'll admit it is a little clumsy, granted, but it works - having Starman write the PID file means that start-stop-daemon can reliably start & stop it.

这篇关于用于作为单独用户运行应用程序的最佳初始化脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆