shi*_*ams 2 linux init-script systemd
所以我试图在启用 systemd 的系统上启动服务。服务名称是ossec-hids-authdossec(入侵检测软件)中的身份验证引擎(代理)。当我去启动 init 脚本然后 systemctl 超时并且在获取状态时我看到这个错误。
/etc/init.d/ossec-hids-authd status
? ossec-hids-authd.service - LSB: Authentication Daemon for OSSEC-HIDS.
Loaded: loaded (/etc/rc.d/init.d/ossec-hids-authd; bad; vendor preset: disabled)
Active: failed (Result: timeout) since Thu 2018-02-22 07:34:28 UTC; 11min ago
Docs: man:systemd-sysv-generator(8)
Feb 22 07:24:11 ip-10-0-197-117.ec2.internal systemd[1]: Starting LSB: Authentication Daemon for OSSEC-HIDS....
Feb 22 07:24:11 ip-10-0-197-117.ec2.internal ossec-hids-authd[21142]: [39B blob data]
Feb 22 07:24:11 ip-10-0-197-117.ec2.internal systemd[1]: PID file /var/run/ossec-authd.pid not readable (yet?) after start.
Feb 22 07:24:11 ip-10-0-197-117.ec2.internal ossec-hids-authd[21142]: 2018/02/22 07:24:11 ossec-authd: INFO: Started (pid: 21148).
Feb 22 07:34:28 ip-10-0-197-117.ec2.internal systemd[1]: ossec-hids-authd.service start operation timed out. Terminating.
Feb 22 07:34:28 ip-10-0-197-117.ec2.internal systemd[1]: Failed to start LSB: Authentication Daemon for OSSEC-HIDS..
Feb 22 07:34:28 ip-10-0-197-117.ec2.internal systemd[1]: Unit ossec-hids-authd.service entered failed state.
Feb 22 07:34:28 ip-10-0-197-117.ec2.internal systemd[1]: ossec-hids-authd.service failed.
Feb 22 07:40:20 ip-10-0-197-117.ec2.internal ossec-hids-authd[21142]: 2018/02/22 07:40:20 ossec-authd(1225): INFO: SIGNAL [(15)-(Terminated)] Received. Exit Cleaning...
Run Code Online (Sandbox Code Playgroud)
现在在 init 脚本中,这个过程实际上是在创建 pid 文件/var/ossec/var/run而不是/var/run我检查了 pid 文件实际上是在那里创建的。但不知何故 systemctl 无法识别它。
systemd 是否有可能无法识别在外部创建的 pid 文件/var/run,如果是这种情况怎么办?
下面是初始化脚本
#!/bin/sh
#
# ossec-authd Start the OSSEC-HIDS Authentication Daemon
#
# chkconfig: 2345 99 01
# description: Provides key signing for OSSEC Clients
# processname: ossec-authd
# config: /var/ossec/etc/ossec.conf
# pidfile: /var/run/ossec-authd.pid
### BEGIN INIT INFO
# Provides: ossec-authd
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Authentication Daemon for OSSEC-HIDS.
# Description: Provides key signing for OSSEC Clients
### END INIT INFO
# Author: Brad Lhotsky <brad.lhotsky@gmail.com>
NAME=ossec-authd
DAEMON=/var/ossec/bin/ossec-authd
DAEMON_ARGS="-p 1515 2>&1 >> /var/ossec/logs/ossec-authd.log &"
PIDDIR=/var/ossec/var/run
SCRIPTNAME=/etc/init.d/ossec-authd
. /etc/rc.d/init.d/functions
getpid() {
for filename in $PIDDIR/${NAME}*.pid; do
pidfile=$(basename $filename)
pid=$(echo $pidfile |cut -d\- -f 3 |cut -d\. -f 1)
kill -0 $pid &> /dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ]; then
PIDFILE=$filename
PID=$pid
else
rm -f $filename
fi;
done;
}
start() {
echo -n $"Starting $NAME: "
daemon $DAEMON $DAEMON_ARGS
retval=$?
if [ $retval -eq 0 ]; then
echo_success
echo
else
echo_failure
echo
fi
return $retval
}
stop() {
echo -n $"Stopping $NAME: "
getpid
killproc -p $PIDFILE $NAME
retval=$?
echo
return $retval
}
restart() {
stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
getpid
if [ -z $PIDFILE ]; then
status $NAME
else
status -p $PIDFILE $NAME
fi;
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|status}"
exit 2
;;
esac
exit $?
Run Code Online (Sandbox Code Playgroud)
systemd 解析 init 脚本的注释以在启动或daemon-reload命令时生成临时 .service 文件。换线
# pidfile: /var/run/ossec-authd.pid
Run Code Online (Sandbox Code Playgroud)
到
# pidfile: /var/ossec/var/run/ossec-authd.pid
Run Code Online (Sandbox Code Playgroud)
并运行 systemctl daemon-reload
UPD:现在我看到 pid 文件名是在运行时由 authd 生成的,init 脚本必须搜索 $PIDDIR/${NAME}*.pid。
Systemd 无法搜索 pidfile,但可以在没有它的情况下工作。所以你可以尝试# pidfile:完全删除行,或者编写自己的 .service 文件
| 归档时间: |
|
| 查看次数: |
6891 次 |
| 最近记录: |