How to start Unicorn with systemctl and systemd

1k Views Asked by At

I would like to start Unicorn with systemctl on the amazon-linux-2, but the Unicorn doesn't start.

I've wrote a /etc/systemd/system/unicorn.service file.

[Unit]
Description=The unicorn process

[Service]
User=myname
WorkingDirectory=/var/www/rails/myapp
SyslogIdentifier=unicorn
Type=simple

ExecStart=/bin/bash -l -c 'bundle exec unicorn_rails -c /var/www/rails/myapp/config/unicorn.conf.rb -E production -D'

[Install]
WantedBy=multi-user.target

Here are the commands I used to start the service

sudo systemctl daemon-reload
sudo systemctl start unicorn.service

I can't find any process about unicorn with command ps -ef | grep unicorn | grep -v grep.

Here I check the status:

$ sudo systemctl status unicorn -l
● unicorn.service - The unicorn process
   Loaded: loaded (/etc/systemd/system/unicorn.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

xxx.compute.internal systemd[1]: Started The unicorn process.
xxx.compute.internal systemd[1]: Starting The unicorn process...

Here is unicorn.log. (there aren't any error log)

I, [2020-11-25T20:00:24.564840 #6604]  INFO -- : Refreshing Gem list
I, [2020-11-25T20:00:25.278814 #6604]  INFO -- : unlinking existing socket=/var/www/rails/myapp/tmp/sockets/.unicorn.sock
I, [2020-11-25T20:00:25.279020 #6604]  INFO -- : listening on addr=/var/www/rails/myapp/tmp/sockets/.unicorn.sock fd=9
I, [2020-11-25T20:00:25.299977 #6604]  INFO -- : master process ready
I, [2020-11-25T20:00:25.406567 #6604]  INFO -- : reaped #<Process::Status: pid 6607 exit 0> worker=0
I, [2020-11-25T20:00:25.406659 #6604]  INFO -- : reaped #<Process::Status: pid 6608 exit 0> worker=1
I, [2020-11-25T20:00:25.406760 #6604]  INFO -- : master complete

Why the unicorn doesn't start ?

1

There are 1 best solutions below

0
On

Change Type=simple to Type=forking.