Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOG-1498: Add batch-mode. #108

Open
wants to merge 3 commits into
base: master
from

Conversation

@kristjanvalur
Copy link

@kristjanvalur kristjanvalur commented Nov 2, 2017

Add batch mode, useful for automatic deployment on machines that are known to be compatible.
if --batch flag is provided, then no user account testing is performed. Also, no log delivery tests are
performed.

@mostlyjason
Copy link
Contributor

@mostlyjason mostlyjason commented Nov 2, 2017

Is there any reason you want to run the script for automatic deployments, versus just deploying the configuration file that is generated? All you should have to do is deploy the 22-loggly.com and restart rsyslog. A lot of the tests in the script check are to help spot issues in new environments.

@kristjanvalur
Copy link
Author

@kristjanvalur kristjanvalur commented Nov 3, 2017

Yes, I'm working with ElasticBeanstalk and deploying custom files there is a hassle. It is much simpler to have a script to download and execute a configuration script with secrets that are passed in environment variables. This is particularly useful if the deployment platform changes, then I can expect the installation script to pick up on that change and adapt.
Environments like ElasticBeanstalk don't really encourage you to log into the individual server nodes and experiment with configurations until you are happy with them. Rather, a LAMP server of some brand or other, compatible with your application, is provisioned and deployed.

Of course, it would be super to have a custom solution for EB, but Loggly's portfolio of installers does not include those.

Here is a link that I found that I tried initially:
https://filib.io/posts/2015-07-19-using-loggly-on-elastic-beanstalk.html
(the approach is a bit roundabout, but you get the picture)

The problem with this one is that it
a) uses an apparently undocumented install scrtip install_syslog.py
b) does not seem to work on new systems using systemd.

This approach seems to work well. The reason for the pull request is to illustrate this use case, and of course, it is useful to benefit from further future script updates.
Of course, it would be useful to add enviroment variables / flags to modify the hostname, add tags, etc,

This is the contents of the loggly.config yaml file that I have in .ebextensions folder right now to configure the instances:

# .ebextensions/loggly.config
files:
  "/tmp/loggly_config.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/bin/bash
      set -e
      [ -z "$LOGGLY_ACCOUNT" -o -z "$LOGGLY_AUTH" ] && exit 0  #quit if not set
      curl -O https://raw.githubusercontent.com/kristjanvalur/install-script/feature/batch-mode1/Linux%20Script/configure-linux.sh
      bash configure-linux.sh -a "$LOGGLY_ACCOUNT" -t "$LOGGLY_AUTH" --batch

container_commands:
  01_loggly:
    command:
      /tmp/loggly_config.sh
    cwd: /tmp
    ignoreErrors: true  # don't worry if it fails
@mostlyjason
Copy link
Contributor

@mostlyjason mostlyjason commented Nov 3, 2017

Yes we talked about having a custom solution for elastic beanstalk but we haven't had a chance to make one yet. I like how this example shows how to create an rsyslog configuration file https://gist.github.com/zoellner/9849597. It's an nginx example, so it would need to be modified to create 22-loggly.conf instead. The contents you would need to insert in the file are here https://www.loggly.com/docs/rsyslog-manual-configuration/. The MaxMessageSize parameter is optional and only needed if you have long stack traces. You also don't have to restart rsyslog because I think that it would create the files before starting the instance. Really the only thing you have to do is insert the contents of 22-loggly.conf.

@kristjanvalur
Copy link
Author

@kristjanvalur kristjanvalur commented Nov 6, 2017

One problem with a 22-loggly.conf file like this is that it is static.

  • You have to have your loggly token in the file
  • Any tags have to be predefined
  • Hostname is fixed.

It is really useful to have your logging configured based on environment variables provided to your host environment, thus e.g. able to fudge hostname, set application/environment tag, etc.
This allows you to deploy the same source to different environments.

Additionally, there are extra steps required if --secure logging is desired. Here are some of the actions taken on the hosts, according to EB logs.

INFO: rsyslog is present as service.
  INFO: Modified $MaxMessageSize to 64k in rsyslog.conf
  INFO: Creating directory
  mkdir: created directory '/var/spool/rsyslog'
  DOWNLOADING CERTIFICATE
  mkdir: created directory '/etc/rsyslog.d/keys'
  mkdir: created directory '/etc/rsyslog.d/keys/ca.d'

Perhaps one cannot reasonably expect a single setup script to do all things, but this is at least a start...
Alternatively, perhaps a simpler loggly installer can be created, some shell script that takes a 22-loggly.conf.template file and interpolates the proper environment variables.
At any rate, an example would be really useful.

@mostlyjason
Copy link
Contributor

@mostlyjason mostlyjason commented Nov 6, 2017

Why does it need to be static? Can't you pass environment variables in your eb config, which then populate hostname, tags, token, etc.? Yes for secure logging you'll have to curl the certificate file and use this content https://www.loggly.com/docs/rsyslog-tls-configuration/. My main worry with the script is its getting quite complex to support so many different use cases. The number of parameters is increasing and will need to be maintained over time. It might be better to have a configuration example specifically for elastic beanstalk. If you got one working and shared a gist we'd be happy to send some swag your way as a thanks.

@kristjanvalur
Copy link
Author

@kristjanvalur kristjanvalur commented Nov 7, 2017

I understand. I'll see if I can't contribute some different EB way. Stay tuned :)

@kristjanvalur
Copy link
Author

@kristjanvalur kristjanvalur commented Nov 13, 2017

Check this out. Currently using this on our EB instances with good success.
https://gist.github.com/kristjanvalur/1715e7df2392134595ebe7d122c51099

@mostlyjason
Copy link
Contributor

@mostlyjason mostlyjason commented Nov 13, 2017

Wow thats really cool thanks for sharing! I added a link to your example on our Loggly Libraries Catalog page https://www.loggly.com/docs/loggly-libraries-catalog/. We'd like to send you some swag as a thanks should I send the invite to the email listed on your github profile?

@nguyenfilip nguyenfilip changed the title Add batch-mode. LOG-1498: Add batch-mode. Nov 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.