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.
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.
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.
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.