1

I am currently writing a Puppet module to get GitLab running on CentOS 6/7. For the CentOS 7 install I need to write a systemd unit file to start the gitlab service (which is actually Unicorn & Sidekiq).

Here's the unit file I came up with based on my vague understanding of the init script that GitLab themselves provide:

[Unit]
Description=GitLab
After=network.target
Requires=network.target
After=mariadb.service
Requires=mariadb.service
After=redis.service
Requires=redis.service

[Service]
EnvironmentFile=/etc/sysconfig/gitlab
ExecStartPre=source /etc/profile.d/rvm.sh
ExecStart=/bin/bash --pidfile=$UPID --user=$USER "$PATH_PATCH RAILS_ENV=$RAILS_ENV bin/web start" && /bin/bash --pidfile=$SPID --user=$USER "$PATH_PATCH RAILS_ENV=$RAILS_ENV bin/background_jobs start"

[Install]
WantedBy=multi-user.target

And here is the associated sysconfig file:

RAILS_ENV="production"
USER=git
APP_PATH=/home/$USER/gitlab
UPID=$APP_PATH/tmp/pids/unicorn.pid
ULOCK=/var/lock/subsys/unicorn
SPID=$APP_PATH/tmp/pids/sidekiq.pid
SLOCK=/var/lock/subsys/sidekiq
PATH_PATCH="PATH=$(su $USER -s /bin/bash -l -c "echo \"\$PATH\"") && export PATH && "

This does not work in the slightest (not unexpected):

[root@gitlab ~]# systemctl status gitlab -l
gitlab.service - GitLab
   Loaded: loaded (/usr/lib/systemd/system/gitlab.service; disabled)
   Active: failed (Result: exit-code) since Fri 2015-04-17 15:48:38 BST; 6s ago
  Process: 9942 ExecStart=/bin/bash --pidfile=$UPID --user=$USER $PATH_PATCH RAILS_ENV=$RAILS_ENV bin/web start && /bin/bash --pidfile=$SPID --user=$USER $PATH_PATCH RAILS_ENV=$RAILS_ENV bin/background_jobs start (code=exited, status=2)
 Main PID: 9942 (code=exited, status=2)

Apr 17 15:48:38 gitlab.thefallenphoenix.net bash[9942]: --rcfile
Apr 17 15:48:38 gitlab.thefallenphoenix.net bash[9942]: --rpm-requires
Apr 17 15:48:38 gitlab.thefallenphoenix.net bash[9942]: --restricted
Apr 17 15:48:38 gitlab.thefallenphoenix.net bash[9942]: --verbose
Apr 17 15:48:38 gitlab.thefallenphoenix.net bash[9942]: --version
Apr 17 15:48:38 gitlab.thefallenphoenix.net bash[9942]: Shell options:
Apr 17 15:48:38 gitlab.thefallenphoenix.net bash[9942]: -irsD or -c command or -O shopt_option                (invocation only)
Apr 17 15:48:38 gitlab.thefallenphoenix.net bash[9942]: -abefhkmnptuvxBCHP or -o option
Apr 17 15:48:38 gitlab.thefallenphoenix.net systemd[1]: gitlab.service: main process exited, code=exited, status=2/INVALIDARGUMENT
Apr 17 15:48:38 gitlab.thefallenphoenix.net systemd[1]: Unit gitlab.service entered failed state.

Can anyone shed some light over what exactly is needed here or point me in the right direction?

kemra102
  • 211
  • 4
  • 12
  • why not use https://github.com/gitlabhq/gitlab-recipes/tree/master/init/systemd? – Federico Sierra Apr 17 '15 at 17:03
  • A good start thanks, I hadn't seen these before (because they aren't in the gitlab source tree itself like the init script was). They will still need some massaging however as I need to use rvm so the bundle path listed is not accepted. – kemra102 Apr 18 '15 at 22:05

1 Answers1

0

You can't use variable substitution in /etc/sysconfig/gitlab and in ExecStart you need to use ${UPID} form of variable substitution if it isn't surrounded by whitespace.

See also example unit file to start unicorn with RVM support

AlexD
  • 8,179
  • 2
  • 28
  • 38