2
3
I have created a systemd service file, whose task is nothing, but just to bring up other services, and bring them down as well.
Since it does nothing, other than bringing up other services, i have put an echo to ExecStart
and ExecStop
.
The issue is, i can see the dependencies are brought up fine when i invoke service <myService> start
, but they are not stopped when i call service <myService> stop
. Even using BindsTo
does not work.
Here is my service configuration file:
[Unit]
Description=Starts the DCCA index software
Requires=mysql.service ifmFuseHandler.service
After=mysql.service ifmFuseHandler.service
BindsTo=mysql.service ifmFuseHandler.service
[Install]
WantedBy=multi-user.target
[Service]
ExecStart=/bin/sh -c "echo 'Index started'"
ExecStop=/bin/sh -c "echo 'Index stopped'"
# Execute pre and post scripts as root
PermissionsStartOnly=true
Restart=on-failure
TimeoutSec=600
Type=forking
RemainAfterExit=yes
Solution:
As suggested by @grawity
i created a .target file called index-start.target as below:
[Unit]
Description=Starts the DCCA index software
Requires=mysql.service ifmFuseHandler.service
After=mysql.service ifmFuseHandler.service
BindsTo=mysql.service ifmFuseHandler.service
[Install]
WantedBy=multi-user.target
And a service file called index.service:
[Unit]
Description=Starts the DCCA index software
Requires=index-start.target
After=index-start.target
[Install]
WantedBy=multi-user.target index-start.target
[Service]
ExecStart=/bin/true
ExecStop=/bin/sh -c "echo 'Index stopped'"
# Execute pre and post scripts as root
PermissionsStartOnly=true
#Restart=on-failure (Commented as does not work with type=oneshot)
TimeoutSec=600
Type=oneshot
RemainAfterExit=yes
And when invoked, service index start
it starts the dependencies and service index stop
it stops the dependencies.
I just tried it once as-is using
type=oneshot
but it does not bring down the dependencies. I tried usingExecStop=/bin/false
but looks like it does not exist, like/bin/true
does. Pardon my ignorance, but is there a way out to stop it, usingtype=oneshot
which you mentioned? Although, i wish to make it full-proof using thetarget
later, but just for hands-on sake tried it. – kingsmasher1 – 2016-01-12T11:35:44.610I tried using the
.target
but the issue is, there is no way to manually start or stop the service using theservice xxxx start
orservice xxxx stop
, which is also a required part, in addition to starting at boot time. Any way out? – kingsmasher1 – 2016-01-12T11:50:17.087I created a .target file, as u indicated, and the same is edited and posted above. It works as expected, thanks. – kingsmasher1 – 2016-01-12T14:00:53.130