Skip to content

Conversation

@davispuh
Copy link

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
Copy link
Contributor

Please add header to each file


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

@davispuh
Copy link
Author

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
Copy link

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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.

@Flydiverny
Copy link

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
Copy link
Author

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 mentioned this pull request Aug 2, 2013
14 tasks
@ghost ghost assigned axilleas Aug 5, 2013
@axilleas
Copy link
Contributor

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
Copy link
Author

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

@axilleas
Copy link
Contributor

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

@davispuh
Copy link
Author

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
Copy link
Contributor

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

Development

Successfully merging this pull request may close these issues.

5 participants