Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Add "disable" and "enable" omsagent service commands to /opt/microsof…
Browse files Browse the repository at this point in the history
…t/omsagent/bin/service_control
  • Loading branch information
Nicolas Roy authored and jeffaco committed Nov 30, 2015
1 parent 9b2ead6 commit d57d1c9
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 106 deletions.
64 changes: 63 additions & 1 deletion installer/bundle/bundle_skel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,67 @@ pkg_upd() {
fi
}

# This code is here to allow upgrade from version 47-48
# It was moved to the OMS service_control script but is also needed here
# because version 47-48 do not have the 'disable' option in that script
# and it is called in preinstall
resolve_systemd_paths(){
# Various distributions have different paths for systemd unit files ...
SYSTEMD_UNIT_DIR=""
if pidof systemd 1> /dev/null 2> /dev/null; then
# Be sure systemctl lives where we expect it to
if [ ! -f /bin/systemctl ]; then
echo "FATAL: Unable to locate systemctl program" 1>&2
exit 1
fi

# Find systemd unit directory
UNIT_DIR_LIST="/usr/lib/systemd/system /lib/systemd/system"
for i in ${UNIT_DIR_LIST}; do
if [ -d $i ]; then
SYSTEMD_UNIT_DIR=${i}
return
fi
done

echo "FATAL: Unable to resolve systemd unit directory!" 1>&2
exit 1
fi
}

disable_omsagent_service() {
OMS_SERVICE='/opt/microsoft/omsagent/bin/service_control'
# Stop the server if it's running
if [ -f ${OMS_SERVICE} ]; then
${OMS_SERVICE} stop
fi

resolve_systemd_paths

# Registered as a systemd service?
if [ -f ${SYSTEMD_UNIT_DIR}/omsagent.service ]; then
echo "Unconfiguring OMS agent (systemd) service ..."
/bin/systemctl disable omsagent
rm -f ${SYSTEMD_UNIT_DIR}/omsagent.service
/bin/systemctl daemon-reload
elif [ -f /etc/init.d/omsagent ]; then
echo "Unconfiguring OMS agent service ..."
if [ -f /usr/sbin/update-rc.d ]; then
/usr/sbin/update-rc.d -f omsagent remove
elif [ -x /usr/lib/lsb/remove_initd ]; then
/usr/lib/lsb/remove_initd /etc/init.d/omsagent
elif [ -x /sbin/chkconfig ]; then
chkconfig --del omsagent > /dev/null
else
echo "Unrecognized Service Controller to unregister OMS Agent Service."
exit 1
fi

rm /etc/init.d/omsagent
fi
}
# End of temporary upgradecode


#
# Main script follows
Expand Down Expand Up @@ -467,7 +528,7 @@ case "$installMode" in

pkg_add $SCX_PKG scx
SCX_EXIT_STATUS=$?

pkg_add $OMS_PKG omsagent
OMS_EXIT_STATUS=$?

Expand Down Expand Up @@ -558,6 +619,7 @@ case "$installMode" in
echo "${CIPHER}" >> $OMISERV_CONF
fi

disable_omsagent_service
pkg_upd $OMS_PKG omsagent
OMS_EXIT_STATUS=$?

Expand Down
110 changes: 7 additions & 103 deletions installer/datafiles/linux.data
Original file line number Diff line number Diff line change
Expand Up @@ -17,99 +17,6 @@ OMS_SERVICE: '/opt/microsoft/omsagent/bin/service_control'

/etc/opt/microsoft/omsagent/sysconf/sudoers; installer/conf/sudoers; 664; root; root


%Systemd_resolver
# Various distributions have different paths for systemd unit files ...

SYSTEMD_UNIT_DIR=""
ResolveSystemdPaths()
{
local UNIT_DIR_LIST="/usr/lib/systemd/system /lib/systemd/system"

if pidof systemd 1> /dev/null 2> /dev/null; then
# Be sure systemctl lives where we expect it to
if [ ! -f /bin/systemctl ]; then
echo "FATAL: Unable to locate systemctl program" 1>&2
exit 1
fi

# Find systemd unit directory
for i in ${UNIT_DIR_LIST}; do
if [ -d $i ]; then
SYSTEMD_UNIT_DIR=${i}
return 0
fi
done

# Didn't fine unit directory, that's fatal
echo "FATAL: Unable to resolve systemd unit directory!" 1>&2
exit 1
else
return 1
fi
}

