0

For example if I had two service files that ran as type=forking that start two different java applications and then two service files that run as type=simple running different applications, is there a way to run another service file that would start/stop the other four but the other four can still be used independently?

for example:

dataingest-type1.service
dataingest-type2.service
different-dataingest.type3.service
different-dataingest.type4.service

All run properly as separate services under systemd.

Could a service, like dataingest.service, start/stop the other four?

Also if one of the other services went down and the dataingest.service was run again it should start the service again. (basically I tried making a script that runs systemctl start <list of services> and set it up as a service, however if one of the services stops and the service start is run again it does not run the script as it thinks the service is running.)

So the dataingest.service looked like this:

[Unit]
Description=Stuff blah blah
Requires=network.target
After=network.target

[Service]
Type=oneshot  
ExecStart=/path/to/little/script.sh start
ExecStop=/path/to/little/script.sh stop
RemainAfterExit=true

[install]
WantedBy=multi-user.target

The bash script just does one job!

#/bin/bash

/bin/systemctl $1 dataingest-type1.service dataingest-type2.service different-dataingest.type3.service different-dataingest.type4.service

Obviously if there is a better method.....

0

Welcome to Ask Ubuntu.

This is one uses of systemd .targets.

There's already an answer to this question in the StackExchange network at How to create a virtual systemd service to stop/start several instances together?

|improve this answer|||||
1

So using The link provided by @Mark I could workout what needed to be done.

The main service, dataingest.service, needed to be a target instead so renamed as dataingest.target The dataingest.target unit had the following:

[Unit]
Description=Data Ingest Services
Requires=network.target
After=network.target
Wants=dataingest-type1.service dataingest-type2.service different-dataingest.type3.service different-dataingest.type4.service

[Install]
WantedBy=multi-user.target

Then the individual services had something similar to the following:

[Unit]
Description=type x data ingest service
PartOf=dataingest.target

[Service]
Type=......
etc
etc
etc

[Install]
WantedBy=dataingest.target

Then systemctl enable dataingest..... followed by a reload.

Now the services can be started individually and also just using the target file. sudo systemctl start dataingest.target

Also if one of the services is down the target unit will start the individual service.

Thanks @mark

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.