1

I've wrote a systemd file for systemctl to start unicorn:

[Unit]
Description=Unicorn server

[Service]
SyslogIdentifier=my-app-unicorn
User=deployer
PIDFile=/tmp/unicorn.my-app.pid
WorkingDirectory=/opt/www/my-app.com

ExecStart=/home/deployer/.rvm/gems/ruby-2.2.1@my-app/bin/bundle exec "unicorn_rails -D -c /opt/www/my-app.com/config/unicorn.rb -E production"
#ExecReload=/bin/kill -s HUP $MAINPID
ExecReload=/bin/kill -s USR2 $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID

[Install]
WantedBy=multi-user.target

Here are the commands I used to start the service

$ sudo systemctl daemon-reload
$ sudo systemctl start my-app.service

Here I check the status:

$ sudo systemctl status my-app
● my-app.service - My app unicorn server
   Loaded: loaded (/lib/systemd/system/my-app.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2016-03-15 14:56:31 UTC; 4s ago
  Process: 22165 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=200/CHDIR)
  Process: 22162 ExecStart=/home/deployer/.rvm/gems/ruby-2.2.1@my-app/bin/bundle exec unicorn_rails -D -c /opt/www/my-app.com/config/unicorn.rb -E production (code=exited, status=200/CHDIR)
 Main PID: 22162 (code=exited, status=200/CHDIR)

Mar 15 14:56:31 fat-man systemd[1]: Started My-App unicorn server.
Mar 15 14:56:31 fat-man systemd[22162]: my-app.service: Failed at step CHDIR spawning /home/deployer/.rvm/gems/ruby-2.2.1@my-app/bin/bundle: No such file or directory
Mar 15 14:56:31 fat-man systemd[1]: my-app.service: Main process exited, code=exited, status=200/CHDIR
Mar 15 14:56:31 fat-man systemd[1]: my-app.service: Control process exited, code=exited status=200
Mar 15 14:56:31 fat-man systemd[1]: my-app.service: Unit entered failed state.
Mar 15 14:56:31 fat-man systemd[1]: my-app.service: Failed with result 'exit-code'.

What could be the problem?

LE: The access grants of user deployer to the /opt/www/my-app directory:

$ ls -alh
total 84K
drwxr-xr-x 12 deployer admin 4.0K Mar 12 20:10 .
drwxr-xr-x  3 root     root  4.0K Mar 11 20:43 ..
drwxr-xr-x  9 deployer admin 4.0K Mar 11 20:52 app
drwxr-xr-x  2 deployer admin 4.0K Mar 11 20:52 bin
drwxr-xr-x  5 deployer admin 4.0K Mar 13 14:02 config
-rw-r--r--  1 deployer admin  153 Mar 11 20:52 config.ru
drwxr-xr-x  3 deployer admin 4.0K Mar 11 20:52 db
-rw-r--r--  1 deployer admin 1.9K Mar 11 20:52 Gemfile
-rw-r--r--  1 deployer admin 5.1K Mar 11 20:52 Gemfile.lock
-rw-r--r--  1 deployer admin  616 Mar 11 20:52 .gitignore
drwxr-xr-x  5 deployer admin 4.0K Mar 11 20:52 lib
drwxr-xr-x  2 deployer admin 4.0K Mar 12 20:53 log
drwxr-xr-x  3 deployer admin 4.0K Mar 12 19:12 public
-rw-r--r--  1 deployer admin  249 Mar 11 20:52 Rakefile
-rw-r--r--  1 deployer admin  478 Mar 11 20:52 README.rdoc
-rw-r--r--  1 deployer admin    9 Mar 11 20:52 .ruby-gemset
-rw-r--r--  1 deployer admin   11 Mar 11 20:52 .ruby-version
drwxr-xr-x  8 deployer admin 4.0K Mar 11 20:52 test
drwxr-xr-x  6 deployer admin 4.0K Mar 12 20:53 tmp
drwxr-xr-x  3 deployer admin 4.0K Mar 11 20:52 vendor
3
  • Look at the error in the log. It says Failed at step CHDIR spawning /home/deployer/.rvm/gems/ruby-2.2.1@my-app/bin/bundle: No such file or directory. That's the problem here.
    – Munir
    Commented Mar 15, 2016 at 22:05
  • I saw that error. The file exists. If I type in the linux terminal /home/deployer/.rvm/gems/ruby-2.2.1@my-app/bin/bundle exec "unicorn_rails -D -c /opt/www/my-app.com/config/unicorn.rb -E production" the unicorn will start but apparently it doesn't work in the .service file
    – Razvan El
    Commented Mar 15, 2016 at 22:38
  • Multi-posted to stackoverflow.com/questions/36014993 . help center
    – JdeBP
    Commented Mar 22, 2016 at 10:44

2 Answers 2

3

Error message Failed at step CHDIR means that systemd is unable to cd into directory specified in WorkingDirectory. It is specified as /opt/www/my-app.com but later you list it as /opt/www/my-app.

Another issue is that you are starting unicorn_rails with option -D which tells unicorn_rails process to daemonize (started process forks child and immediately exits) but your [Service] section doesn't specify Type so it defaults to simple and systemd expects process to stay alive. You need to remove -D option or specify Type=forking.

See example unit file for unicorn

0

It's propably because of letter case instead of eg /opt/www/my-app.com try /opt/www/My-app.com

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .