<![CDATA[nginx - theCruskit]]>https://thecruskit.com/Ghost 0.11Tue, 05 May 2020 10:56:03 GMT60<![CDATA[Using systemd to manage Ghost & nginx on CentOS 7]]>So, you want to be able to easily stop and start Ghost & nginx on CentOS7? (at least I did when I was setting up this blog...)

Centos 7 uses systemd rather than the older /etc/init.d method of managing services and daemons, so it could be a little

]]>
https://thecruskit.com/using-systemd-to-manage-ghost-nginx-on-centos/ce09b439-e2c0-4549-a4c1-856b22ab07adMon, 17 Nov 2014 10:49:28 GMTSo, you want to be able to easily stop and start Ghost & nginx on CentOS7? (at least I did when I was setting up this blog...)

Centos 7 uses systemd rather than the older /etc/init.d method of managing services and daemons, so it could be a little bit of a change from what you're used to (and a source of a little controversy).

systemd uses service files (unit definitions) that declaratively capture the expected behaviour of an application (eg: how to start/stop, automatic restart behaviour upon failure, etc) as its native method of configuration.

nginx comes with a systemd unit definition (see: /usr/lib/systemd/system/nginx.service), so if you've installed from the standard repos using yum, you should be able to start, stop, restart & check status nginx using the following (as root or via sudo):

systemctl start nginx  
systemctl stop nginx  
systemctl restart nginx  
systemctl status nginx  

If you install Ghost by using the zip file installer then you will need to provide a unit definition for Ghost so it can be managed by systemd. An example of a unit definition is below (change user, group, paths to ghost as appropriate for your installation). Create the unit definition as:

/etc/systemd/system/ghost.service

[Service]
ExecStart=/usr/bin/node /ghost/index.js  
Restart=always  
StandardOutput=syslog  
StandardError=syslog  
SyslogIdentifier=ghost  
User=ghost  
Group=ghost  
Environment=NODE_ENV=production

[Install]
WantedBy=multi-user.target  

Once you've created the ghost.service file you'll be able to manage ghost in the same way as nginx, ie:

systemctl start ghost  
systemctl stop ghost  
systemctl restart ghost  
systemctl status ghost  

Note that having Restart=always set in the unit definition means that if the node.js process running ghost dies for any reason, then systemd will automatically restart it.

For more detailed information on how to use systemd (enabling/disabling services, auditing, logging, etc), some useful references include:

]]>