Page 1 of 1

Systemd service for boot-loader kind of implementation

Posted: 2018/02/13 12:26:46
by ravinathwani
We have a requirement where multiple application versions can be installed simultaneously on a system.
There exists a boot-loader.conf file that lists app versions along with a config file for each version associated to a boot-priority.
The requirement is to iterate over this file and
- start an app version at the least boot-priority with specified config file
- if app fails to start, iterate to next app version
- if app starts successfully and later is killed/crashes, restart the app (of earlier running version)

To achieve this on CentOS 6, following sys V init scripts were written
- boot-loader service (iterates over boot-loader.conf file and starts the app service)
- app service (starts the app with appropriate config file)
- boot-loader waits till the app service is started successfully
- monit was used to monitor the app service and restart if not running
Note: Both boot-loader and monit used 'service app start' to start the app.

With CentOS 7 and systemd, we thought of getting rid of monit and use systemd integrated service monitoring.
Hence the init scripts were migrated to
- boot-loader service with type=oneshot and RemainAfterExit
- app service with type=simple, After=boot-loader.service and Restart=always

Somehow, these seem to not work, since the boot-loader needs to wait for the app to successfully start and the app is not started till boot-loader exits.
What are the possible ways to implement such a behaviour?

Re: Systemd service for boot-loader kind of implementation

Posted: 2018/02/15 04:55:32
by hunter86_bg
This line

Code: Select all

After=boot-loader.service 
indicates that boot-loader should be over before starting your service.
Maybe the easiest way should be boot-loader to call the app service, but this means to incorporate a watchdog.

I think that there is a flaw in the design and most probably creation of single app service with

Code: Select all

ExecStartPre=boot-loader-script &
would do as intended, but the logic should be adapted.