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

The cond service occasionally shows status "Active: deactivating" #139

Closed
YoruStar opened this issue Feb 1, 2023 · 1 comment · Fixed by #146
Closed

The cond service occasionally shows status "Active: deactivating" #139

YoruStar opened this issue Feb 1, 2023 · 1 comment · Fixed by #146
Labels

Comments

@YoruStar
Copy link
Contributor

YoruStar commented Feb 1, 2023

Hello, I found something wrong with my crond service

Execute the commands systemctl restart crond and systemctl reload crond at the same time , The cond service occasionally shows status Active: deactivating .

When the command systemctl reload crond is executed, systemd will send the HUP to the crond process. Under normal circumstances, the crond process will modify the behavior of the HUP signal (without interrupting the process, and only record the received signal in the global variable). However, after executing the command systemctl restart crond, the crond process received the HUP signal sent by the command systemctl reload crond before it could modify the HUP signal behavior just after the crond process was started, which caused the crond process to be interrupted, so the crond service status appears as Active: deactivating .

I try to add a dead loop at the beginning of the main function of the crond service to reproduce this situation

int main(int argc, char *argv[]) {
	while (1)
	{
		/* code */
	}

	struct sigaction sact;
	cron_db database;
	int fd;
	char *cs;
	pid_t pid = getpid();
	long oldGMToff;
	struct timeval tv;
	struct timezone tz;
	char buf[256];

	... ...

Replace process to /usr/sbin/crond, Execute the commands systemctl restart crond and systemctl reload crond successively, the result as follows

[root@localhost SOURCES]# systemctl restart crond &
[1] 945128
[root@localhost SOURCES]# systemctl reload crond &
[2] 945171
[root@localhost SOURCES]# systemctl status crond
● crond.service - Command Scheduler
     Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
     Active: deactivating (start) since Wed 2023-02-01 10:13:00 CST; 9s ago
Cntrl PID: 945139 (crond)
      Tasks: 1 (limit: 8645)
     Memory: 204.0K
     CGroup: /system.slice/crond.service
             └─ 945139 /usr/sbin/crond -n

Feb 01 10:13:00 localhost.localdomain systemd[1]: Starting Command Scheduler...

I also tried to change the Type of cron.service to forking, and set the PIDFile to /var/run/cron.pid , but this seems to be getting worse

@t8m
Copy link
Member

t8m commented Feb 1, 2023

If there was any other signal that is by default ignored we could use that to signal the reload. The only such signal is SIGURG which is in POSIX1.2001 only. I assume we could use it as we do not use sockets so it should not be received spuriously.

On the other hand, why do you call restart and reload simultaneously?

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

Successfully merging a pull request may close this issue.

2 participants