2

I am trying to restart all the stale sqlrelay connection services using systemd.timer. Systemd service looks like this:

[Unit]
Description=sqlrelay-state-connection-restart

[Service]
Type=oneshot
User=sqlrelay
ExecStart=/bin/ps -eo pid,etimes,cmd  | /bin/awk '$2 >=100 && $3=="sqlr-connection"  {printf "sqlrelay@%s.target\n", $9}' | /usr/bin/sudo /bin/xargs -r /bin/systemctl restart

Timer:

[Timer]
OnCalendar=*-*-* *:0/5:0

[Install]
WantedBy=timers.target

I have added sqlrelay user with Nopasswd in sudoers file.

Timer starts properly without any errors. But with the service, it's not loaded. In the logs I see this:

Apr 23 23:10:00 ****.com systemd[1]: sqlrelay-stale-restart.service failed to run 'start' task: Operation not supported
Apr 23 23:10:00 ****.com systemd[1]: Failed to start sqlrelay-state-connection-restart.
Apr 23 23:15:00 ****.com systemd[1]: sqlrelay-stale-restart.service: main process exited, code=exited, status=1/FAILURE
Apr 23 23:15:00 ****.com systemd[1]: Failed to start sqlrelay-state-connection-restart.
Apr 23 23:15:00 ****.com systemd[1]: Unit sqlrelay-stale-restart.service entered failed state.
Apr 23 23:15:00 ****.com systemd[1]: sqlrelay-stale-restart.service failed.

Sometimes I get operation not permitted with sqlrelay user. If I remove the sqlrelay user, to allow it to run as root, I get 'Unit entered failed state' error

1

2 Answers 2

2

I fixed it by putting them in a Bash script and call the script from ExecStart. The problem here is pipe command should not be used directly with ExecStart. We have to use subshell

Example:

ExecStart=/bin/sh -c 'ps -eo ...| ....|.. '
0

The value of the ExecStart key in the .INI file is not shell script.

Further reading

  • Lennart Poettering et al. (2019). "COMMAND LINES". systemd.service. systemd manual pages.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .