Appdynamics / appdynamics-cookbooks

29 stars 36 forks source link

SystemD init script for ubuntu 16.04 #77

Open spuder opened 6 years ago

spuder commented 6 years ago

Getting this error when trying to install the machine agent on ubuntu 16.04 with chef 12

 appdynamics_machine_agent.service is not a native service, redirecting to systemd-sysv-install
    Executing /lib/systemd/systemd-sysv-install enable appdynamics_machine_agent
    insserv: warning: script 'appdynamics_machine_agent' missing LSB tags and overrides
    update-rc.d: error: appdynamics_machine_agent Default-Start contains no runlevels, aborting.
Recipe: appdynamics::java_agent
  * remote_file[/var/chef/cache/AppDynamicsJavaAgent.zip] action create (up to date)
  * ark[javaagent] action put
    * directory[/opt/appdynamics/javaagent] action create (up to date)
    * remote_file[/var/chef/cache/javaagent.zip] action create (up to date)
    * execute[unpack /var/chef/cache/javaagent.zip] action nothing (skipped due to action :nothing)
    * execute[set owner on /opt/appdynamics/javaagent] action nothing (skipped due to action :nothing)
     (up to date)
  * template[/opt/appdynamics/javaagent/conf/controller-info.xml] action create (up to date)
Recipe: appdynamics::machine_agent
  * apt_package[unzip] action install (up to date)
  * directory[/opt/appdynamics/machineagent/conf] action create (up to date)
  * remote_file[/var/chef/cache/AppDynamicsMachineAgent.zip] action createps aux | grep java

    - create new file /var/chef/cache/AppDynamicsMachineAgent.zip
    - update content in file /var/chef/cache/AppDynamicsMachineAgent.zip from none to 924837
    (file sizes exceed 10000000 bytes, diff output suppressed)
    - change mode from '' to '0444'
  * execute[unzip-appdynamics-machine-agent] action run
    - execute unzip -qqo /var/chef/cache/AppDynamicsMachineAgent.zip
  * template[/opt/appdynamics/machineagent/run.sh] action create
    - create new file /opt/appdynamics/machineagent/run.sh
    - update content in file /opt/appdynamics/machineagent/run.sh from none to 1faa75
    --- /opt/appdynamics/machineagent/run.sh    2017-10-19 22:55:54.161147103 +0000
    +++ /opt/appdynamics/machineagent/.chef-run20171019-109208-18fa3q4.sh   2017-10-19 22:55:54.161147103 +0000
    @@ -1 +1,3 @@
    +#!/bin/sh
    +"/usr/bin/java" -Xmx32m -jar "/opt/appdynamics/machineagent/machineagent.jar" &
    - change mode from '' to '0744'
    - change owner from '' to 'root'
    - change group from '' to 'root'
  * execute[unzip-appdynamics-machine-agent] action run
    - execute unzip -qqo /var/chef/cache/AppDynamicsMachineAgent.zip
  * template[/etc/init.d/appdynamics_machine_agent] action create
    - create new file /etc/init.d/appdynamics_machine_agent
    - update content in file /etc/init.d/appdynamics_machine_agent from none to a07c17
    --- /etc/init.d/appdynamics_machine_agent   2017-10-19 22:55:57.837080954 +0000
    +++ /etc/init.d/.chef-appdynamics_machine_agent20171019-109208-5mshtg   2017-10-19 22:55:57.837080954 +0000
    @@ -1 +1,54 @@
    +#!/bin/sh
    +#
    +#
    +# Subsystem file for AppDynamics machine agent
    +#
    +# chkconfig: 2345 95 05 (1)
    +# description: AppDynamics machine agent
    +
    +# source function library
    +if [ -r /lib/lsb/init-functions ]; then
    +    . /lib/lsb/init-functions
    +elif [ -r /etc/rc.d/init.d/functions ]; then
    +    . /etc/rc.d/init.d/functions
    +elif [ -r /etc/init.d/functions ]; then
    +    . /etc/init.d/functions
    +fi
    +
    +INSTALL_DIR="/opt/appdynamics/machineagent"
    +RETVAL=0
    +PROG="$INSTALL_DIR/run.sh"
    +
    +start() {
    +    echo -n $"Starting AppDynamics machine agent:"
    +    "$PROG"
    +    RETVAL=$?
    +    echo
    +}
    +
    +stop() {
    +    echo -n $"Stopping AppDynamics machine agent:"
    +    killproc "$PROG" -TERM
    +    RETVAL=$?
    +    echo
    +}
    +
    +case "$1" in
    +    start)
    +        start
    +        ;;
    +    stop)
    +        stop
    +        ;;
    +    restart)
    +        stop
    +        start
    +        ;;
    +    *)
    +        echo $"Usage: $0 {start|stop|restart}"
    +        RETVAL=1
    +        ;;
    +esac
    +
    +exit $RETVAL
    - change mode from '' to '0744'
    - change owner from '' to 'root'
    - change group from '' to 'root'
  * template[/opt/appdynamics/machineagent/conf/controller-info.xml] action create
    - update content in file /opt/appdynamics/machineagent/conf/controller-info.xml from 282428 to 8074cc
    --- /opt/appdynamics/machineagent/conf/controller-info.xml  2017-10-12 21:29:38.000000000 +0000
    +++ /opt/appdynamics/machineagent/conf/.chef-controller-info20171019-109208-8wqabh.xml  2017-10-19 22:55:57.849080738 +0000
    @@ -1,75 +1,48 @@
     <?xml version="1.0" encoding="UTF-8"?>
     <controller-info>
    -    <!-- For more detailed information on different configurations that an agent can support and the respective rules,
    -    consult the online documentation. In general, configuration properties may be set in different ways. Here is the
    -    order of precedence of how the agent will read and respect specific configurations.
    -      1. Environment Variables
    -      2. System Properties
    -      3. Default/Root controller-info.xml. See .../$(Agent-Base-Install-Dir)/conf/controller-info.xml -->

    -    <!-- This is the host name or the IP address of the AppDynamics Controller (e.g., 192.168.1.22 or myhost or
    -    myhost.abc.com). This is the same host that you use to access the AppDynamics browser-based User interface. This can
    -    be overridden with the environment variable 'CONTROLLER_HOST_NAME' or the system property
    -    '-Dappdynamics.controller.hostName' -->
    -    <controller-host></controller-host>
    +    <!-- This is the host name or the IP address of the AppDynamics Controller e.g. 192.168.1.22 or myhost or myhost.abc.com
    +    This is the same host that you use to access the AppDynamics browser based User interface.
    +    This can be overridden with the system property '-Dappdynamics.controller.hostName' -->
    +    <controller-host>netdocuments2.saas.appdynamics.com</controller-host>

    -    <!-- This is the http(s) port of the AppDynamics Controller. If 'controller-ssl-enabled' (below) is set to true, you
    -    must specify the HTTPS port of the Controller; otherwise, specify the HTTP port. The default values are 8090 for
    -    HTTP and 8181 for HTTPS. This is the same port that you use to access the AppDynamics browser-based User interface.
    -    This can be overridden with the environment variable 'APPDYNAMICS_CONTROLLER_PORT' or the system property
    -    '-Dappdynamics.controller.port' -->
    -    <controller-port></controller-port>
    +    <!-- This is the http(s) port of the AppDynamics Controller , If 'controller-ssl-enabled' below is set to true, you must
    +    specify the HTTPS port of the Controller, otherwise specify the HTTP port. The default values are 8090 for HTTP and 8181 for HTTPS
    +    This is the same port that you use to access the AppDynamics browser based User interface.
    +    This can be overridden with the system property '-Dappdynamics.controller.port' -->
    +    <controller-port>443</controller-port>

    -    <!-- This specifies if the AppDynamics agent should use SSL (HTTPS) to connect to the Controller. If you set this to
    -    true, the controller port property above should be set to the HTTPS port of the Controller. This can be overridden
    -    with the environment variable 'APPDYNAMICS_CONTROLLER_SSL_ENABLED' or the system property
    -    '-Dappdynamics.controller.ssl.enabled' -->
    -    <controller-ssl-enabled>false</controller-ssl-enabled>
    +    <!-- This specifies if the AppDynamics agent should use SSL(HTTPS) to connect to the Controller. If you set this to true,
    +    the controller port property above should be set to the HTTPs port of the Controller.
    +    This can be overridden with the system property '-Dappdynamics.controller.ssl.enabled' -->
    +    <controller-ssl-enabled>true</controller-ssl-enabled>

         <!-- Set this flag to 'true' to enable features required for AppDynamics Orchestration, including the following:
         1) Enables the agent to execute tasks specified in AppDynamics Orchestration workflows.
    -    2) Enables the agent to resolve the AppDynamics Controller host and port when the host machine where this agent
    -       resides is created through AppDynamics Orchestration. -->
    +    2) Enables the agent to resolve the AppDynamics Controller host and port when the host
    +       machine where this agent resides is created through AppDynamics Orchestration. -->
         <enable-orchestration>false</enable-orchestration>

    -    <!-- The Machine Agent uses the Java API to get the host name of the agent. The results from the API can be
    -    inconsistent, and the same JVM can sometimes return a different value for the same machine each time the machine
    -    agent is restarted. It is recommended to set this field in the following scenarios:
    +    <!-- If the AppDynamics Controller is running in multi-tenant mode or you are using the AppDynamics SaaS Controller
    +    you must specify the account name and account access key for this agent to authenticate with the controller.
    +    If you are running in single-tenant mode (the default) there is no need to configure these values. -->
    +    <account-name>netdocuments2</account-name>
    +    <account-access-key>b37f635b956e</account-access-key>

    -    1) The machine host name is not constant
    -    2) You prefer to use a specific name in the UI
    -    3) The machine has both a machine agent and app agents on it.
    +    <!--  For Auto Agent Registration specify the application name, tier name,
    +    and optionally, node name. If the application and/or tier does not exist
    +    already it will be created. If there is already a registered app server agent
    +    installed on the same host as this machine agent then Auto Agent Registration
    +    is not necessary for this machine agent. -->
    +    <application-name>lab-ducot</application-name>
    +    <tier-name></tier-name>
    +    <node-name></node-name>

    -    This can be overridden with the environment variable 'APPDYNAMICS_AGENT_UNIQUE_HOST_ID' or the system property
    -    '-Dappdynamics.agent.uniqueHostId' -->
    -    <unique-host-id></unique-host-id>
    -
    -    <!-- This key is generated at installation time and can be found by viewing the license information in the
    -    controller settings. This can be overridden with the environment variable 'APPDYNAMICS_AGENT_ACCOUNT_ACCESS_KEY' or
    -    the system property '-Dappdynamics.agent.accountAccessKey' -->
    -    <account-access-key></account-access-key>
    -
    -    <!-- If the AppDynamics Controller is running in multi-tenant mode or you are using the AppDynamics SaaS Controller,
    -    you must specify the account name for this agent to authenticate with the controller. If you are running in
    -    single-tenant mode (the default) there is no need to configure this value. This can be overridden with the
    -    environment variable 'APPDYNAMICS_AGENT_ACCOUNT_NAME' or the system property '-Dappdynamics.agent.accountName' -->
    -    <account-name></account-name>
    -
    -    <!-- If this agent is licensed for Server Monitoring, set this flag to 'true' to enable Server Monitoring expanded
    -    metrics. This can be overridden with the environment variable 'APPDYNAMICS_SIM_ENABLED' or the system property
    -    '-Dappdynamics.sim.enabled' -->
    -    <sim-enabled>false</sim-enabled>
    -
    -    <!-- This value is used to create the hierarchy infrastructure view in the UI for this machine. Each hierarchy level
    -    should be separated with a vertical bar ("|"). For example, if this machine belongs to "DataRack1" and it is located
    -    in "Virginia Data Center", then the machine path could be set to "Virginia Data Center|DataRack1|Machine1" and the
    -    UI will display it in that hierarchy ("Virginia Data Center|DataRack1"). The last element of the path indicates the
    -    server name (e.g., "Machine1") and appears as the name on the servers list in the UI. This can be overridden with
    -    the environment variable 'APPDYNAMICS_MACHINE_HIERARCHY_PATH' or the system property
    -    '-Dappdynamics.machine.agent.hierarchyPath'.
    -
    -    Note: The number of characters up to but not including the last vertical bar must not exceed 95. -->
    -    <machine-path></machine-path>
    +    <!-- Change to 'true' only under special circumstances where this agent has been moved to a new application and/or tier
    +    from the UI but you want to override that move by specifying a new application name and/or tier name in the agent configuration.
    +    If there is already a registered app server agent installed on the same host as this machine agent then this override DOES not work.
    +    If you want to override the UI in this case, you must force the agent registration change from the app server agent configuration. -->
    +    <force-agent-registration>false</force-agent-registration>

     </controller-info>
  * service[appdynamics_machine_agent] action enable

    ================================================================================
    Error executing action `enable` on resource 'service[appdynamics_machine_agent]'
    ================================================================================

    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '1'
    ---- Begin output of /bin/systemctl --system enable appdynamics_machine_agent ----
    STDOUT:
    STDERR: appdynamics_machine_agent.service is not a native service, redirecting to systemd-sysv-install
    Executing /lib/systemd/systemd-sysv-install enable appdynamics_machine_agent
    insserv: warning: script 'appdynamics_machine_agent' missing LSB tags and overrides
    update-rc.d: error: appdynamics_machine_agent Default-Start contains no runlevels, aborting.
    ---- End output of /bin/systemctl --system enable appdynamics_machine_agent ----
    Ran /bin/systemctl --system enable appdynamics_machine_agent returned 1

    Resource Declaration:
    ---------------------
    # In /var/chef/cache/cookbooks/appdynamics/recipes/machine_agent.rb

    105: service 'appdynamics_machine_agent' do
    106:   supports [:start, :stop, :restart]
    107:   action [:enable, :start]
    108: end

    Compiled Resource:
    ------------------
    # Declared in /var/chef/cache/cookbooks/appdynamics/recipes/machine_agent.rb:105:in `from_file'

    service("appdynamics_machine_agent") do
      action [:enable, :start]
      supports {:restart=>true, :reload=>nil, :status=>nil, :start=>true, :stop=>true}
      retries 0
      retry_delay 2
      default_guard_interpreter :default
      service_name "appdynamics_machine_agent"
      enabled nil
      running nil
      masked nil
      pattern "appdynamics_machine_agent"
      declared_type :service
      cookbook_name "appdynamics"
      recipe_name "machine_agent"
    end

    System Info:
    ------------
    chef_version=12.21.4
    platform=ubuntu
    platform_version=16.04
    ruby=ruby 2.3.4p301 (2017-03-30 revision 58214) [x86_64-linux]
    program_name=chef-client worker: ppid=109203;start=22:55:28;
    executable=/opt/chef/bin/chef-client

