зеркало из https://github.com/telerik/wazuh-api.git
Systemd unit and installer
This commit is contained in:
Родитель
4a738c812d
Коммит
57e31c3a46
|
@ -0,0 +1,79 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Installer for Wazuh-API daemon
|
||||||
|
# Wazuh Inc.
|
||||||
|
# April 11, 2016
|
||||||
|
|
||||||
|
I_OWNER="root"
|
||||||
|
I_GROUP="root"
|
||||||
|
I_XMODE="755"
|
||||||
|
I_FMODE="644"
|
||||||
|
I_SYSTEMD="/etc/systemd/system"
|
||||||
|
I_SYSVINIT="/etc/init.d"
|
||||||
|
|
||||||
|
OSSEC_CONF="/etc/ossec-init.conf"
|
||||||
|
DEF_OSSDIR="/var/ossec"
|
||||||
|
|
||||||
|
# Test root permissions
|
||||||
|
|
||||||
|
if [ "$USER" != "root" ]; then
|
||||||
|
echo "Warning: Please run this script with root permissions."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Directory where OSSEC is installed
|
||||||
|
|
||||||
|
if ! [ -f $OSSEC_CONF ]; then
|
||||||
|
echo "Can't find $OSSEC_CONF. Is OSSEC installed?"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
. $OSSEC_CONF
|
||||||
|
|
||||||
|
if [ -z "$DIRECTORY" ]; then
|
||||||
|
DIRECTORY=$DEF_OSSDIR
|
||||||
|
fi
|
||||||
|
|
||||||
|
APP_PATH="${DIRECTORY}/api/app.js"
|
||||||
|
LOG_PATH="${DIRECTORY}/logs/api.log"
|
||||||
|
|
||||||
|
if ! [ -f $APP_PATH ]; then
|
||||||
|
echo "Can't find $APP_PATH. Is Wazuh-API installed?"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Binary name for NodeJS
|
||||||
|
|
||||||
|
BIN_DIR=$(which nodejs 2> /dev/null)
|
||||||
|
|
||||||
|
if [ "X$BIN_DIR" = "X" ]; then
|
||||||
|
BIN_DIR=$(which node 2> /dev/null)
|
||||||
|
|
||||||
|
if [ "X$BIN_DIR" = "X" ]; then
|
||||||
|
echo "NodeJS binaries not found. Is NodeJS installed?"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Install for systemd
|
||||||
|
|
||||||
|
if [ -n "$(ps -e | egrep ^\ *1\ .*systemd$)" ]; then
|
||||||
|
sed -i "s:^ExecStart=.*:ExecStart=$BIN_DIR $APP_PATH >> $LOG_PATH:g" wazuh-api.service
|
||||||
|
install -m $I_FMODE -o $I_OWNER -g $I_GROUP wazuh-api.service $I_SYSTEMD
|
||||||
|
systemctl enable wazuh-api
|
||||||
|
systemctl daemon-reload
|
||||||
|
systemctl start wazuh-api
|
||||||
|
echo "Daemon installed successfully. Please check the status running:"
|
||||||
|
echo " systemctl status wazuh-api"
|
||||||
|
|
||||||
|
# Install for SysVinit
|
||||||
|
|
||||||
|
elif [ -n "$(ps -e | egrep ^\ *1\ .*init$)" ]; then
|
||||||
|
sed -i "s:^BIN_DIR=.*:BIN_DIR=\"$BIN_DIR\":g" wazuh-api
|
||||||
|
sed -i "s:^APP_PATH=.*:APP_PATH=\"$APP_PATH\":g" wazuh-api
|
||||||
|
sed -i "s:^LOG_PATH=.*:LOG_PATH=\"$LOG_PATH\":g" wazuh-api
|
||||||
|
insserv wazuh-api
|
||||||
|
service wazuh-api start
|
||||||
|
else
|
||||||
|
echo "Unknown init system. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
|
@ -21,41 +21,24 @@
|
||||||
# sudo systemctl daemon-reload
|
# sudo systemctl daemon-reload
|
||||||
# sudo systemctl restart wazuh-api
|
# sudo systemctl restart wazuh-api
|
||||||
|
|
||||||
. /etc/ossec-init.conf
|
PID_PATH="/var/run/wazuh-api.pid"
|
||||||
|
BIN_DIR=
|
||||||
if [ "X${DIRECTORY}" = "X" ]; then
|
APP_PATH=
|
||||||
DIRECTORY="/var/ossec"
|
LOG_PATH=
|
||||||
fi
|
|
||||||
|
|
||||||
BIN_DIR=$(which nodejs 2> /dev/null)
|
|
||||||
|
|
||||||
if [ "X$BIN_DIR" = "X" ]; then
|
|
||||||
BIN_DIR=$(which node 2> /dev/null)
|
|
||||||
|
|
||||||
if [ "X$BIN_DIR" = "X" ]; then
|
|
||||||
echo "NodeJS binaries not found"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
PID_DIR="/var/run/wazuh-api.pid"
|
|
||||||
APP_PATH="${DIRECTORY}/api/app.js"
|
|
||||||
LOG_DIR="${DIRECTORY}/logs/api.log"
|
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
if [ ! -f $PID_DIR ]; then
|
if [ ! -f $PID_PATH ]; then
|
||||||
($BIN_DIR $APP_PATH >> $LOG_DIR) & echo $!>$PID_DIR
|
($BIN_DIR $APP_PATH >> $LOG_PATH) & echo $!>$PID_PATH
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
if [ -f $PID_DIR ]; then
|
if [ -f $PID_PATH ]; then
|
||||||
kill `cat $PID_DIR`
|
kill `cat $PID_PATH`
|
||||||
rm $PID_DIR
|
rm $PID_PATH
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
start)
|
start)
|
||||||
start
|
start
|
||||||
|
@ -74,3 +57,4 @@ status)
|
||||||
echo "*** Usage: $0 {start|stop|restart|status}"
|
echo "*** Usage: $0 {start|stop|restart|status}"
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
# WAZUH API Service (Systemd unit)
|
||||||
|
# Wazuh Inc.
|
||||||
|
# April 11, 2016
|
||||||
|
|
||||||
|
[Unit]
|
||||||
|
Description=Wazuh API daemon
|
||||||
|
Documentation=http://wazuh-documentation.readthedocs.org/en/latest/ossec_api.html
|
||||||
|
After=network-online.target
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
ExecStart=
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
|
Загрузка…
Ссылка в новой задаче