I want to create systemd for "RAILS_ENV=staging bundle exec rake jobs:work"
I have this:
$ sudo cat /etc/systemd/system/my_bg_jobs.service
[Unit]
Description=bg jobs
After=syslog.target
[Service]
Type=simple
User=my_user123
WorkingDirectory=/home/my_user123/projects/ruby/my_app123
ExecStart=/home/my_user123/.gem/ruby/2.3.4/bin/bundle exec rake jobs:work
Restart=on-abort
Environment=RAILS_ENV=staging
SyslogIdentifier=my_bg_jobs
[Install]
WantedBy=multi-user.target
When I'm running it:
$ sudo systemctl status my_bg_jobs
●
Loaded: loaded (/etc/systemd/system/my_bg_jobs.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Tue 2018-07-10 11:07:29 +07; 1s ago
Process: 24138 ExecStart=/home/my_user123/.gem/ruby/2.3.4/bin/bundle exec rake jobs:work (code=exited, status=1/FAILURE)
Main PID: 24138 (code=exited, status=1/FAILURE)
[..........]
systemd[1]: Started bg jobs.
my_bg_jobs[24138]: /home/my_user123/.rubies/ruby-2.3.4/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem bundler (>= 0.a) (Gem::GemNot>
my_bg_jobs[24138]: from /home/my_user123/.gem/ruby/2.3.4/bin/bundle:22:in `<main>'
systemd[1]: my_bg_jobs.service: Main process exited, code=exited, status=1/FAILURE
systemd[1]: my_bg_jobs.service: Failed with result 'exit-code'.
Why is that and how to fix it?
I have bundler in place:
$ which bundler
/home/my_user123/.gem/ruby/2.3.4/bin/bundle
The rake job itself, without systemd, when run normally, runs flawlessly.