我从源代码构建了 ntpd,该进程将其放入 /usr/local/sbin 中。当然,ntp服务指向/usr/sbin。所以,我想我可以像这样更改 init.d 配置文件中的路径:
### BEGIN INIT INFO
# Provides: ntp
# Required-Start: $network $remote_fs $syslog
# Required-Stop: $network $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Start NTP daemon
### END INIT INFO
PATH=/sbin:/bin:/usr/sbin:/usr/bin
. /lib/lsb/init-functions
DAEMON=/usr/local/sbin/ntpd
PIDFILE=/var/run/ntpd.pid
...[etc]
我更改了以“DAEMON”开头的行以指向新二进制文件的位置。但是,当我尝试重新启动服务时,出现错误:
[ ok ] Stopping NTP server: ntpd.
[....] Starting NTP server: ntpd/usr/local/sbin/ntpd: The 'user' option has been disabled. -- built without --enable-clockctl or --enable-linuxcaps or --enable-solarisprivs
ntpd - NTP daemon program - Ver. 4.2.7p475
Usage: ntpd [ -<flag> [<val>] | --<name>[{=| }<val>] ]... \
[ <server1> ... <serverN> ]
Try 'ntpd --help' for more information.
failed!
如何让服务从 /usr/local/sbin 而不是 /usr/sbin 运行?
解决方案(基于已接受的答案):
显然,在 Linux 上构建时,您需要使用该开关--enable-linuxcaps
。以下是 Debian Wheezy 上所需的步骤:
cd ~/install/ntp-dev-4.2.7p475 # or wherever you have the source unpacked
make clean # clean out the previous build
sudo apt-get install libcap-dev # this library is required by linuxcaps
./configure --enable-linuxcaps # this is the critical switch
make
sudo make install
sudo /etc/init.d/ntp restart # restart ntp
ntpq -c "rv 0 version" # make sure you are running the right version
如上所述,/etc/init.d/ntp 中唯一需要更改的行是 DAEMON 行。
答案1
您已经构建了ntpd
没有--enable-linuxcaps
选项的情况。没有这个ntpd
就无法识别用户选项-u
。
您的选择是:
使用正确的选项重新编译
-u $UGID
从NTPD_OPTS
行中删除/etc/init.d/ntp