0

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.

0

There is something missing in your environment. Certainly the PATH entry for /home/my_user123/.gem/ruby/2.3.4/bin, and maybe other variables.

Try starting your application with env -i. You can then add the necessary environment variables to the env command line and to the systemd unit file, or you can create a shell script that sets up the environment and then calls the command you want to execute.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.