https://github.com/swisscom/mcollective-cmd-agent
This is a fork of the puppetlabs shell agent with ruby 1.8.7 support and additional features. https://github.com/puppetlabs/mcollective-shell-agent
https://github.com/swisscom/mcollective-cmd-agent
Last synced: 8 months ago
JSON representation
This is a fork of the puppetlabs shell agent with ruby 1.8.7 support and additional features. https://github.com/puppetlabs/mcollective-shell-agent
- Host: GitHub
- URL: https://github.com/swisscom/mcollective-cmd-agent
- Owner: swisscom
- License: apache-2.0
- Created: 2016-01-05T08:07:52.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-03-27T11:36:20.000Z (about 10 years ago)
- Last Synced: 2023-08-04T09:23:20.184Z (almost 3 years ago)
- Language: Ruby
- Size: 65.4 KB
- Stars: 2
- Watchers: 17
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
> [!NOTE]
> DEPRECATED - no longer maintained!
# Cmd agent
This is a fork of the puppetlabs shell agent with ruby 1.8.7 support and
additional features.
[](https://travis-ci.org/swisscom/mcollective-cmd-agent)
The cmd agent allows you to start and manage shell commands via
mcollective.
It allows the running of long-running processes with a mechanism to check in
on the output from these long-running processes, which is independent of the
mcollective daemon process (the daemon can be restarted without interrupting
the processes)
To use this agent you need at least:
* MCollective 2.2.4
* For Ruby 1.8.7 support: 'posix-spawn' and 'uuid' gem
Please note: we do not recommend this agent as a way of building out your
automation, for that you're still better off writing your own tailored
[agents][writing-agents] that fit your use case. This agent is targeted
at the ad-hoc needs that people occasionally have.
[writing-agents]: http://docs.puppetlabs.com/mcollective/simplerpc/agents.html
## Installation
Follow the [basic plugin install guide][install guide], taking all
the code from lib and adding it to your MCollective $libdir
[install guide]: http://projects.puppetlabs.com/projects/mcollective-plugins/wiki/InstalingPlugins
## Configuring the agent
The agent should work without any additional configuration, though there are
some options you can tune the mcollective server.cfg.
### `plugin.cmd.state_directory`
This is where the state used to track processes will live. By default this
will be /var/run/mcollective-cmd on Unix systems.
```
plugin.cmd.state_directory = /opt/run/mcollective-cmd
```
## Application usage
The `mco cmd` application has several subcommands to start and manage
processes.
### mco shell run
Runs a command and reports back. Use this for discrete short-living commands.
For long-running commands look at `start` or `run --tail`.
```
$ mco cmd run dir
* [ ============================================================> ] 2 / 2
master:
bin dev home lib64 media opt root selinux srv tmp vagrant
boot etc lib lost+found mnt proc sbin src sys usr var
server2008r2a:
Volume in drive C has no label.
Volume Serial Number is DADF-75F9
Directory of C:\
09/22/2012 11:45 AM manifests [\\vboxsrv\manifests]
09/22/2012 11:45 AM modules [\\vboxsrv\modules]
07/13/2009 08:20 PM PerfLogs
09/22/2012 11:42 AM Program Files
03/27/2014 06:52 AM Program Files (x86)
07/03/2014 07:42 AM src [\\vboxsrv\C:_src]
03/27/2014 06:39 AM Users
07/03/2014 07:42 AM vagrant [\\vboxsrv\vagrant]
03/27/2014 06:41 AM Windows
0 File(s) 0 bytes
9 Dir(s) 34,565,091,328 bytes free
Finished processing 2 / 2 hosts in 221.28 ms
```
### mco cmd run --tail
Starts a command, shows you the output from it, kills the command when you
interrupt with control-c, exits normally when the command exits.
```
$ mco cmd -I /master/ run --tail vmstat 1
* [ ============================================================> ] 1 / 1
master stdout: procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
master stdout: r b swpd free buff cache si so bi bo in cs us sy id wa st
master stdout: 0 1 445812 120584 5808 37348 34 29 52 48 39 47 6 1 93 0 0
master stdout: 1 0 445112 122692 5824 37332 2692 0 2692 84 911 2089 47 9 40 4 0
master stdout: 1 0 444848 122576 5824 37344 288 0 288 0 773 1914 48 5 47 0 0
master stdout: 0 0 444012 121320 5824 37348 1212 0 1212 0 823 1917 47 6 45 1 0
master stdout: 0 0 443984 121204 5824 37372 0 0 0 0 797 1796 52 5 43 0 0
master stdout: 0 0 438800 117244 5824 37360 3896 0 3896 0 910 2123 49 6 45 0 0
master stdout: 1 0 438768 117136 5840 37368 0 0 0 136 811 1926 48 6 45 0 0
^CAttempting to stopping cleanly, interrupt again to kill
Sending kill to master 6dad5cb9-57f7-46e0-bad7-07ab117369a5
```
### mco cmd start
Starts a command in the background and tells you the id that has been assigned
to it. You can then use `mco cmd watch`, `mco shell kill`, `mco shell list`
to monitor this process and observe its output
```
$ mco cmd -I /master/ start vmstat 1
* [ ============================================================> ] 1 / 1
master: 0dd67fac-734f-4824-8b4d-03100d4f9d07
Finished processing 1 / 1 hosts in 76.37 ms
```
### mco cmd watch
Shows you the output of a command you previously started with `mco cmd start`
```
$ mco cmd watch 0dd67fac-734f-4824-8b4d-03100d4f9d07
* [ ============================================================> ] 2 / 2
master stdout: procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
master stdout: r b swpd free buff cache si so bi bo in cs us sy id wa st
master stdout: 2 0 431448 110704 8484 40644 34 29 52 48 40 47 6 1 93 0 0
```
### mco cmd list
Show a list of running jobs.
```
$ mco cmd list -v
* [ ============================================================> ] 2 / 2
master:
0dd67fac-734f-4824-8b4d-03100d4f9d07
1fd3961a-f48d-4119-b988-146b490a5ca3
d174e20b-9cdb-4c14-9f34-fd29995f30cb
ea809b20-3123-46b4-bf59-10ff7251ca9b
Finished processing 2 / 2 hosts in 142.34 ms
```
### mco cmd kill
Kill a running job.
```
$ mco cmd kill 0dd67fac-734f-4824-8b4d-03100d4f9d07
* [ ============================================================> ] 2 / 2
Finished processing 2 / 2 hosts in 170.17 ms
```
### mco cmd clean
Cleanup an old job
```
$ mco cmd clean 0dd67fac-734f-4824-8b4d-03100d4f9d07
* [ ============================================================> ] 2 / 2
Finished processing 2 / 2 hosts in 110.23 ms
```