Sidekiq service file for systemd (CentOS, Fedora) #43

Closed
wants to merge 9 commits into
from

Conversation

Projects
None yet
5 participants
@davispuh

CentOS and Fedora uses systemd not usual init.d so it needs bit different configuration.

I added sidekiq.service file

first I tried:

ExecStart=/bin/sh -c "cd /home/gitlab/gitlab/ && bundle exec rake sidekiq:start"
User=gitlab
Group=gitlab

but sidekiq was crashing (don't know why, it was launched as gitlab user)

this works fine
ExecStart=/bin/su - gitlab -c "cd /home/gitlab/gitlab/ && bundle exec rake sidekiq:start"

@dzaporozhets

This comment has been minimized.

Show comment Hide comment
@dzaporozhets

dzaporozhets Jan 21, 2013

Owner

Please add header to each file


# GITLAB
# Maintainer: @davispuh
# App Version: 4.1

Owner

dzaporozhets commented Jan 21, 2013

Please add header to each file


# GITLAB
# Maintainer: @davispuh
# App Version: 4.1

@davispuh

This comment has been minimized.

Show comment Hide comment
@davispuh

davispuh Jan 21, 2013

done ;)

there's only one service file: sidekiq.service and I don't see reason why add to README

Also there's just sidekiq because all other services can be installed with package management which creates startup files automatically and there's multiple choices which software to use (eg. nginx or apache)

Also seems I've lied a bit, current stable CentOS release doesn't come with systemd, but it can be installed.

Distributions with systemd as default:

  • Fedora
  • openSUSE
  • Arch Linux
  • Mandriva
  • Mageia
  • Frugalware

Distributions where systemd can be enabled/installed easily:

  • Debian GNU/Linux
  • Gentoo
  • Ubuntu

done ;)

there's only one service file: sidekiq.service and I don't see reason why add to README

Also there's just sidekiq because all other services can be installed with package management which creates startup files automatically and there's multiple choices which software to use (eg. nginx or apache)

Also seems I've lied a bit, current stable CentOS release doesn't come with systemd, but it can be installed.

Distributions with systemd as default:

  • Fedora
  • openSUSE
  • Arch Linux
  • Mandriva
  • Mageia
  • Frugalware

Distributions where systemd can be enabled/installed easily:

  • Debian GNU/Linux
  • Gentoo
  • Ubuntu
@nbigaouette

This comment has been minimized.

Show comment Hide comment
@nbigaouette

nbigaouette Jan 22, 2013

Why not something more along the lines of:

[Service]
Type=simple
PIDFile=/home/gitlab/gitlab/tmp/pids/sidekiq.pid
WorkingDirectory=/home/gitlab/gitlab
User=gitlab
ExecStart=/home/gitlab/bin/bundle exec rake sidekiq:start RAILS_ENV=production
ExecStop=/home/gitlab/bin/bundle exec rake sidekiq:stop RAILS_ENV=production

The ExecStart/Stop need an absolute path, but this is a lot simpler...

I'll check why it is crashing, if it does, on my Arch machine.

Why not something more along the lines of:

[Service]
Type=simple
PIDFile=/home/gitlab/gitlab/tmp/pids/sidekiq.pid
WorkingDirectory=/home/gitlab/gitlab
User=gitlab
ExecStart=/home/gitlab/bin/bundle exec rake sidekiq:start RAILS_ENV=production
ExecStop=/home/gitlab/bin/bundle exec rake sidekiq:stop RAILS_ENV=production

The ExecStart/Stop need an absolute path, but this is a lot simpler...

I'll check why it is crashing, if it does, on my Arch machine.

@davispuh

This comment has been minimized.

Show comment Hide comment
@davispuh

davispuh Jan 22, 2013

wasn't aware there's WorkingDirectory. I don't see it mentioned anywhere in man pages... using systemd 44 version.
I was looking for something like that but didn't found so had to use shell..

EDIT:
oh, just found man systemd.exec didn't view that... :D

wasn't aware there's WorkingDirectory. I don't see it mentioned anywhere in man pages... using systemd 44 version.
I was looking for something like that but didn't found so had to use shell..

EDIT:
oh, just found man systemd.exec didn't view that... :D

@davispuh

This comment has been minimized.

Show comment Hide comment
@davispuh

davispuh Jan 22, 2013

I updated sidekiq service, thanks :)

seems to work good :)

[Service]
Type=simple
PIDFile=/home/gitlab/gitlab/tmp/pids/sidekiq.pid
WorkingDirectory=/home/gitlab/gitlab/
ExecStart=/bin/bundle exec rake sidekiq:start RAILS_ENV=production
ExecStop=/bin/bundle exec rake sidekiq:stop RAILS_ENV=production
User=gitlab
Group=gitlab

I updated sidekiq service, thanks :)

seems to work good :)

