1

So I have this systemd service file that acts as a template (using %i) for a handful of equal services that act as the workers for a pool.

[Unit]
Description=Bot %i

[Service]
Environment=
User=limitedPermission
WorkingDirectory=${installFolder}
ExecStart=${installFolder}/run_bot.sh --bot-number %i
Restart=on-failure

[Install]
WantedBy=multi-user.target

This script is enabled for instances bot@01 to bot@07, so that 7 instances are spawned when the system starts.

This works, however the indiviual instances require a tremendous amount of resources (CPU cycles and RAM) on startup, slowing down each other when starting all at the same time. Sometimes taking almost 20 minutes. After startup the instances have loaded all their required data and keep idling, requiring almost no resources in this state.

When starting them individually the whole process is a lot faster, a single instance takes less than a minute to start when having no limitations to system resources.

So here's what I want to achieve: Ideally the startup of the bots is delayed by a certain amount of time when the script detects that another instance of itself was started in less than said time.

I have found this question that applies a delay, but only for a single instance which is not what I need. I thought about random delays (which would easily work with this solution) which would probably be a good hack on average and wouldn't require the scripts to know of each other, but this would also kick in when starting/restarting the instances individually because something locked up which is clearly not the goal.

  1. Is there a better way to solve starting the services one after another?

  2. Also, how would I check if another instance has been started recently?

rubo77
  • 19,527
  • 31
  • 134
  • 226
RoiEX
  • 1,186
  • 1
  • 10
  • 37

0 Answers0