Discussion:
Own Salt Modules and Python Output
John Doe
2013-07-17 07:11:24 UTC
Permalink
Hi,
Im a bit new to salt and trying to write my own module.
so far it looks like

checkProcess = 'ps -ef | grep Main'
startProcess = 'pushd /test/process && ant run-process'
stopProcess = ' kill -9 Main'
def ctrl(operation):
if operation == 'start':
return __salt__['cmd.run'](startProcess)
if operation == 'stop'
return __salt__['cmd.run'](stopProcess)

i would like to add a condition to check if the process is up before
starting it but cant figure out how to return the output to the python
module.
meaning i want to add an if condintion to use checkProcess and if the
output for the 'ps -ef | grep Main' is 12345 Main to echo process is
already running, if it returns none to start the process.

appriciate any help
thanks a lot

John...
--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Colton Myers
2013-07-17 16:04:07 UTC
Permalink
In custom modules, the loader will automatically inject useful things like
the __salt__ dictionary. You can then use any salt module by way of that
dictionary. For example, you could use cmd.retcode:

ret = __salt__['cmd.retcode']('ps -ef | grep Main')

You should look into the various functions in the cmd module, I think they
might serve your purposes:
http://docs.saltstack.com/ref/modules/all/salt.modules.cmdmod.html

Hope that helps!

--
Colton Myers
Post by John Doe
Hi,
Im a bit new to salt and trying to write my own module.
so far it looks like
checkProcess = 'ps -ef | grep Main'
startProcess = 'pushd /test/process && ant run-process'
stopProcess = ' kill -9 Main'
return __salt__['cmd.run'](startProcess)
if operation == 'stop'
return __salt__['cmd.run'](stopProcess)
i would like to add a condition to check if the process is up before
starting it but cant figure out how to return the output to the python
module.
meaning i want to add an if condintion to use checkProcess and if the
output for the 'ps -ef | grep Main' is 12345 Main to echo process is
already running, if it returns none to start the process.
appriciate any help
thanks a lot
John...
--
You received this message because you are subscribed to the Google Groups
"Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Loading...