centos 编译 start-stop-daemon,支持最新的option(--chdir)

start-stop-daemon 是 debian的工具。

在centos/redhat发布版本中没有此库。为了兼容一些脚本调用此程序,我们需要手工编译此工具。

目前网上能够搜索到的版本是这个版本 http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-2.tar.gz

遗憾的是,你编译运行之后,发现此版本不支持 --chdir的option,

start-stop-daemon --help

start-stop-daemon 1.9.18 for Debian - small and fast C version written by
Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>, public domain.

Usage:
  start-stop-daemon -S|--start options ... -- arguments ...
  start-stop-daemon -K|--stop options ...
  start-stop-daemon -H|--help
  start-stop-daemon -V|--version

Options (at least one of --exec|--pidfile|--user is required):
  -x|--exec <executable>        program to start/check if it is running
  -p|--pidfile <pid-file>       pid file to check
  -c|--chuid <name|uid[:group|gid]>
                change to this user/group before starting process
  -u|--user <username>|<uid>    stop processes owned by this user
  -n|--name <process-name>      stop processes with this name
  -s|--signal <signal>          signal to send (default TERM)
  -a|--startas <pathname>       program to start (default is <executable>)
  -N|--nicelevel <incr>         add incr to the process's nice level
  -b|--background               force the process to detach
  -m|--make-pidfile             create the pidfile before starting
  -R|--retry <schedule>         check whether processes die, and retry
  -t|--test                     test mode, don't do anything
  -o|--oknodo                   exit status 0 (not 1) if nothing done
  -q|--quiet                    be more quiet
  -v|--verbose                  be more verbose
Retry <schedule> is <item>|/<item>/... where <item> is one of
 -<signal-num>|[-]<signal-name>  send that signal
 <timeout>                       wait that many seconds
 forever                         repeat remainder forever
or <schedule> may be just <timeout>, meaning <signal>/<timeout>/KILL/<timeout>

Exit status:  0 = done      1 = nothing done (=> 0 if --oknodo)
              3 = trouble   2 = with --retry, processes wouldn't die

上面没有我需要的--chdir的选项。

继续google搜索(ps: 一般这种英文库的搜索使用google, baidu基本搜索不出有用的东东)

发现一个链接,http://florent.clairambault.fr/get-start-stop-daemon-on-any-linux,它里面介绍了官方的路径。

不过它时间有点久,有些地方需要更正一下。下面就是我的安装过程

wget http://ftp.de.debian.org/debian/pool/main/d/dpkg/dpkg_1.17.25.tar.xz
tar -xf  dpkg_1.17.25.tar.xz
cd dpkg-1.17.25
./configure >/dev/null
make >/dev/null
cd utils
make
sudo cp start-stop-daemon /usr/local/bin/start-stop-daemon  
提示:  make >/dev/null 会报错的,不管它。因为我们只需要后面的 cd utils中的start-stop-daemon

现在运行 start-stop-daemon --help, 结果如下,可以找到我想要的--chdir的选项了。


Usage: start-stop-daemon [<option> ...] <command>

Commands:
  -S|--start -- <argument> ...  start a program and pass <arguments> to it
  -K|--stop                     stop a program
  -T|--status                   get the program status
  -H|--help                     print help information
  -V|--version                  print version

Matching options (at least one is required):
  -p|--pidfile <pid-file>       pid file to check
  -x|--exec <executable>        program to start/check if it is running
  -n|--name <process-name>      process name to check
  -u|--user <username|uid>      process owner to check

Options:
  -g|--group <group|gid>        run process as this group
  -c|--chuid <name|uid[:group|gid]>
                                change to this user/group before starting
                                  process
  -s|--signal <signal>          signal to send (default TERM)
  -a|--startas <pathname>       program to start (default is <executable>)
  -r|--chroot <directory>       chroot to <directory> before starting
  -d|--chdir <directory>        change to <directory> (default is /)
  -N|--nicelevel <incr>         add incr to the process' nice level
  -P|--procsched <policy[:prio]>
                                use <policy> with <prio> for the kernel
                                  process scheduler (default prio is 0)
  -I|--iosched <class[:prio]>   use <class> with <prio> to set the IO
                                  scheduler (default prio is 4)
  -k|--umask <mask>             change the umask to <mask> before starting
  -b|--background               force the process to detach
  -C|--no-close                 do not close any file descriptor
  -m|--make-pidfile             create the pidfile before starting
  -R|--retry <schedule>         check whether processes die, and retry
  -t|--test                     test mode, don't do anything
  -o|--oknodo                   exit status 0 (not 1) if nothing done
  -q|--quiet                    be more quiet
  -v|--verbose                  be more verbose

Retry <schedule> is <item>|/<item>/... where <item> is one of
 -<signal-num>|[-]<signal-name>  send that signal
 <timeout>                       wait that many seconds
 forever                         repeat remainder forever
or <schedule> may be just <timeout>, meaning <signal>/<timeout>/KILL/<timeout>

The process scheduler <policy> can be one of:
  other, fifo or rr

The IO scheduler <class> can be one of:
  real-time, best-effort or idle

Exit status:
  0 = done
  1 = nothing done (=> 0 if --oknodo)
  2 = with --retry, processes would not die
  3 = trouble
Exit status with --status:
  0 = program is running
  1 = program is not running and the pid file exists
  3 = program is not running
  4 = unable to determine status


此blog的源地址:http://blog.csdn.net/wu4long/article/details/13048771

有啥问题欢迎评论。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
linux系统命令start-stop-daemon的源码及二进制,其中也提供了一个服务启动脚本模板。 此程序能帮助你实现将命令行程序变成服务运行,比如将"java -jar xxx.jar" 放在后台执行。 ./start-stop-daemon --help start-stop-daemon 1.9.18 for Debian - small and fast C version written by Marek Michalkiewicz , public domain. Usage: start-stop-daemon -S|--start options ... -- arguments ... start-stop-daemon -K|--stop options ... start-stop-daemon -H|--help start-stop-daemon -V|--version Options (at least one of --exec|--pidfile|--user is required): -x|--exec program to start/check if it is running -p|--pidfile pid file to check -c|--chuid change to this user/group before starting process -w|--chdir change the work directory to 'dir' -u|--user | stop processes owned by this user -n|--name stop processes with this name -s|--signal signal to send (default TERM) -a|--startas program to start (default is ) -N|--nicelevel add incr to the process's nice level -b|--background force the process to detach -m|--make-pidfile create the pidfile before starting -R|--retry check whether processes die, and retry -t|--test test mode, don't do anything -o|--oknodo exit status 0 (not 1) if nothing done -q|--quiet be more quiet -v|--verbose be more verbose Retry is |//... where is one of -|[-] send that signal wait that many seconds forever repeat remainder forever or may be just , meaning //KILL/ Exit status: 0 = done 1 = nothing done (=> 0 if --oknodo) 3 = trouble 2 = with --retry, processes wouldn't die
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值