ResolveSystemdPaths

%OMSService_funcs
StopOMSService() {
if [ -f ${{OMS_SERVICE}} ]; then
${{OMS_SERVICE}} stop
fi
}

RemoveOMSService() {
# Stop the server if it's running
StopOMSService

# Registered as a systemd service?
if [ -f ${SYSTEMD_UNIT_DIR}/omsagent.service ]; then
echo "Unconfiguring OMS agent (systemd) service ..."
/bin/systemctl disable omsagent
rm -f ${SYSTEMD_UNIT_DIR}/omsagent.service
/bin/systemctl daemon-reload
elif [ -f /etc/init.d/omsagent ]; then
echo "Unconfiguring OMS agent service ..."
if [ -f /usr/sbin/update-rc.d ]; then
/usr/sbin/update-rc.d -f omsagent remove
elif [ -x /usr/lib/lsb/remove_initd ]; then
/usr/lib/lsb/remove_initd /etc/init.d/omsagent
elif [ -x /sbin/chkconfig ]; then
chkconfig --del omsagent > /dev/null
else
echo "Unrecognized Service Controller to unregister OMS Agent Service."
exit 1
fi

rm /etc/init.d/omsagent
fi
}

ConfigureOMSService() {
echo "Configuring OMS agent service ..."
if pidof systemd 1> /dev/null 2> /dev/null; then
# systemd
cp /etc/opt/microsoft/omsagent/sysconf/omsagent.systemd ${SYSTEMD_UNIT_DIR}/omsagent.service
/bin/systemctl daemon-reload
/bin/systemctl enable omsagent
else
cp /etc/opt/microsoft/omsagent/sysconf/omsagent.ulinux /etc/init.d/omsagent

if [ -x /usr/sbin/update-rc.d ]; then
update-rc.d omsagent defaults > /dev/null
elif [ -x /usr/lib/lsb/install_initd ]; then
/usr/lib/lsb/install_initd /etc/init.d/omsagent
elif [ -x /sbin/chkconfig ]; then
chkconfig --add omsagent > /dev/null
else
echo "Unrecognized Service Controller to configure OMS Agent Service."
exit 1
fi
fi

${{OMS_SERVICE}} start
}

