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

Ability to exec processes in background mode #22

Closed
qk4l opened this issue Aug 11, 2018 · 20 comments
Closed

Ability to exec processes in background mode #22

qk4l opened this issue Aug 11, 2018 · 20 comments

Comments

@qk4l
Copy link
Contributor

qk4l commented Aug 11, 2018

Hi,

I'm looking on remco as a configuration manage tool inside containers for our cloud infrastructure.
We are using system OS containers with several applications inside and systemd is used as an init system.

remco is starting as a daemon before any services for which configs should be generated.
But here is a problem - there is not option to detect if remco's resources have been successfully proceed and services could be start.

To resolve this there is exec option (command) but it require foreground mode which is not suitable for systemd services. =(
Also I do not like an idea to run services in foreground mode because they will be killed if remco failed and died. It's ok if remco is used as a supervisor or init system (proc 1) but decrease reliability if it works as configuration management tool only.

I suggest to add additional option and allow to exec processes in background mode.

@HeavyHorst
Copy link
Owner

Isn't the check and reload commands what you need?
https://heavyhorst.github.io/remco/details/commands/

@qk4l
Copy link
Contributor Author

qk4l commented Aug 12, 2018 via email

@HeavyHorst
Copy link
Owner

I've added a start_cmd option.
The start command is executed only once at startup. If no start command is specified, the behavior is the same as before.

The config looks like:

  [[template]]
    src         = "/etc/remco/templates/test.cfg"
    dst         = "/home/rkaufmann/Downloads/remcotest"
    mode        = "0644"
    start_cmd  = "echo 'start'"
    reload_cmd = "echo 'reload'"

Could you try this with latest master to see if that works for you?

@qk4l
Copy link
Contributor Author

qk4l commented Aug 12, 2018 via email

@qk4l
Copy link
Contributor Author

qk4l commented Aug 12, 2018 via email

@HeavyHorst
Copy link
Owner

Youre right.
I moved the start_cmd to the resource configuration.
I'ts only executed after all templates are processed without errors.

   name = "someName"
   start_cmd  = "echo 'start'"
   [[template]]
     src         = "/etc/remco/templates/test.cfg"
     dst         = "/home/rkaufmann/Downloads/remcotest"
     mode        = "0644"
     reload_cmd = "echo 'reload'"

@HeavyHorst
Copy link
Owner

Maybe a reload_command at the resource level would also make sense.
This would be executed as soon as one of the templates changes (like the reload_signal in exec mode).

What do you think?

@qk4l
Copy link
Contributor Author

qk4l commented Aug 13, 2018

I've tested start_cmd but it not works.

# /usr/bin/remco -version
remco Version: 0.10.0
UTC Build Time: 2018-08-13 09:01:49
Git Commit Hash: 9eda77c9d22417a23c70d3bafa6dd47862bcd95c
Go Version: go1.10.1
Go OS/Arch: linux/amd64

resource.d/nginx.toml

name = 'nginx'
start_cmd = "systemctl start nginx"

[[template]]
  src        = "/etc/remco/test.tmpl"
  dst        = "/etc/test_remco"
  reload_cmd = "systemctl reload nginx"
[0000]  INFO /usr/bin/remco[29255]: loading resource configuration path=/etc/remco/resource.d/nginx.toml
[0000]  INFO /usr/bin/remco[29255]: [creating pid file at "/var/run/remco.pid"]
[0000] DEBUG /usr/bin/remco[29255]: retrieving keys backend=env key_prefix= resource=nginx
[0000] DEBUG /usr/bin/remco[29255]: compiling source template resource=nginx template=/etc/remco/test.tmpl
[0000] DEBUG /usr/bin/remco[29255]: comparing staged and dest config files dest=/etc/test_remco resource=nginx staged=.test_remco041936203
[0000]  INFO /usr/bin/remco[29255]: target config out of sync config=/etc/test_remco resource=nginx
[0000] DEBUG /usr/bin/remco[29255]: overwriting target config config=/etc/test_remco resource=nginx
[0000] DEBUG /usr/bin/remco[29255]: Running systemctl reload nginx resource=nginx
[0000] ERROR /usr/bin/remco[29255]: "Job for nginx.service invalid.\n" resource=nginx
[0000] ERROR /usr/bin/remco[29255]: createStageFileAndSync failed: sync files failed: reload command failed: the reload command failed: exit status 1 resource=nginx
[0000] ERROR /usr/bin/remco[29255]: not all templates could be rendered, trying again after 20 seconds resource=nginx
  • It seems that start_cmd is not processing
  • reload_cmd should not be triggered if start_cmd was called.

Maybe a reload_command at the resource level would also make sense.
This would be executed as soon as one of the templates changes (like the reload_signal in exec mode).

Great idea! I think there are cases when one template required a reload and other one does not, so it's better to make reload_cmd at the resource level optional and save it in template array.

This allow to define reload_cmd globally for resource and avoid duplicates but still save flexibility for each template.

@HeavyHorst
Copy link
Owner

Hm, the start_cmd is only executed after all templates are processed without errors.
The reload_cmd is a part of the template processing.

I will change the code so that the reload_cmd is not called if a start_cmd is provided (only at startup obviously).

Great idea! I think there are cases when one template required a reload and other one does not, so it's better to make reload_cmd at the resource level optional and save it in template array.

I plan to keep both reload commands: one per template for fine grained control and one on the resource level. Both are optional.

Thank you for your help!

@qk4l
Copy link
Contributor Author

qk4l commented Aug 13, 2018

Hm, the start_cmd is only executed after all templates are processed without errors.
The reload_cmd is a part of the template processing.

# /usr/bin/remco -config config.toml
[0000]  INFO /usr/bin/remco[49211]: loading resource configuration path=/etc/remco/resource.d/nginx.toml
[0000]  INFO /usr/bin/remco[49211]: [creating pid file at "/var/run/remco.pid"]
[0000] DEBUG /usr/bin/remco[49211]: retrieving keys backend=env key_prefix= resource=nginx
[0000] DEBUG /usr/bin/remco[49211]: compiling source template resource=nginx template=/etc/remco/test.tmpl
[0000] DEBUG /usr/bin/remco[49211]: comparing staged and dest config files dest=/etc/test_remco resource=nginx staged=.test_remco915523972
[0000]  INFO /usr/bin/remco[49211]: target config out of sync config=/etc/test_remco resource=nginx
[0000] DEBUG /usr/bin/remco[49211]: overwriting target config config=/etc/test_remco resource=nginx
[0000] DEBUG /usr/bin/remco[49211]: Running echo reload nginx resource=nginx
[0000] DEBUG /usr/bin/remco[49211]: "reload nginx\n" resource=nginx
[0000]  INFO /usr/bin/remco[49211]: target config has been updated config=/etc/test_remco resource=nginx

Even if template's render have finished successful start_cmd does not execute.

@HeavyHorst
Copy link
Owner

Are you sure that you're using the latest master branch?

cat /etc/remco/resource.d/test.toml

  name = "haproxy"
  start_cmd  = "echo 1"
  [[template]]
    src         = "/etc/remco/templates/test.cfg"
    dst         = "/home/rkaufmann/Downloads/remcotest"
    mode        = "0644"
    reload_cmd = "echo 'reload'"

  [backend]
    [backend.file]
      filepath = "/etc/remco/test.yml"
      watch    = true
      keys     = ["/"]
[0000]  INFO remco[8264]: loading resource configuration path=/etc/remco/resource.d/test.toml
[0000]  INFO remco[8264]: set file path backend=file filepath=/etc/remco/test.yml
[0000] DEBUG remco[8264]: retrieving keys backend=file key_prefix= resource=haproxy
[0000] DEBUG remco[8264]: compiling source template resource=haproxy template=/etc/remco/templates/test.cfg
[0000] DEBUG remco[8264]: comparing staged and dest config files dest=/home/rkaufmann/Downloads/remcotest resource=haproxy staged=.remcotest060591536
[0000]  INFO remco[8264]: target config out of sync config=/home/rkaufmann/Downloads/remcotest resource=haproxy
[0000] DEBUG remco[8264]: overwriting target config config=/home/rkaufmann/Downloads/remcotest resource=haproxy
[0000] DEBUG remco[8264]: Running echo 'reload' resource=haproxy
[0000] DEBUG remco[8264]: "reload\n" resource=haproxy
[0000]  INFO remco[8264]: target config has been updated config=/home/rkaufmann/Downloads/remcotest resource=haproxy
[0000] DEBUG remco[8264]: Running echo 1 resource=haproxy
[0000] DEBUG remco[8264]: "1\n" resource=haproxy
^C[0003]  INFO remco[8264]: Captured interrupt. Exiting...
[0003] DEBUG remco[8264]: closing client connection backend=file resource=haproxy

@qk4l
Copy link
Contributor Author

qk4l commented Aug 13, 2018

Yes, just have recompiled. =(

# /usr/bin/remco -version
remco Version: 0.10.0
UTC Build Time: 2018-08-13 13:18:09
Git Commit Hash: 9eda77c9d22417a23c70d3bafa6dd47862bcd95c
Go Version: go1.10.1
Go OS/Arch: linux/amd64

Latest commit - 9eda77c

@HeavyHorst
Copy link
Owner

What is the exact content of /etc/remco/resource.d/nginx.toml?

@qk4l
Copy link
Contributor Author

qk4l commented Aug 13, 2018

I simplify it as I can.

Here is tar with compiled remco and config directory.
remco.tar.gz

Something is wrong here =(

@HeavyHorst
Copy link
Owner

Your file doesn't work for me either.
Is your remco source by any chance not in $GOPATH/src/github.com/HeavyHorst/remco/cmd/remco?

Thats always the path the buildscript uses.
You could build it without the script:

  • go build github.com/qk4l/remco/cmd/remco

@HeavyHorst
Copy link
Owner

All import paths are like this: github.com/HeavyHorst/remco/pkg/template
It'd be the easiest thing if you worked from there.

@HeavyHorst
Copy link
Owner

I've also added the mentionend reload command.

I will change the code so that the reload_cmd is not called if a start_cmd is provided (only at startup obviously).

Also done.

let me know if you have any more problems building the source.

@qk4l
Copy link
Contributor Author

qk4l commented Aug 13, 2018

Oh, sorry, my mistake.
I should read more about golang building.

I've tested reload_cmd and start_cmd. Everything woks as expected.

Thank you very much!

@HeavyHorst
Copy link
Owner

Great! I will leave this issue open until i've added the documentation.

@LanceKroepke
Copy link

@HeavyHorst DOCU PLS?!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants