To process tasks for a web application, I have a background "task runner" that's managed with systemd:
[Unit] Description=Background Job Runner After=network.target mariadb.service [Service] Type=simple Restart=always User=sitesdb ExecStart=/bin/scl enable rh-git29 rh-php71 "/var/www/sitesdb/current/bin/console --env=prod jms-job-queue:run -v" [Install] WantedBy=multi-user.target
The web application queues jobs for the task runner to execute, which is constantly looking for new jobs to run.
One of these jobs runs a remote SSH command on another server and needs to forward the SSH keys of the "sitesdb" user to that server.
Since systemd is starting the job runner, how can this work? I need to ensure that an SSH agent is running, and then need to add the SSH keys of the
sitesdb user to it, since that's the user that owns the process.
One idea is to change the startup command to this:
eval `ssh-agent -s` && ssh-add && /bin/scl enable rh-git29 rh-php71 "/var/www/sitesdb/current/bin/console --env=prod jms-job-queue:run -v"
But is this appropriate? I think this would start multiple SSH agents every time my job runner command died and must be started again (and it's configured to auto kill every 15 min).