From a137da643c3bf1349e03b29a32f190fff8a483b3 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Thu, 16 Dec 2010 19:34:22 +0000 Subject: [PATCH] 2010-12-16 Ramon Novoa * pandora_agent_installer, pandora_agent_daemon: Additional changes to run the agent as a different user. Starting and stopping the daemon did not work except as root. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3664 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/unix/ChangeLog | 6 ++++++ pandora_agents/unix/pandora_agent_daemon | 6 +++--- pandora_agents/unix/pandora_agent_installer | 13 ++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index 56a637bc23..716e46a9b5 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,9 @@ +2010-12-16 Ramon Novoa + + * pandora_agent_installer, pandora_agent_daemon: Additional + changes to run the agent as a different user. Starting and + stopping the daemon did not work except as root. + 2010-12-16 Miguel de Dios * DEBIAN/control, DEBIAN/make_deb_package.sh, pandora_console.spec, diff --git a/pandora_agents/unix/pandora_agent_daemon b/pandora_agents/unix/pandora_agent_daemon index 9a1045cdd4..5e698cf425 100755 --- a/pandora_agents/unix/pandora_agent_daemon +++ b/pandora_agents/unix/pandora_agent_daemon @@ -24,6 +24,7 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin PANDORA_PATH=/etc/pandora DAEMON=/usr/bin/pandora_agent LOGFILE=/var/log/pandora/pandora_agent.log +PANDORA_USER=root # This function replace pidof, not working in the same way in different linux distros @@ -73,8 +74,7 @@ case "$1" in echo "Cannot launch again. Aborting." exit 1 fi - PATH=$PATH nohup $DAEMON $PANDORA_PATH 2> $LOGFILE & - rm nohup.out 2> /dev/null + su -c "PATH=$PATH nohup $DAEMON $PANDORA_PATH >/dev/null 2>$LOGFILE &" $PANDORA_USER sleep 2 PANDORA_PID=`pidof_pandora` echo "Pandora FMS Agent is now running with PID $PANDORA_PID" @@ -88,7 +88,7 @@ case "$1" in exit 1 else echo "Stopping Pandora Agent." - kill -9 $PANDORA_PID > /dev/null 2>&1 + su -c "kill -9 $PANDORA_PID >/dev/null 2>&1" $PANDORA_USER fi ;; diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 6589fb47a0..89a8db4d93 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -232,6 +232,9 @@ install () { sed -e "s/^DAEMON\=[.]*/DAEMON\=$PANDORA_BASE_DECODED/g" $DAEMON_SCRIPT > $DAEMON_TEMP mv $DAEMON_TEMP $DAEMON_SCRIPT + + sed -e "s/^PANDORA_USER\=.*/PANDORA_USER\=$PANDORA_USER/g" $DAEMON_SCRIPT > $DAEMON_TEMP + mv $DAEMON_TEMP $DAEMON_SCRIPT fi sed -e "s/^temporal [.]*/temporal $PANDORA_BASE_DECODED/g" $AGENT_CFG > $AGENT_CFG_TEMP @@ -358,6 +361,8 @@ install () { then cp pandora_agent_daemon /etc/rc.pandora_agent_daemon ln -s /etc/rc.pandora_agent_daemon /etc/rc.d/rc2.d/S90pandora_agent_daemon + chmod 755 $PANDORA_STARTUP + chown root:root $PANDORA_STARTUP echo "Pandora FMS agent has been included in /etc/rc.d/rc2.d/S90pandora_agent_daemon" fi @@ -367,6 +372,8 @@ install () { cp pandora_agent_daemon $PANDORA_STARTUP ln -s /sbin/init.d/pandora_agent_daemon /sbin/rc3.d/S90pandora_agent_daemon 2> /dev/null ln -s /sbin/init.d/pandora_agent_daemon /sbin/rc2.d/S90pandora_agent_daemon 2> /dev/null + chmod 755 $PANDORA_STARTUP + chown root:root $PANDORA_STARTUP echo "Pandora FMS agent has been included in /sbin/rcX.d/S90pandora_agent_daemon" fi @@ -375,6 +382,8 @@ install () { PANDORA_STARTUP=/etc/init.d/pandora_agent_daemon cp pandora_agent_daemon $PANDORA_STARTUP ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent_daemon 2> /dev/null + chmod 755 $PANDORA_STARTUP + chown root:root $PANDORA_STARTUP echo "Pandora FMS agent has been included in /etc/rc2.d/S90pandora_agent_daemon" fi @@ -390,11 +399,13 @@ install () { ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent 2> /dev/null ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent 2> /dev/null fi + chmod 755 $PANDORA_STARTUP + chown root:root $PANDORA_STARTUP fi if [ "$OS_NAME" = "FreeBSD" ] then - PANDORA_STARTUP=/usr/local/etc/rc.d/pandora_agent + PANDORA_STARTUP=/usr/local/etc/rc.d/pandora_agent cp FreeBSD/pandora_agent $PANDORA_STARTUP chmod 555 $PANDORA_STARTUP chown root:wheel $PANDORA_STARTUP