Skip to content

Manage with systemd (WIP)

Ami Mahloof edited this page Feb 20, 2017 · 10 revisions

This is a placeholder page to add some (recommended?) practices on running eye in a server using systemd.

Files:

# /etc/eye/config.rb
# vi:syntax=ruby   

Eye.load('./apps-enabled/*.rb')

Eye.config do
  logger '/tmp/eye.log'
end

and

# /etc/eye/apps-available/my_app.rb
# a normal eye file, but don't set things in the global scope,
# everything inside the `Eye.application 'myapp'` block

Eye.application 'myapp' do
  cwd = "some/dir"
  env "RAILS_ENV" => rails_env
  process "thin" do
    # Note: use binstubs to ensure the right ruby version etc is used"
    start_command "bin/thin start ..." 
  end
end

and

# /etc/systemd/system/eye.service
# vi:syntax=dosini

[Unit]
Description=Run the eye daemon

[Service]
Type=forking
Environment=HOME=/tmp
ExecStart=/usr/local/bin/eye load /etc/eye/config.rb

If you want to run eye on system boot using systemctl script provided here, you also need to add [Install] section, so whole file would look like this:

# /etc/systemd/system/eye.service
# vi:syntax=dosini

[Unit]
Description=Run the eye daemon

[Service]
Type=forking
Environment=HOME=/tmp
ExecStart=/usr/local/bin/eye load /etc/eye/config.rb

[Install]
WantedBy=multi-user.target

You can also use a service unit like below to start the service on boot, but not supervise it after the initial start-up, which is useful for allowing non-privileged users to manage the service through eye, but still ensure service start-up on boot.

[Unit]
Description=My App

[Install]
WantedBy=multi-user.target

[Service]
WorkingDirectory=/srv/my-app/current
User=deploy
Group=deploy
EnvironmentFile=/srv/my-app/.rbenv-vars
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/local/rbenv/shims/bundle exec eye load /srv/my-app/current/config/my-app.eye

In order to make sure that the services are running on start up

sudo systemctl enable eye.service

Created symlink from /etc/systemd/system/multi-user.target.wants/eye.service to /etc/systemd/system/eye.service.

Then hopefully with systemctl start eye.service everything will work...