[Service]
Type=simple
PIDFile=/home/gitlab/gitlab/tmp/pids/sidekiq.pid
WorkingDirectory=/home/gitlab/gitlab/
ExecStart=/bin/bundle exec rake sidekiq:start RAILS_ENV=production
ExecStop=/bin/bundle exec rake sidekiq:stop RAILS_ENV=production
User=gitlab
Group=gitlab
@davispuh

This comment has been minimized.

Show comment Hide comment
@davispuh

davispuh Jan 22, 2013

whoops... sidekiq is crashing same as my first attempt...

EDIT:
this is from log..

/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:106:in `block in interrupt': Interrupt (Interrupt)
        from <internal:prelude>:10:in `synchronize'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:103:in `interrupt'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:9:in `block in <top (required)>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `call'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/action_view/template/resolver.rb:4:in `<top (required)>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/action_view/railtie.rb:50:in `block (2 levels) in <class:Railtie>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:26:in `block in on_load'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:25:in `each'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:25:in `on_load'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/action_view/railtie.rb:48:in `block in <class:Railtie>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from /home/gitlab/gitlab/config/environment.rb:5:in `<top (required)>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:133:in `require'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:133:in `boot_system'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:74:in `parse'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/bin/sidekiq:7:in `<top (required)>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/bin/sidekiq:19:in `load'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/bin/sidekiq:19:in `<main>'

whoops... sidekiq is crashing same as my first attempt...

EDIT:
this is from log..

/home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:106:in `block in interrupt': Interrupt (Interrupt)
        from <internal:prelude>:10:in `synchronize'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:103:in `interrupt'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:9:in `block in <top (required)>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `call'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/action_view/template/resolver.rb:4:in `<top (required)>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/action_view/railtie.rb:50:in `block (2 levels) in <class:Railtie>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:26:in `block in on_load'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:25:in `each'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.11/lib/active_support/lazy_load_hooks.rb:25:in `on_load'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.11/lib/action_view/railtie.rb:48:in `block in <class:Railtie>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
        from /home/gitlab/gitlab/config/environment.rb:5:in `<top (required)>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:133:in `require'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:133:in `boot_system'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/lib/sidekiq/cli.rb:74:in `parse'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/sidekiq-2.6.4/bin/sidekiq:7:in `<top (required)>'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/bin/sidekiq:19:in `load'
        from /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/bin/sidekiq:19:in `<main>'
@davispuh

This comment has been minimized.

Show comment Hide comment
@davispuh

davispuh Jan 22, 2013

I reverted back... I've no idea why sidekiq is crashing... anyway while this config might not be the nicest it does work so unless someone have better one which doesn't crash sidekiq I'm leaving this one.

I reverted back... I've no idea why sidekiq is crashing... anyway while this config might not be the nicest it does work so unless someone have better one which doesn't crash sidekiq I'm leaving this one.

@nathansamson nathansamson referenced this pull request in gitlabhq/gitlabhq Jan 28, 2013

Closed

Alternate solutions for GitLab startup script #2744

@Flydiverny

This comment has been minimized.

Show comment Hide comment
@Flydiverny

Flydiverny Feb 27, 2013

So after going crazy trying to get a working sidekiq.service on my arch machine I ended up with this service, where setting Environment=PATH= seems to be the winner for me since sidekiq kept throwing failed to run command on bundle even with absolute paths etc. Kinda assumed there's another bundle call inside which wont find the bundle without the PATH set.

[Unit]
Description=GitLab Sidekiq Service
After=redis.service gitlab.service
Requires=redis.service

[Service]
Type=forking
SyslogIdentifier=gl-sidekiq
PIDFile=/home/gitlab/gitlab/tmp/pids/sidekiq.pid
WorkingDirectory=/home/gitlab/gitlab
TimeoutStartSec=600
User=gitlab

Environment=PATH=/home/gitlab/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl
ExecStart=/bin/bash -c 'bundle exec rake sidekiq:start RAILS_ENV=production'
ExecStop=/bin/bash -c 'bundle exec rake sidekiq:stop RAILS_ENV=production'

[Install]
WantedBy=multi-user.target

Well idk figured I'd just post it just in case it might actually help someone ^^

So after going crazy trying to get a working sidekiq.service on my arch machine I ended up with this service, where setting Environment=PATH= seems to be the winner for me since sidekiq kept throwing failed to run command on bundle even with absolute paths etc. Kinda assumed there's another bundle call inside which wont find the bundle without the PATH set.

[Unit]
Description=GitLab Sidekiq Service
After=redis.service gitlab.service
Requires=redis.service

[Service]
Type=forking
SyslogIdentifier=gl-sidekiq
PIDFile=/home/gitlab/gitlab/tmp/pids/sidekiq.pid
WorkingDirectory=/home/gitlab/gitlab
TimeoutStartSec=600
User=gitlab

Environment=PATH=/home/gitlab/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/bin/core_perl
ExecStart=/bin/bash -c 'bundle exec rake sidekiq:start RAILS_ENV=production'
ExecStop=/bin/bash -c 'bundle exec rake sidekiq:stop RAILS_ENV=production'

[Install]
WantedBy=multi-user.target

Well idk figured I'd just post it just in case it might actually help someone ^^

@davispuh

This comment has been minimized.

Show comment Hide comment
@davispuh

davispuh Mar 10, 2013

this ^ above, doesn't work for me on Fedora, still crash but bit different than earlier.
My previous attempts, it just exits without any sign (no idea why). So currently I don't see any way to run sidekiq with systemd.. It needs to be started manually. If anyone have time, would be great if could look into it.
this is my best try, no luck, but doesn't crash. just exits.

[Unit]
Description=GitLab Sidekiq Service
After=syslog.target network.target remote-fs.target redis.service
Wants=redis.service

[Service]
Type=simple
TimeoutStartSec=30
SyslogIdentifier=gl-sidekiq
PIDFile=/home/gitlab/gitlab/tmp/pids/sidekiq.pid
ExecStart=/bin/su - gitlab -c "(cd /home/gitlab/gitlab/ && bundle exec rake sidekiq:start RAILS_ENV=production) || 0"
ExecStop=/bin/su - gitlab -c "(cd /home/gitlab/gitlab/ && bundle exec rake sidekiq:stop RAILS_ENV=production) || 0"

[Install]
WantedBy=multi-user.target

|| 0 because otherwise that command returns 1 to systemd and it assumes it failed, even if it's still running.

this ^ above, doesn't work for me on Fedora, still crash but bit different than earlier.
My previous attempts, it just exits without any sign (no idea why). So currently I don't see any way to run sidekiq with systemd.. It needs to be started manually. If anyone have time, would be great if could look into it.
this is my best try, no luck, but doesn't crash. just exits.

[Unit]
Description=GitLab Sidekiq Service
After=syslog.target network.target remote-fs.target redis.service
Wants=redis.service

[Service]
Type=simple
TimeoutStartSec=30
SyslogIdentifier=gl-sidekiq
PIDFile=/home/gitlab/gitlab/tmp/pids/sidekiq.pid
ExecStart=/bin/su - gitlab -c "(cd /home/gitlab/gitlab/ && bundle exec rake sidekiq:start RAILS_ENV=production) || 0"
ExecStop=/bin/su - gitlab -c "(cd /home/gitlab/gitlab/ && bundle exec rake sidekiq:stop RAILS_ENV=production) || 0"

[Install]
WantedBy=multi-user.target

|| 0 because otherwise that command returns 1 to systemd and it assumes it failed, even if it's still running.

@axilleas axilleas referenced this pull request Aug 2, 2013

Merged

[WIP] New repository structure #111

12 of 14 tasks complete

@ghost ghost assigned axilleas Aug 5, 2013

@axilleas

This comment has been minimized.

Show comment Hide comment
@axilleas

axilleas Aug 18, 2013

Member

I provided some service files based on many suggestions that play with Fedora (see above commit). Haven't tested with Arch yet. I also included your readme and I added 1-2 things. Feedback welcomed :)

Member

axilleas commented Aug 18, 2013

I provided some service files based on many suggestions that play with Fedora (see above commit). Haven't tested with Arch yet. I also included your readme and I added 1-2 things. Feedback welcomed :)

@axilleas axilleas closed this Aug 19, 2013

@davispuh

This comment has been minimized.

Show comment Hide comment
@davispuh

davispuh Aug 20, 2013

just tested, works good for my Fedora 18 :) Thanks 👍

just tested, works good for my Fedora 18 :) Thanks 👍

@axilleas

This comment has been minimized.

Show comment Hide comment
@axilleas

axilleas Aug 20, 2013

Member

Cool! Thanks for the feedback. I'll add your name to the contributors if you don't mind.

Member

axilleas commented Aug 20, 2013

Cool! Thanks for the feedback. I'll add your name to the contributors if you don't mind.

@davispuh

This comment has been minimized.

Show comment Hide comment
@davispuh

davispuh Aug 20, 2013

sure lol.

When I first tried sidekiq as systemd unit file for some configurations it was crashing, that was when I had F17, maybe some buggy lib/gem somewhere idk, but anyway this unit file is very clean and nice, not sure if you saw any crashes, but I didn't now with this and fully updated system.

sure lol.

When I first tried sidekiq as systemd unit file for some configurations it was crashing, that was when I had F17, maybe some buggy lib/gem somewhere idk, but anyway this unit file is very clean and nice, not sure if you saw any crashes, but I didn't now with this and fully updated system.

@axilleas

This comment has been minimized.

Show comment Hide comment
@axilleas

axilleas Aug 20, 2013

Member

No crashes for me too, I tested before pushing on Fedora 19. Will have to do the same for Archlinux.

To give proper credits, I took the sidekiq one from here.

Member

axilleas commented Aug 20, 2013

No crashes for me too, I tested before pushing on Fedora 19. Will have to do the same for Archlinux.

To give proper credits, I took the sidekiq one from here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment