• Uncategorized

About linux : how-to-write-a-linux-service-to-start-a-service-on-computer-A-after-a-service-in-computer-B-is-up-and-runningcomputer-A-and-B-are-in-same-network

Question Detail

in my senario I have an linux service on computer that need to run after a service in computer B(computer A and B are in same network).how can I use system.d to do this job?

Question Answer

There are several solutions to this scenario, the simplest solution is to write a bash script like bellow.
before that you should set ssh-key between 2 linux computer.

at first open a file.

   nano /usr/bin/script.sh 

and Put the following line in it.

#!/bin/bash
ssh root@computerA  'systemctl start YOURServicName'

now you need to run this bash Script as SystemD Service in computer B.

[Unit]
Description=My Shell Script

[Service]
ExecStart=/usr/bin/script.sh

[Install]
WantedBy=multi-user.target

for more info use this link.

Finally
You need to add this line in your B.service file:

After=A.service

I hope my explanation was useful.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.