简体   繁体   中英

systemd init script for resque worker

i habe an nginx webserver running on an Ubuntu 16.04 Server. Now i am trying to build an init script for resque worker and scheduler for a Rails app.

I created a file resque-worker.service in "/etc/systemd/system/" and it looks like this:

[Unit]
 Description=resque-worker for pageflow

[Service]
 Type=forking
 ExecStart=/home/pageflow/pageflow_daad/rake resque:scheduler QUEUE=* RAILS_ENV=production > /home/pageflow/pageflow_daad/log/resqueschedule.log &

[Install]
 WantedBy=multi-user.target

For some reason after executing "systemctl daemon-reload" and "systemctl start name.service" i get this error:

$ systemctl status resque-worker.service
● resque-worker.service - resque-worker for pageflow
   Loaded: loaded (/etc/systemd/system/resque-worker.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2017-05-17 15:52:38 CEST; 15s ago
  Process: 28096 ExecStart=/home/pageflow/pageflow_daad/rake resque:scheduler QUEUE=* RAILS_ENV=production > /home/pageflow/pageflow_daad/log/resqueschedule.log & (code=exited, status=203/EXEC)

May 17 15:52:38 ostheim systemd[1]: Starting resque-worker for pageflow...
May 17 15:52:38 ostheim systemd[1]: resque-worker.service: Control process exited, code=exited status=203
May 17 15:52:38 ostheim systemd[1]: Failed to start resque-worker for pageflow.
May 17 15:52:38 ostheim systemd[1]: resque-worker.service: Unit entered failed state.
May 17 15:52:38 ostheim systemd[1]: resque-worker.service: Failed with result 'exit-code'.

In this case i used the root path of my Rails app for "/home/pageflow/pageflow_daad/rake".

The times before where i tried the path of the rake binary i got the error: May 17 15:30:26 ostheim rake[26846]: rake aborted! May 17 15:30:26 ostheim rake[26846]: ArgumentError: couldn't find HOME environment -- expanding May 17 15:30:26 ostheim rake[26846]: rake aborted! May 17 15:30:26 ostheim rake[26846]: ArgumentError: couldn't find HOME environment -- expanding ~'`

I hope someone with more experience in this can help me out.

Thanks in advance and best regards, Ronald

I think there 2 types of errors inside the systemd unit. Here are some advices :

1) Let systemd capture your application logs, then use journalctl to look at it

journalctl -u resque-worker.service

2) Use env the systemd way :

[Unit]
Description=resque-worker for pageflow

[Service]
Type=forking
ExecStart=/home/pageflow/pageflow_daad/rake resque:scheduler
Environement=QUEUE=*
Enrironement=RAILS_ENV=production

[Install]
WantedBy=multi-user.target

Then,

systemctl daemon-reload
systemctl restart resque-worker.service

After studying the several docu sites and the documentation itself i found a way to get this running. Just wanted to post this if someone finds this to be helpfull:

[Unit]
Description=resque-scheduler for pageflow

[Service]
User=yourUser
WorkingDirectory=/path/to/rails/app
ExecStart=/path/to/executeable/rake resque:scheduler &
Environment=QUEUE=*
Environment=RAILS_ENV=production

[Install]
WantedBy=multi-user.target

With this script, a

systemctl daemon-reload

&

systemctl start example.service

The Service startet running and runs like a charm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM