LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   need help with creating a systemd unit file. (https://www.linuxquestions.org/questions/linux-server-73/need-help-with-creating-a-systemd-unit-file-4175657269/)

thaylin 07-12-2019 08:47 AM

need help with creating a systemd unit file.
 
I am trying to start some rails workers on startup, the command to do this is :

RAILS_ENV=development bundle exec rails resque:start_workers[2]


I put in a unitfile with the following:
Code:

[Unit]
Description=background workers
After=httpd.service solr.service

[Service]
Environment=RAILS_ENV=development
ExecStart=/usr/local/bin/bundle exec rails resque:restart_workers[2]
User=deploy
WorkingDirectory=/opt/wonda/current
Environment=rvm_bin_path=/usr/local/rvm/bin
Environment=GEM_HOME=/usr/local/rvm/gems/ruby-2.5.1
Environment=SHELL=/bin/bash
Environment=IRBRC=/usr/local/rvm/rubies/ruby-2.5.1/.irbrc
Environment=MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-2.5.1
Environment=LD_LIBRARY_PATH=/opt/rh/rh-php71/root/usr/lib64
Environment=PATH=/usr/local/rvm/gems/ruby-2.5.1/bin:/usr/local/rvm/gems/ruby-2.5.1@global/bin:/usr/local/rvm/rubies/ruby-2.5.1/bin:/usr/local/rvm/bin:/opt/rh/rh-php71/root/usr/bin:/opt/rh/rh-php71/root/usr/sbin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/sbin:/usr/local/sbin:/opt/puppetlabs/bin
Environment=GEM_PATH=/usr/local/rvm/gems/ruby-2.5.1:/usr/local/rvm/gems/ruby-2.5.1@global
Environment=DBUSER=wonda
Environment=DBPASS=***************

[Install]
WantedBy=multi-user.target

It appears to start the workers, but they never actually start, I assume thier processes are dieing immediately.

Can anyone help or spot what I am doing wrong? Note that all the Environment was me trying to replicate the users environment.

smallpond 07-12-2019 09:12 AM

What do you get from:
Code:

systemctl status <your service name>
and do the workers log any messages?

thaylin 07-12-2019 12:19 PM

Quote:

Originally Posted by smallpond (Post 6014373)
What do you get from:
Code:

systemctl status <your service name>
and do the workers log any messages?

No messages, though I do see

Code:

Jul 12 09:29:37 wonda bundle[16935]: Starting 2 worker(s) with QUEUE: ingest,mailers,checksum
Jul 12 09:29:37 wonda bundle[16935]: Started worker with PID 16945
Jul 12 09:29:37 wonda bundle[16935]: Started worker with PID 16947

But those PIDs are dead by the time I check.

thaylin 07-12-2019 12:42 PM

Quote:

Originally Posted by smallpond (Post 6014373)
What do you get from:
Code:

systemctl status <your service name>
and do the workers log any messages?

we added some deug logging but all it outputs is

Code:

D, [2019-07-12T13:39:54.937421 #29170] DEBUG -- : Checking ingest
D, [2019-07-12T13:39:54.938149 #29170] DEBUG -- : Checking mailers
D, [2019-07-12T13:39:54.938574 #29170] DEBUG -- : Checking checksum
D, [2019-07-12T13:39:54.938896 #29170] DEBUG -- : Sleeping for 5.0 seconds
D, [2019-07-12T13:39:54.939002 #29170] DEBUG -- : resque-2.0.0: Waiting for ingest,mailers,checksum


rnturn 07-13-2019 12:17 PM

Quote:

Originally Posted by thaylin (Post 6014370)
I am trying to start some rails workers on startup, the command to do this is :

RAILS_ENV=development bundle exec rails resque:start_workers[2]


I put in a unitfile with the following:
Code:

<snip>

[Service]
Environment=RAILS_ENV=development
ExecStart=/usr/local/bin/bundle exec rails resque:restart_workers[2]
User=deploy
WorkingDirectory=/opt/wonda/current
Environment=rvm_bin_path=/usr/local/rvm/bin
Environment=GEM_HOME=/usr/local/rvm/gems/ruby-2.5.1
Environment=SHELL=/bin/bash
Environment=IRBRC=/usr/local/rvm/rubies/ruby-2.5.1/.irbrc
Environment=MY_RUBY_HOME=/usr/local/rvm/rubies/ruby-2.5.1

<snip>

It appears to start the workers, but they never actually start, I assume thier processes are dieing immediately.

Can anyone help or spot what I am doing wrong? Note that all the Environment was me trying to replicate the users environment.

Not sure how much I can help---I've not tackled a unit file quite like this.

While the documentation says that multiple instances of "Environment=" should work but it wouldn't be the first time the "fine manual" was in error.

Would something like this work?
Code:

Environment=RAILS_ENV=development \
  rvm_bin_path=/usr/local/rvm/bin \
  GEM_HOME=/usr/local/rvm/gems/ruby-2.5.1 \
  SHELL=/bin/bash \
  (etc.)

Worth a try.


All times are GMT -5. The time now is 10:04 PM.