我目前正在编写一个 Puppet 模块,以使 GitLab 在 CentOS 6/7 上运行。对于 CentOS 7 安装,我需要编写一个 systemd 单元文件来启动 gitlab 服务(实际上是 Unicorn 和 Sidekiq)。
这是我根据对 GitLab 自己提供的初始化脚本的模糊理解得出的单元文件:
[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
以下是相关的 sysconfig 文件:
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 && "
这根本不起作用(这并不出乎意料):
[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.
有人可以解释一下这里到底需要什么或者给我指明正确的方向吗?
答案1
您不能在中使用变量替换,/etc/sysconfig/gitlab
并且如果变量没有被空格包围,则ExecStart
需要使用变量替换的形式。${UPID}