%Syslog_Services
RestartService() {
if [ -z "$1" ]; then
Expand All @@ -120,8 +27,9 @@ RestartService() {
echo "Restarting service: $1"

# Does the service exist under systemd?
local systemd_dir=$(${{OMS_SERVICE}} find-systemd-dir)
pidof systemd 1> /dev/null 2> /dev/null
if [ $? -eq 0 -a -f ${SYSTEMD_UNIT_DIR}/${1}.service ]; then
if [ $? -eq 0 -a -f ${systemd_dir}/${1}.service ]; then
/bin/systemctl restart $1
else
if [ -x /usr/sbin/invoke-rc.d ]; then
Expand Down Expand Up @@ -265,17 +173,17 @@ SudoSupportsIncludeDirective() {


%Preinstall_1000
#include Systemd_resolver
#include Syslog_Services
#include OMSService_funcs

# If our service is already running, stop it
if [ -f /opt/microsoft/omsagent/bin/service_control ]; then
/opt/microsoft/omsagent/bin/service_control stop
fi

UnconfigureSyslog
RemoveOMSService

# The OMS_SERVICE script will not be present on a fresh install
[ -f ${{OMS_SERVICE}} ] && ${{OMS_SERVICE}} disable

# Add the 'omsagent' group if it does not already exist
# (Can't use useradd with -U since that doesn't exist on older systems)
Expand All @@ -293,13 +201,11 @@ if [ $? -ne 0 ]; then
fi

%Postinstall_200
#include Systemd_resolver
#include OMSService_funcs
#include Syslog_Services
#include Sudoer_Functions

${{OMI_SERVICE}} reload
ConfigureOMSService
${{OMS_SERVICE}} enable
ConfigureSyslog

# Deal with sudo (either place in sudoers.d or append to sudoers configuration)
Expand Down Expand Up @@ -328,14 +234,12 @@ fi


%Postuninstall_1000
#include Systemd_resolver
#include Syslog_Services
#include OMSService_funcs

# If we're called for upgrade, don't do anything
if ${{PERFORMING_UPGRADE_NOT}}; then
UnconfigureSyslog
RemoveOMSService
${{OMS_SERVICE}} disable

# Restart the OMI server in case an agent is running under service account
${{OMI_SERVICE}} restart
Expand Down
4 changes: 2 additions & 2 deletions installer/scripts/omsagent.systemd
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Operations Management Suite agent
After=network.target
Wants=omiserverd.service
Wants=omid.service

[Service]
Type=simple
Expand All @@ -12,7 +12,7 @@ ExecStart=/opt/microsoft/omsagent/bin/omsagent \
-d /var/opt/microsoft/omsagent/run/omsagent.pid \
-o /var/opt/microsoft/omsagent/log/omsagent.log \
--no-supervisor
ExecStop=rm -f /var/opt/microsoft/omsagent/run/omsagent.pid
ExecStop=/bin/rm -f /var/opt/microsoft/omsagent/run/omsagent.pid
KillMode=process
KillSignal=SIGKILL
TimeoutStartSec=10
Expand Down
97 changes: 97 additions & 0 deletions installer/scripts/service_control
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,91 @@ restart_omsagent()
fi
}


find_systemd_dir()
{
# Various distributions have different paths for systemd unit files ...
local UNIT_DIR_LIST="/usr/lib/systemd/system /lib/systemd/system"

if pidof systemd 1> /dev/null 2> /dev/null; then
# Be sure systemctl lives where we expect it to
if [ ! -f /bin/systemctl ]; then
echo "FATAL: Unable to locate systemctl program" 1>&2
exit 1
fi

# Find systemd unit directory
for i in ${UNIT_DIR_LIST}; do
if [ -d $i ]; then
echo ${i}
return 0
fi
done

# Didn't find unit directory, that's fatal
echo "FATAL: Unable to resolve systemd unit directory!" 1>&2
exit 1
else
return 1
fi
}

enable_omsagent_service()
{
echo "Configuring OMS agent service ..."
if pidof systemd 1> /dev/null 2> /dev/null; then
# systemd
local systemd_dir=$(find_systemd_dir)
cp /etc/opt/microsoft/omsagent/sysconf/omsagent.systemd ${systemd_dir}/omsagent.service
/bin/systemctl daemon-reload
/bin/systemctl enable omsagent
else
cp /etc/opt/microsoft/omsagent/sysconf/omsagent.ulinux /etc/init.d/omsagent

if [ -x /usr/sbin/update-rc.d ]; then
update-rc.d omsagent defaults > /dev/null
elif [ -x /usr/lib/lsb/install_initd ]; then
/usr/lib/lsb/install_initd /etc/init.d/omsagent
elif [ -x /sbin/chkconfig ]; then
chkconfig --add omsagent > /dev/null
else
echo "Could not find a service controller to configure the OMS Agent Service."
exit 1
fi
fi

start_omsagent
}

disable_omsagent_service()
{
# Stop the server if it's running
stop_omsagent

# Registered as a systemd service?
local systemd_dir=$(find_systemd_dir)
if [ -f ${systemd_dir}/omsagent.service ]; then
echo "Unconfiguring OMS agent (systemd) service ..."
/bin/systemctl disable omsagent
rm -f ${systemd_dir}/omsagent.service
/bin/systemctl daemon-reload
elif [ -f /etc/init.d/omsagent ]; then
echo "Unconfiguring OMS agent service ..."
if [ -f /usr/sbin/update-rc.d ]; then
/usr/sbin/update-rc.d -f omsagent remove
elif [ -x /usr/lib/lsb/remove_initd ]; then
/usr/lib/lsb/remove_initd /etc/init.d/omsagent
elif [ -x /sbin/chkconfig ]; then
chkconfig --del omsagent > /dev/null
else
echo "Unrecognized Service Controller to unregister OMS Agent Service."
exit 1
fi

rm /etc/init.d/omsagent
fi
}

case "$1" in
functions)
;;
Expand All @@ -186,6 +271,18 @@ case "$1" in
restart_omsagent
;;

find-systemd-dir)
find_systemd_dir
;;

enable)
enable_omsagent_service
;;

disable)
disable_omsagent_service
;;

*)
echo "Unknown parameter : $1" 1>&2
exit 1
Expand Down

0 comments on commit d57d1c9

Please sign in to comment.