We have defined a "[email protected]" file which handles our application server starts. On some servers there are a lot of application servers and we hit issues where one or two servers won't start.
This is a RedHat Enterprise Linux 7 server.
Is there a way to limit the number of concurrent / simultaneous processes for this one service?
The service file:
[Unit]
Description=Appserver Instance %i
After=network.target
[Service]
Type=forking
ExecStart=/custom/server start %i
ExecStop=/custom/server stop %i
PIDFile=/custom/servers/.pid/%i.pid
User=%i
SuccessExitStatus=1
TimeoutStartSec=600
TimeoutStopSec=60
[Install]
WantedBy=multi-user.target
Target is that all servers should start, but at boot time I don't want all of them to start at the same time. They should all be able to run at the same time.
If you don't care about the ordering, you can use an
ExecStartPre
with a small variable sleep.ExecStartPre=/bin/bash -c 'sleep $(( RANDOM % 5 ))'
should make batch them into five buckets, each delayed by a second. If you need to control the order, you can use a.path
unit per instance and a limiter that touches the paths in the order you want.