I have a java application with 4 processes running (on Ubuntu 20.04LTS), ref below picture. Service 1 starts before 2+, Service 2 would also start service 3 and 4.
I've setup 1 and 2 as simple and that works.
service dependencies, service 2 starting service 3 and 4
However, service 3 and 4 can be stopped/restarted independently of service 2. Is there a way to implement this into the service definition app-service4.service?
I've looked at blog post describing a similiar case, so based upon that I Think defining service 3 and 4 with "PartOf" service 2 may be a way, but how to make service 3 and 4 understand it was already started by service 2?
Below is the service2.service
[Unit]
Description=Service 2
After=service1.service
[Service]
ExecStart=/usr/local/bin/service2.sh start
ExecStop=/usr/local/bin/service2.sh stop
[Install]
WantedBy=default.target
After startup the status on the service show a CGroup like below (pid and names etc simplified)
/system.slice/service2.service
|- 123 /bin/sh /usr/local/bin/service2.sh start
|- 124 java service2
|- 125 java service3
|- 126 java service4
So how do I add a service3.service which would allow me to bring down/restart service3 without terminating service2? Below is my attempt which is not able to understand service2 is already running.
[Unit]
Description=Service 3
PartOf=service2.service
[Service]
ExecStart=/usr/local/bin/service3.sh start
ExecStop=/usr/local/bin/service3.sh stop
[Install]
WantedBy=default.target
With this setup after service2 is started "systemctl status service2" shows up service2-servic4 processes as mentioned above, and "systemctl status service 3" shows up as "inactive (dead)". An attempt to start service 3 (systemctl start service3) ends up stopping the same (as it was already running, the start command terminates upon which the stop command is executed).If I re-attempt the start it would start as a separate service.
I'd like the daemon to understand that the process under service-2 is actually service-3, hence service-3 would appear as running. Is this possible?
If not - is there any work-around to allow separate handling of the services?