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

How to run with chef-client zero (-z, local mode, or solo) #68

Closed
PAStheLoD opened this issue Nov 17, 2014 · 29 comments
Closed

How to run with chef-client zero (-z, local mode, or solo) #68

PAStheLoD opened this issue Nov 17, 2014 · 29 comments

Comments

@PAStheLoD
Copy link

Hello,

Could you help me with this? I've tried to run it through bundler, and did bekshelf install too.

I want to clone this onto a server (or preferably not) and issue a few one liners to get the dependencies (on both sides) and have a running kafka 20 minutes later.

Thanks!

Starting Chef Client, version 11.12.8
resolving cookbooks for run list: ["kafka-cookbook::binary"]
Synchronizing Cookbooks:
  - kafka-cookbook
Compiling Cookbooks...

================================================================================
Recipe Compile Error in /root/.chef/local-mode-cache/cache/cookbooks/kafka-cookbook/recipes/binary.rb
================================================================================


NoMethodError
-------------
No resource or method named `kafka_download' for `Chef::Recipe "binary"'


Cookbook Trace:
---------------
  /root/.chef/local-mode-cache/cache/cookbooks/kafka-cookbook/recipes/binary.rb:9:in `from_file'


Relevant File Content:
----------------------
/root/.chef/local-mode-cache/cache/cookbooks/kafka-cookbook/recipes/binary.rb:

  2:  # Cookbook Name:: kafka
  3:  # Recipe:: binary
  4:  #
  5:  
  6:  kafka_tar_gz = [kafka_base, kafka_archive_ext].join('.')
  7:  local_file_path = ::File.join(Chef::Config.file_cache_path, kafka_tar_gz)
  8:  
  9>> kafka_download local_file_path do
 10:    source kafka_download_uri(kafka_tar_gz)
 11:    checksum node.kafka.checksum
 12:    md5_checksum node.kafka.md5_checksum
 13:    not_if { kafka_installed? }
 14:  end
 15:  
 16:  execute 'extract-kafka' do
 17:    user 'root'
 18:    group 'root'

@mthssdrbrg
Copy link
Contributor

Chef uses the name of the directory when "creating" LWRPs, so in this case the directory is named kafka-cookbook which unfortunately won't work that well. If you clone it to a kafka directory everything should work as expected.

Let me know whether this solves the issue for you.

@PAStheLoD
Copy link
Author

Thanks, it helps get the ball rolling, then it

  • fails on missing /opt/kafka/build,
  • missing kafka user and group,
  • and then it needed a chown kafka /opt/kafka.

And I get a nice extracted deployment, but attributes doesn't seem to have any effect.

I run chef-client -z -c /var/chef/cookbooks/solo.rb -j /var/chef/cookbooks/attr.json and attr.json is:

{
    "run_list": [ "recipe[kafka::binary]" ],
    "kafka": {
        "init_style": "systemd",
        "automatic_start": true
     }
}

@mthssdrbrg
Copy link
Contributor

Use the default recipe instance rather than the binary one (it will use the binary recipe by default, but the default recipe also includes some other "internal" recipes, for setting up user/group and whatnot).

@mthssdrbrg
Copy link
Contributor

@PAStheLoD: did that solve your issue?

@PAStheLoD
Copy link
Author

Yes, thanks, now I'm trying to use attributes, but so far I haven't been able to figure it out completely, and the cookbook seems to assume RedHat style layout, because it fails with the following:

* Parent directory /etc/sysconfig does not exist.

So I see that somehow I should tweak init_opts (kafka_init_opts {:env_path=>"/etc/sysconfig/kafka", :env_template=>"systemd/kafka.env.erb", :source=>"systemd/default.erb", :script_path=>"/etc/systemd/system/kafka.service", :provider=>Chef::Provider::Service::Systemd, :permissions=>"644"}), right?

@mthssdrbrg
Copy link
Contributor

Hm, I was under the assumption that /etc/sysconfig for Environment files was something generic for systemd, but perhaps I'm mistaken. What Linux distro are you using?

@PAStheLoD
Copy link
Author

Debian 7

For systemd the /etc/systemd is the generic directory.

@mthssdrbrg
Copy link
Contributor

It appears as if /etc/sysconfig for EnvironmentFile(s) is a Fedora specific thing, my bad. There doesn't really seem to be any generic place to put EnvironmentFile(s), but I'm gonna do some more digging to see where exactly this file should be placed. Another alternative would be to create a wrapper script for starting Kafka, but that's a slightly larger task than just placing the file in a different location.

@PAStheLoD
Copy link
Author

Debian uses /etc/default/.

Also, I'd link kafka.service into multi-user.wants target.

And, it seems that if I modify scala_version, nothing happens. (So, maybe I should be asking how to force a reinstall? [I'm using current master.])

Anyway, with your tremendous help I've finally managed to reach the end of the cookbook.

@mthssdrbrg
Copy link
Contributor

Hm, alright, maybe I should do the same kind of value_for_platform_family logic that's done for the :sysv install method for the time being.

To force a reinstall simply remove /opt/kafka or whatever node.kafka.install_dir is set to.

I'll look into multi-user.wants, my knowledge of systemd is rather limited...

@mthssdrbrg
Copy link
Contributor

I just merged a branch with some systemd-related fixes, would be great if you could take it for a spin.

@PAStheLoD
Copy link
Author

Okay, master is now at 5cd3511.

Removing /opt/kafka, leads me to this:

  * kafka_install[/opt/kafka] action run
    * execute[install-kafka] action run

      ================================================================================
      Error executing action `run` on resource 'execute[install-kafka]'
      ================================================================================

      Mixlib::ShellOut::ShellCommandFailed
      ------------------------------------
      Expected process to exit with [0], but received '1'
      ---- Begin output of cp -r /root/.chef/local-mode-cache/cache/kafka-build/kafka_2.9.2-0.8.1.1/* /opt/kafka ----
      STDOUT: 
      STDERR: cp: cannot stat '/root/.chef/local-mode-cache/cache/kafka-build/kafka_2.9.2-0.8.1.1/*': Permission denied
      ---- End output of cp -r /root/.chef/local-mode-cache/cache/kafka-build/kafka_2.9.2-0.8.1.1/* /opt/kafka ----
      Ran cp -r /root/.chef/local-mode-cache/cache/kafka-build/kafka_2.9.2-0.8.1.1/* /opt/kafka returned 1

I guess the cp -r would run as kafka, but obviously /root is off limits for anyone except root.

Also, I have set scala version to 2.10.1, so seeing 2.9.2 is a bit strange :)

@mthssdrbrg
Copy link
Contributor

Ah, so Chef::Config.file_cache_path is under /root, that's rather unexpected. I've worked around that now though, should be in master in a little bit.

I'm not sure why it's using 2.9.2 if you've specified 2.10.1, could you share your cookbook code?

@mthssdrbrg
Copy link
Contributor

The cp -r issue should be resolved in b996099.

@PAStheLoD
Copy link
Author

Still using zero/solo,

attr.json:

{
    "run_list": [ "recipe[kafka::default]" ],
    "kafka":  {
        "default": {
            "init_style": "systemd",
            "automatic_start": true,
            "scala_version": "2.10.1"
        }
    }
}

And solo.rb:

cookbook_path [ "/root/.berkshelf/cookbooks", "/var/chef/cookbooks" ]

In /var/chef/cookbooks there is only attr.json and solo.rb, I just call it as chef-client -z -c /var/chef/cookbooks/solo.rb -j /var/chef/cookbooks/attr.json, and in the berkshelf folder there is only the apt, java and kafka cookbooks.

So, now I get the error message about systemd's system/ directory being in the wrong place:

Recipe: kafka::_configure
  * template[/opt/kafka/config/log4j.properties] action create (up to date)
  * template[/opt/kafka/config/server.properties] action create (up to date)
  * template[/etc/default/kafka] action create (up to date)
  * template[/usr/lib/systemd/system/kafka.service] action create
    * Parent directory /usr/lib/systemd/system does not exist.
    ================================================================================
    Error executing action `create` on resource 'template[/usr/lib/systemd/system/kafka.service]'

It's in /lib/systemd/system.

Strange. The "official" page on unit load paths mentions the one you use in the code, man page recommends using pkg-config:

Currently on Debian Jessie

pkg-config systemd --print-variables | xargs -n1 -I{} bash -c "echo -n {}=; pkg-config systemd --variable={}"


systemdsystemconfdir=/etc/systemd/system
systemdusergeneratordir=/usr/lib/systemd/user-generators
sysctldir=/usr/lib/sysctl.d
systemdshutdowndir=/lib/systemd/system-shutdown
tmpfilesdir=/usr/lib/tmpfiles.d
systemgidmax=999
catalogdir=/usr/lib/systemd/catalog
systemduserconfdir=/etc/systemd/user
systemdsleepdir=/lib/systemd/system-sleep
systemdsystemunitdir=/lib/systemd/system
systemdutildir=/lib/systemd
systemdsystemunitpath=/etc/systemd/system:/etc/systemd/system:/run/systemd/system:/usr/local/lib/systemd/system:/lib/systemd/system:/usr/lib/systemd/system:/lib/systemd/system
prefix=/usr
libdir=/usr/lib/x86_64-linux-gnu
systemduserunitpath=/etc/systemd/user:/etc/systemd/user:/run/systemd/user:/usr/local/lib/systemd/user:/usr/local/share/systemd/user:/usr/lib/systemd/user:/usr/lib/systemd/user:/usr/share/systemd/user
sysusersdir=/usr/lib/sysusers.d
modulesloaddir=/usr/lib/modules-load.d
systemdsystemgeneratordir=/lib/systemd/system-generators
binfmtdir=/usr/lib/binfmt.d
systemuidmax=999
systemduserunitdir=/usr/lib/systemd/user
systemduserpresetdir=/usr/lib/systemd/user-preset
systemdsystempresetdir=/lib/systemd/system-preset

@mthssdrbrg
Copy link
Contributor

Sigh, guess I'll revert the commit that change the path for the unit file. It's kinda funny though, I was under the impression that systemd was supposed to be the "same" on all platforms, but it sure doesn't look like it.

@mthssdrbrg
Copy link
Contributor

16a5f0c should be good to go, give it a spin whenever you get the chance.

@PAStheLoD
Copy link
Author

Well, it's supposed to be universal, and you could go with whatever path you feel like, just mkdir -p it, but the real advantage is that you can just write a unit file once and it supposedly runs on every systemd-enabled distro.

And it's working! Sort of. Because I can't figure out how to write a JSON Attributes file to override the defaults. Could you help me out with that?

@mthssdrbrg
Copy link
Contributor

Yeah, that's true, guess I sort of expected paths to be universal as well :). Being able to use a single unit file is definitely nice though.

test-kitchen uses the following JSON attributes file, and it overrides the defaults correctly:

{
    "java": {
        "jdk_version": 7
    },
    "kafka": {
        "broker": {
            "controlled_shutdown_enable": null,
            "log_dirs": [
                "/mnt/kafka-logs-1",
                "/mnt/kafka-logs-2"
            ],
            "zookeeper_connect": [
                "localhost:2181"
            ],
            "zookeeper_connection_timeout_ms": 15000
        },
        "checksum": "",
        "md5_checksum": "",
        "scala_version": "2.10",
        "ulimit_file": 128000,
        "version": "0.8.1.1"
    },
    "run_list": [
        "recipe[apt]",
        "recipe[java::default]",
        "recipe[kafka::default]"
    ]
}

The only thing I can think of is that run_list is specified after the attributes, but I can't imagine that that would make a difference (or at least I certainly hope it doesn't...).

@PAStheLoD
Copy link
Author

Thanks, the "default" was causing the problems.

Everything works as intended, so I'm closing this.

@mthssdrbrg
Copy link
Contributor

Cool, I'm glad that it worked out alright.

@PAStheLoD
Copy link
Author

Oh, sorry for my lack of thoroughness, but I just noticed that the systemd service file refers to /etc/sysconfig/kafka even on Debian. Do you plan to handle distribution specific differences?

@mthssdrbrg
Copy link
Contributor

Hm, I changed that in b55aba0 and the systemd service file should be in /etc/systemd/system since 16a5f0c.

@PAStheLoD
Copy link
Author

I've run systemd-delta that informed me that they are identical. Then edited the system file.

But I just did a run and:

  * template[/etc/systemd/system/kafka.service] action create
    - update content in file /etc/systemd/system/kafka.service from 8535f8 to 5e844d

    --- /etc/systemd/system/kafka.service       2014-11-24 20:34:19.152063214 +0100
    +++ /tmp/chef-rendered-template20141124-2650-1ax6fl1        2014-11-24 20:34:51.403124971 +0100
    @@ -3,6 +3,7 @@

     [Service]
     User=kafka
    +EnvironmentFile=/etc/sysconfig/kafka

Anyway, I've found that with systemd setting rlimits are quite easy, and kafka needs quite a lot of them, so could you also add:

LimitNOFILE=65000 (or whatever someone specified in attributes ulimit_nofile)

@mthssdrbrg
Copy link
Contributor

Oh, wow, just realized that the systemd service template hardcodes /etc/sysconfig/<%= @daemon_name %>, I'll get on that in a minute, and I'll include the limit as well.

@mthssdrbrg
Copy link
Contributor

Latest master contains fixes for the two things that you mentioned, let me know if you find something else that should be fixed.

@mthssdrbrg mthssdrbrg reopened this Nov 24, 2014
@PAStheLoD
Copy link
Author

Currentely I don't have other kafka nodes to install, sorry :)

@mthssdrbrg
Copy link
Contributor

Alright, then I'll close this again as the integration tests passed :)

@lock
Copy link

lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants