Moving to systemd
Having recently set up a self-hosted Ghost server on DigitalOcean using their "one-click application" images, I wanted to upgrade the system since the base image used Ubuntu 14.04. The latest version of Ubuntu at the moment (16.04.1) utilizes systemd. Because of this, the Ghost service won't restart properly since it was configured using the prior Upstart init system in Ubuntu 14.04 and there won't be a corresponding systemd configuration in the new 16.04 system.
This post describes the process of adding a service configuration to utilize the new systemd init system. The example is a self-hosted Ghost blog application but this would apply to any service.
Who is this relevant For?
If you upgraded your Linux system to a systemd based system from a prior System V or Upstart based init system.
For example, after an upgrade, your service might encounter the following error
Failed to start ghost.service: Unit ghost.service failed to load: No such file or directory.
Here are the steps to achieve the above with detailed explanations of steps and configuration items. Once complete, see the reference section for further reading. Enjoy!
Create systemd service configuration file for ghost
Create the new systemd service configuration file at this location
[Unit] Description=ghost # free-form string describing the unit After=network.target # start after these services are started [Service] Type=simple # type of service--see reference section WorkingDirectory=/var/www/ghost # working dir for executed processes User=ghost Group=ghost ExecStart=/usr/bin/npm start --production # executed when this service is started ExecStop=/usr/bin/npm stop --production # executed when this service is stopped Restart=always # restart when the service process exits, is killed, or a timeout is reached? SyslogIdentifier=Ghost # prefix for log lines sent to the logging system [Install] WantedBy=multi-user.target # service(s) dependent on this service
Enable new service
systemctl enable ghost to enable the service. It should now restart upon reboot of the system.
Check service status
To check the status of your service use the
systemctl status ghost
- Determine what init system is used: http://unix.stackexchange.com/questions/196166/how-to-find-out-if-a-system-uses-sysv-upstart-or-systemd-initsystem
- Error after upgrading to systemd based init: http://askubuntu.com/questions/690993/mongodb-3-0-2-wont-start-after-upgrading-to-ubuntu-15-10
- Systemd "service" config reference: https://www.freedesktop.org/software/systemd/man/systemd.service.html
- Systemd "unit" config reference: https://www.freedesktop.org/software/systemd/man/systemd.unit.html
- What is /etc/init vs /etc/init.d?: http://askubuntu.com/questions/5039/what-is-the-difference-between-etc-init-and-etc-init-d