I'm using saltstack minion on Windows.
I would like to always check if an application is started. Restarts if it crashes. And also add the possibility to stop it.
The application is not a Windows service. But I would like to simulate the service with saltstack.
I've check the cmd.run but i'm not sure how to use it. It seems this command wait for the exit of my application. But I don't want to exit
Thank you.
Salt only runs commands when you tell it to. You may want to use the service beacon if you want to constantly check the status of a service.
The service beacon will check once a second (or whatever interval you prefer) and send an event on Salt's event bus when the status changes.
Then you could make salt reactor that will start up the service that has gone down.
Beacon description here: http://docs.saltstack.com/en/latest/topics/beacons/
Service beacon description here: http://docs.saltstack.com/en/latest/ref/beacons/all/salt.beacons.service.html#module-salt.beacons.service
Related
On Raspberry Pi with Arch Linux there is a service active called serial-getty#AMA0.
The unit file is: /usr/lib/systemd/system/serial-getty#.service
As root I can invoke
systemctl stop serial-getty#ttyAMA0
systemctl disable serial-getty#ttyAMA0
But after reboot the service is enabled and running again.
Why is the service enabled after disabling it? How can I disable it permanent?
UPDATE
systemd uses generators at /usr/lib/systemd/system-generators/ is a binary called systemd-getty-generator. This binary runs at system start and adds the symlink serial-getty#ttyAMA0.service to /run/systemd/generator/getty.target.wants.
I eventually found a dirty solution. I commented out all actions in /usr/lib/systemd/system/serial-getty#.service. The service did appear to start anyway, but without blocking ttyAMA0.
The correct way to stop a service ever being enabled again is to use:
systemctl mask serial-getty#ttyAMA0.service
(using ttyAMA0 as the example in this case). This will add a link to null to the entry for that service.
Try this code:
system("systemctl stop serial-getty#ttyAMA0.service");
system("systemctl disable serial-getty#ttyAMA0.service");
I use it, and it works well.
How to implement a state that wait for other minions finishing certain jobs then execute certain state?
For example, I have a cluster of minions called minion-aha1 to minion-aha3, and I install hadoop and hbase on these 3 minions. Now, I would like to convert them to HA mode. Suppose minion-aha1 is the leader. So the logic flow would be:
Start hadoop and hbase on all 3 minions
-> minion-aha1 wait till rest of minions are hadoop and hbase are on and healthy
-> minion-aha1 call join (e.g. stop namenode, hdfs namenode -initializeSharedEdits, start namenode)
-> rest minions call nn2 (e.g. hdfs namenode -bootstrapStandby, start namenode)
I already knew how to convert hbase to HA mode, and I could set the leader in grain, just curious on how to shrink above procedure to single-line, i.e.
salt 'minion-aha*' state.apply hadoop.hbase_to_ha
Or even salt.orch state would be acceptable. The above would fail due to minion-aha1 never know the state of rest of minions. In other words, it might run successfully once if the developer is lucky, but I look for the solution would run successfully every time.
Thank you.
If you want to solve this without making use of an Orchestration SLS, you could look at one of the following approaches:
use the Salt Mine to publish information from a Minion to the Master, which can then be retrieved by another one
use Peer Communication to allow one Minion to generate a job to be executed on another one
Basically I benefit from this answer with some modification:
Trigger event on Master and wait for "response event" on Salt Minion
For custom event sent to the salt master, e.g. mycompany/hbase/status/*/start, I have to send event -> saltutil.sync_all, then the wait_for_event.
I will try to post a question since I want to use RxAndroidBle. I want to connect to a device even though I am not running my application, I don`t mind if any service is running. Moreover if possible when I get close to the device with my phone, it automatically launches the application. What would be the drill for something like this?
You could register broadcast receiver with specific filter which will wakes up your app when BLE device is available
Background: I have several servers which run a service I develop. All of them should have the same copy of the service.
To ensure deployment and up-to-dateness I use Ansible, with an idempotent playbook which deploys the service. Since the servers are on an unreliable network, I have to run the playbook periodically (in a cron job) to reach the servers which may not have been available before.
Problem: I was under the impression that the SaltStack philosophy is different: I though I could just "set a state, compile it and offer to a set of minions. These minions would then, at their own leisure, come to the master and get whatever they need to do".
This does not seem to be the case: the minions which were not available at deployment time are skipped.
Question: is there a mechanism which would allow for an asynchronous deployment, in the sense that a state set on the master one time only would then be pulled and applied by the minions (to themselves) once they are ready / can reach the master?
Specifically, without the need to continuously re-offer the same state to all minions, in the hope that the ones which were unavailable in the past are now capable to get the update.
Each time a minion connects to the master there is an event on the event bus which you can react upon.
Reactor
This is the main difference between Ansible and Saltstack.
In order to do what you want, I would react on each minion's reconnect and try to apply a state which is idempotent.
Idempotent
You could also setup a scheduled task in Saltstack that runs the state every X minutes and apply the desired configuration.
Scheduled task
The answer from Daniel Wallace (salt developper):
That is not possible.
The minions connect to the publish port/bus and the master puts new
jobs on that bus. Then the minion picks it up and runs the job, if the
minion is not connected when the job is published, then it will not
see the job.
My description could be a little vague because I have not big experience in this field.
The problem is that my web service should do the following steps.
Another service send phone number in my web service
My web service takes that number and start calling into a particular queue in asterisk
After someone in this queue pickup call he\she should hear a recorded audio message
After that astersik should dial to the phone number from first step
Right now I can call to a local extension and then asterisk do the rest by calling to a client and connecting him with manager.
The first problem is that I don't know how to dial not to a local extension but to a queue in asterisk.
The second issue is how to play audio only when manager pick up call made from my web service.
Would be appreciate any help.
IF you use freepbx, you should put message in Call Confirm Announce
If you use custom dialplan, you should use M option for dial command and create macro which will play needed file.
For dial queue in freepbx you have use queue_num#from-internal. No way give any suggestion for custom dialplan
Note: doing system like that without understanding asterisk internal can result hi bills for international calls becuase of hackers.