I actually have a server at home where I run some custom daemons to control some things, first of all my surveillance system.
I would like to be able to tell Mycroft to start/stop/status a linux service.
Have anyone already developed something like that?
Is there around any library that would help me to discover services and launch them?
Any idea how to begin?
I set up development studio and already working on another skill.
About this I feel like I just don’t know enought of python to handle this.
Will look around the internet while waiting for any hint from the community.
Well if you’re really lazy…
On the raspberry pi, to start / stop a linux server you simply run
sudo service myservicename start|stop. So what you could do is follow the documentation and create a new skill. When the user says “Start|Stop service XXX”, you match XXX to a service name. Then using python, run the bash command
sudo service myservicename start|stop. It’s not pretty, but it should get the job done.
So step 1 would probably be get a basic “Hello World” skill working - for example, make a skill that does this: When the user says “Make me a sandwich”, Mycroft replies with “Nope” (or something simple).
Step 2: Get some RegEx going. Following their documentation, make a skill that does this:
If the user says “Stop service”, Mycroft says “You said Stop”.
If the user says “Start service”, Mycroft says “You said Start”. (Don’t make two skills - make one skill that can listen for both keywords).
Step 3: More RegEx! Make a skill that does this:
If the user says “Stop service Lights”, Mycroft says “Stopping service Lights”.
If the user says “Start service Surveillance”, Mycroft says “Starting service Surveillance”.
Step 4: Actually stop the service.
Instead of just saying “Stopping service Lights”, run the command
sudo service lights stop. You can do this the proper way (Subprocess.Popen and all that stuff) or you can just cheat and use os.system.
Good luck! If you ever get stuck, I’m sure many community members will be very glad to help you.
Thanks for your extensive reply.
I will look into it step by step as you suggested.
I’m actually developing another skill but I’m stuck with library dependency.
Considering Mycroft will run on a different machine than the server that owns services I will need to find the python way to ssh connect and run a command.
Or you can once again be lazy
Use sshpass to ssh from command line with a password argument: http://unix.stackexchange.com/questions/38737/ssh-login-with-clear-text-password-as-a-parameter
Then (not tested) you could do something like
sshpass -p 'YourPassword' ssh user@host "sudo service myservice stop"
Might be better to use keys rather than using a clear text password, especially since it doesn’t introduce a non-standard, non-python dependency. It should be pretty easy to set up - I only skimmed it, but this looks like a decent guide.
For doing things in a more “proper” python way, paramiko is probably the way to go. Though this adds a dependency with a lot of bloat you probably don’t need, it has the benefit of being a pure, platform agnostic, python dependency; you don’t have to depend on ssh (or sshpass) being installed, or even supported.