Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled restart don't work from cron or systemd timers #74

Open
raptikCZ opened this issue Jan 6, 2025 · 2 comments
Open

Scheduled restart don't work from cron or systemd timers #74

raptikCZ opened this issue Jan 6, 2025 · 2 comments

Comments

@raptikCZ
Copy link

raptikCZ commented Jan 6, 2025

Hi,

suddenly restarts stops working aproximatly around 26.december 2024 stops working on my fedora 41 server

(i am using ark-manager - it is renamed POK-manager, but i have inside litle tweaks for creating yaml configs for selinux - it adding :rw,z in volumes paths. without it, it cant be correctly used on this server machine with selinux)

in crontab -e:

0 */12 * * * /home/container/docker/ark-asc/ark-manager.sh -restart 15 -all
0 */6 * * * /home/container/docker/ark-asc/ark-manager.sh -backup -all
*/10 * * * * /home/container/docker/ark-asc/ark-manager.sh -saveworld -all

backups and saveworld working fine
i tried adapt it to systemd timers unit, use in separate shell script, or run it as root - it leads to same behavior

directly from command line or in script it can be run ( /home/container/docker/ark-asc/ark-manager.sh -restart 15 -all )
but if is used in cron or systemd timers (both under user for contanier or root) it cant be used...

from jurnalctl when using in service file prepared for timers:
ark-ds-restart.service:

[Unit]
Description="Restarting for dedicated servers of ark ascended"
After=network.target

[Service]
WorkingDirectory=/home/container/docker/ark-asc/
EnvironmentFile=/home/container/docker/ark-asc/serviceenv.conf
ExecStart=/home/container/docker/ark-asc/ark-manager.sh $PARAM $TIME $INSTANCE
Type=oneshot
#Restart=always
StandardOutput=journal
StandardError=journal

env-file:

PARAM='-restart'
TIME=15
INSTANCE='-all'

journalctl --user -xeu ark-ds-restart.service:

░░ Subject: A start job for unit UNIT has begun execution
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit UNIT has begun execution.
░░
░░ The job identifier is 485678.
led 06 12:27:23 linux.home ark-manager.sh[2765240]: Using Docker Compose command: 'docker compose' (read from file).
led 06 12:27:23 linux.home ark-manager.sh[2765240]: User has chosen to run Docker commands without 'sudo'.
led 06 12:27:23 linux.home ark-manager.sh[2765240]: ----- Server HELLISH666-Ex: Command: restart 15 -----
led 06 12:27:23 linux.home ark-manager.sh[2765240]: ----- Server HELLISH666New: Command: restart 15 -----
led 06 12:27:23 linux.home ark-manager.sh[2765240]: ----- Server HELLISH666-Sv: Command: restart 15 -----
led 06 12:27:23 linux.home ark-manager.sh[2765240]: ----- All running instances processed with -restart command. -----
led 06 12:27:23 linux.home systemd[6449]: Finished ark-ds-restart.service - "Restarting for dedicated servers of ark ascended".
░░ Subject: A start job for unit UNIT has finished successfully
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit UNIT has finished successfully.
░░
░░ The job identifier is 485678.

that three instances didn't get commnad for restart, nothing in logs watched in another terminal pok-manager -logs -live, no restart is performed... just in output from POK-manager is info about restart, but not in related containers...
like it was send to different contaniers, or some of params, cant be accessed in environment for cron or systemd so pok-manager can't correctly perform restart... same is for using instance names ( not for -all parameter)

as mentioned before same is for crontab. only manual run of restart works...

selinux not caused this - i tried to disable it

POK-manager.sh or my ark-manager.sh - booth have same behavior... update doesn't matter.

@raptikCZ raptikCZ changed the title Scheduled restart won't work from cron or systemd timers Scheduled restart don't work from cron or systemd timers Jan 6, 2025
@raptikCZ
Copy link
Author

raptikCZ commented Jan 6, 2025

i tested dirrectly dealing with container throught python docker unit and write very primitive script...

as result working basic solution, leading me to conclusion that is something broken inside pok-manager.sh or some security or environment variable passing, when running through cron or systemd on my system:

service unit for systemd in home ( ~/.config/systemd/user) of unix user with uid 1000:

[Unit]
Description="Restarting for dedicated servers of ark ascended"
After=network.target

[Service]
WorkingDirectory=/home/container/docker/ark-asc/
ExecStart=python /home/container/docker/ark-asc/manager.py
Type=oneshot
#Restart=always
StandardOutput=journal
StandardError=journal

timer unit for systemd systemd in home ( ~/.config/systemd/user) of unix user with uid 1000:
in OnCalendar you can define your time schedule

 
 [Unit]
 Description="Run ark-ds-restarts.service at desired time"
 
 [Timer]
 OnCalendar=*-*-* 23:45:00
 OnCalendar=*-*-* 05:45:00
 Unit=ark-ds-restart.service
 
 [Install]
 WantedBy=timers.target
 

python script manager.py (without error handling and so on):
for more info (https://docker-py.readthedocs.io/en/stable/)

import docker

#very basic usage - no error handling!!!!!

client = docker.from_env()

containers = client.containers.list()

for container in containers:
    print(container.name)
    #in folowing if replace asa with most common string in name for all of your contaniers for ARK ascended - contaniers variable have full list of docker contaniers in system - not only ARK ascended!!!!!
    if container.name.__contains__("asa"):
     print(f"{container.name} is ARK Ascended")
     container.exec_run(cmd=f"/home/pok/scripts/rcon_interface.sh -restart 15", user="pok", stdout=False, stdin=False, stderr=False)

this can restart asa servers for me in sheduled time

@Caelin
Copy link

Caelin commented Jan 29, 2025

I looked at this as I was having the same issues with using -all within cron and found out the issue is that POK-manager is using the filesystem to get the list of server instances instead of using a docker command to get the list. This means that you need to make a small wrapper script for now to cd to where your POK-manager.sh and instance directories are located and then run the command you are wanting to run with the -all option. So for example to save the world on all servers:

#!/bin/bash

cd /gameservers
./POK-manager.sh -saveworld -all

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants