systemctl script froze - how to do to prevent this?

in #beempy6 years ago (edited)

My script to record all played steemmonster games from https://beempy.com froze:

image.png

I restarted the script (I'm using systemctl for this) and it is now catching up.

How to prevent a frozen script

There was no bug, it just froze. This happend already before and I will now try to fix this.
I'm thinking of restarting the systemctl service every day. By this, a frozen script can only lead to a maximum stop of 24 hours.

Possible ideas to implement this:

  • cron job with a systemctl restart service_name
  • systemctl timer with a systemctl restart service_name
  • Using RuntimeMaxSec

Cron job

A new rule can be entered by:

sudo crontab -e

The new rule could look like:

0 0 * * * /bin/systemctl restart yourService

systemctl timer

We need two files, one restart_service.timer

[Unit]
Description=Do something daily

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

and a restart_service.service:

[Unit]
Description=Restart service

[Service]
Type=oneshot
ExecStart=/usr/bin/systemctl try-restart my_program.service

They have to be copied to /etc/systemd/system and can be started by:

systemctl enable --now restart_service.timer

RuntimeMaxSec

When systemctl is newer than version 229, this is a good solution. The version can be found out by:

systemctl --version

The manual says about RuntimeMaxSec:

Configures a maximum time for the service to run. If this is used and the service has been active for longer than the specified time it is terminated and put into a failure state. Note that this setting does not have any effect on Type=oneshot services, as they terminate immediately after activation completed. Pass "infinity" (the default) to configure no runtime limit.

This seems to be exactly what I need.

Restart and RuntimeMaxSec has to be added to the service file in the [Service] part:

[Service]
Restart=always
RuntimeMaxSec=10800

This works for my scripts as they do not run forever. I'm using RestartSec to restart the script when it is finished.

Conclusion

RuntimeMaxSec seems to me a good measure to robustify systemctl scripts. I will try this on my systemctl services.

Sort:  

Couldn't you run your service in a docker container.
To

  • make it more secure
  • implement a healthcheck
  • restart if healthcheck fails

Thanks I will look into docker

Posted using Partiko Android

Something else I noticed about the script @holger80 is that Crustacean King is being cited in broken arrows teams but that monster can't be played under than rule. Or maybe I'm misunderstanding the rule as I've just played it and my opponent did indeed use the Crustacean King.

Crustacean King on level2 doesn't have ranged attack.


:)https://steemmonsters.com/?battle=8eec9c1ffa6296524167ed0017444d72b1ce9b41

Ah. Useful to know @jacekw although crusty is appearing in the results of the higher leagues and higher mana in broken arrows. Presumably they are not playing higher level cards there.

You will see him here, for example https://beempy.com/static/sm_decks_ranking_champion_28_Broken_Arrows.html

Thank you so much for participating in the Partiko Delegation Plan Round 1! We really appreciate your support! As part of the delegation benefits, we just gave you a 3.00% upvote! Together, let’s change the world!

Hi, @holger80!

You just got a 2.72% upvote from SteemPlus!
To get higher upvotes, earn more SteemPlus Points (SPP). On your Steemit wallet, check your SPP balance and click on "How to earn SPP?" to find out all the ways to earn.
If you're not using SteemPlus yet, please check our last posts in here to see the many ways in which SteemPlus can improve your Steem experience on Steemit and Busy.

Hi @holger80!


Your UA account score is currently 7.363 which ranks you at #61 across all Steem accounts.
Your rank has not changed in the last three days.Your post was upvoted by @steem-ua, new Steem dApp, using UserAuthority for algorithmic post curation!

In our last Algorithmic Curation Round, consisting of 208 contributions, your post is ranked at #2. Congratulations!

Evaluation of your UA score:
  • Your follower network is great!
  • The readers appreciate your great work!
  • Great user engagement! You rock!

Feel free to join our @steem-ua Discord server

This post has been included in the latest edition of SoS Daily News - a digest of all you need to know about the State of Steem.