chef runit example
When working with the runit cookbook, you may define a service like this:
and then you’d have to create the following template files:
and
1
sv-your_name-run.erb
. In the 1
sv-your_name-log-run.erb
template you’d have something
like this:1
sv-your_name-run
of course, it’s kind of dumb to just echo date, and have that ran as a service, but, hey, it’s just an example. Basically, runit will make sure that the service will be restarted if it goes down. So, in the case above, you will get a new line in log.txt about once a second.
Notice that in the runit_service I’m setting the env attribute. This has the effect of
passing environment variables to runit, which will be creted in the env folder. That’s why
the
part is there in the run script.1
-e env
The second template, I usually put it like this:
and this will have the effect of sending the logs to
.
Of course, the logs will be sent to that file if you’re logging to STDOUT. As an extra
attribute, I’m setting 1
/etc/service/your_name/log/main/current
, which allows us to write a script to check if our
service is running. It’s template file will be 1
check true
. You can put anything
you want in it, as long as you exit with a 0 code. For example, to check that a ruby
script was running as a service, I did something like this:1
sv-ruby-your_name-check.erb
If the check script writes output to stdout, it causes a write error. That’s why I’m redirecting to /dev/null.
To start/stop/restart/view logs:
fixing hibernation on ubuntu 16.04
After updating to 16.04, hibernation wasn’t working anymore. Found the fix here:
Reboot, and then it should work again.
random examples of working with knife zero
This is the config I’ve used with knife zero:
- configure a kitchen.yml file with a private network ( I will assume 192.168.33.15 is the IP ):
kitchen create
- bootstrap it with
:1
knife zero
knife zero bootstrap 192.168.33.15 --ssh-user vagrant --sudo
- this will ask you for your password, then proceed with the installation of chef
- after the command is done, you should have a new entry in the nodes folder
simple chef-zero setup
Simple Chef-Zero setup
- create folder
1
my-chef
1
cd my-chef
1
mkdir .chef
1
ssh-keygen -f local.pem -P ""
1
ssh-keygen -f validation.pem -P ""
- add this to knife.rb:
- make sure to start chef-zero on port 9901:
chef-zero --port 9901
- make a folder
at the same level as .chef1
nodes
- add some data in
1
nodes/lenode.json
- cd to same level as nodes folder
- upload them:
on configuring chef-server locally
After reading this article, not all the steps applied in my case. I’ve pasted the steps I had to take on my system, to get chef-dk 0.11.0-1_amd64.deb to work on the listed CentOs.
Steps to configure chef-server locally
- use this kitchen file:
- with this recipe:
- do a kitchen converge
- open https://192.168.33.7 in your browser
- login as admin/p@assw0rd1
- change password
- create user geo with whatever password, make him an admin
- on the screen there will be a private key shown, copy that and save it locally to a file named geo.pem
- in chef-repo create a .chef folder
- copy geo.pem there
- we need to copy the chef-validator from the host scp root@192.168.33.7:/etc/chef-server/chef-validator.pem .
- add a new entry to /etc/hosts with the following content:
192.168.33.7 default-centos65
- in .chef, create a file called knife.rb with the following content:
- the content of .chef should be:
.chef/ geo.pem knife.rb chef-validator.pem
- test that server is accessible:
$ knife client list chef-validator chef-webui
Potential problems you may encounter
- I encountered this initially, when running knife client list
➜ chef-repo git:(master) ✗ knife client list ERROR: SSL Validation failure connecting to host: default-centos65.vagrantup.com - hostname "default-centos65.vagrantup.com" does not match the server certificate ERROR: SSL Error connecting to https://default-centos65.vagrantup.com/clients, retry 1/5 ERROR: SSL Validation failure connecting to host: default-centos65.vagrantup.com - hostname "default-centos65.vagrantup.com" does not match the server certificate
- fix for it was to run knife ssl check, where I saw the following:
➜ chef-repo git:(master) ✗ knife ssl check Connecting to host default-centos65.vagrantup.com:443 ERROR: The SSL cert is signed by a trusted authority but is not valid for the given hostname ERROR: You are attempting to connect to: 'default-centos65.vagrantup.com' ERROR: The server's certificate belongs to 'default-centos65'
- then, I just changed the entry from default-centos65.vagrantup.com to default-centos65 in /etc/hosts
- also, I went in knife.rb and I changed chef_server_url from:
chef_server_url "https://default-centos65.vagrantup.com:443"
to
chef_server_url "https://default-centos65:443"
- next, run another knife ssl check, and you should see this output:
➜ chef-repo git:(master) ✗ knife ssl check Connecting to host default-centos65:443 Successfully verified certificates from `default-centos65'