Question

I have a couple of rails rake tasks that I need to start on server bootup. I have been looking to make them run as traditional services using systemd. The service file is created under /etc/system/systemd but unfortunately it looks like systemd did not find the file:

#systemctl start screens.service
Failed to issue method call: Unit screens.service failed to load: No such file or directory. See system logs and 'systemctl status screens.service' for details.

#systemctl status screens.service
screens.service
      Loaded: error
      Active: inactive (dead)

I am currently using Fedora 15

How can I make my systemd service work? Is there another way I could make my rake tasks run at system boot.

Update: screens.service file content

[Unit]
Description=Send Reminders

[Service]
Type=simple
User=myuser
WorkingDirectory=/path/to/rails/app
ExecStart=/usr/local/rvm/gems/ruby-1.9.3-p194/bin/rake reminders:send

I know that I need to set dependencies when I need it to work on bootup, but currently I am trying to start my rake using systemctl command and worry about it dependencies later.

Was it helpful?

Solution 2

To make systemd take notice of the newly added services I had to insert the following command:

systemctl daemon-reload

OTHER TIPS

First, instead of calling rake directly, I would call /path/to/ruby/bin/bundle exec rake my:raketask.

Second, I think you should really take a look at the foreman gem, as it's designed to handle this situation, though you might have to adapt it work with systemd.

One way would be to call foreman from systemd init file, passing it options to specify the Procfile (foreman config file) in your app's directory.

Foreman can already export its config to several formats, but I don't think yours is among them. But, you could create a custom exporter that exports the foreman configuration to systemd format. See https://github.com/ddollar/foreman/wiki/Custom-exporters for more information. If you go this route, consider contributing your exporter back to the foreman project.

Normally if you need to start something in the application initializer, you could put the .rb file to

config/initializers/ folder

Would you elaborate your requirement, because there might be some other way of doing the same? :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top