Systemd service for boot-loader kind of implementation
Posted: 2018/02/13 12:26:46
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?
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?