Starting audit phase

Finished in 0.0006 seconds (files took 0.71417 seconds to load)
0 examples, 0 failures
Auditing complete

Running handlers:
Running handlers complete
Chef Client failed. 13 resources updated in 30 seconds
spuder commented 6 years ago

Looking closer at the output, this appears to be a problem with the init script in the cookbook.

The cookbook should support systemD init scripts

Documented here:

https://docs.appdynamics.com/display/PRO43/Linux+Install+Using+ZIP+with+Bundled+JRE

The zip contains init.d and systemdD


[Unit]
Description=AppDynamics Machine Agent

[Service]

# The AppDynamics machine agent startup script does not fork a process, so
# this is a simple service.
# Note: If you are changing the User running the machine agent, you must also ensure
# that the desired user has read access to controller-info.xml as well as write access
# to the log file. You can change specific file permissions or, most simply, do a
# chown command to give the desired user ownership of the MACHINE_AGENT_HOME directory.

Type=simple

Environment=MACHINE_AGENT_HOME=/opt/appdynamics/machine-agent
Environment=JAVA_HOME=/opt/appdynamics/machine-agent/jre

# Specify agent system properties for systemd here by setting or editing JAVA_OPTS, e.g.,
#Environment="JAVA_OPTS=-D<sys-property1>=<value1> -D<sys-property2>=<value2>"

# Modify the next two lines to specify the user to run the machine agent as. Note that
# you will need to ensure that:
# 1. The controller-info.xml in the agent conf directory is readable by this user
# 2. The logs directory is writeable by this user
# 3. The scripts directory is writeable by this user
User=root
Environment=MACHINE_AGENT_USER=root

# The next three lines must point to the same location (i.e. the
# PIDFILE env var and the PIDFile property.)
Environment=PIDDIR=/var/run/appdynamics
Environment=PIDFILE=${PIDDIR}/appdynamics-machine-agent.pid
PIDFile=/var/run/appdynamics/appdynamics-machine-agent.pid

# Killing the service using systemd causes Java to exit with status 143. This is OK.
SuccessExitStatus=143

# Run ExecStartPre with root-permissions
PermissionsStartOnly=true

# Create the pid dir
ExecStartPre=/usr/bin/install -o $MACHINE_AGENT_USER -d $PIDDIR

# This specifies the command line to use
ExecStart=/bin/sh -c "\"${MACHINE_AGENT_HOME}/bin/machine-agent\" -p ${PIDFILE}"

[Install]
# Start the AppDynamics machine agent service during the setup for a
# non-graphical multi-user system.
WantedBy=multi-user.target
``