Skip to content

Instantly share code, notes, and snippets.

@connerbrooks
Last active January 8, 2018 09:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save connerbrooks/481e8a5fd91b672943590ab84126fa67 to your computer and use it in GitHub Desktop.
Save connerbrooks/481e8a5fd91b672943590ab84126fa67 to your computer and use it in GitHub Desktop.
cgd for swerc or werc with systemd
[Unit]
Description=Job that runs cgd for my cool swerc site.
[Service]
Type=simple
ExecStart=/home/cbrooks/develop/bin/cgd -f -c /home/cbrooks/swerc/bin/werc.rc

Here is a simple NGINX configuration that will handle static files and serve werc from an fcgi proxy like cgd running on port 3333:

server {
        listen   80;

        server_name *.cat-v.org;
        set $werchome /home/uriel/dvl/werc/; # Location of your werc installation

        root $werchome/sites/$host/;
        index index.html;

        location / {
                try_files $uri @werc;
        }
        location /pub/ {
                root $werchome;
                try_files $uri =404;
        }
        location = /favicon.ico {
                root $werchome;
                try_files $werchome/$host/$uri /pub/default_favicon.ico =404;
        }

        error_page 404 = @werc;

        location @werc {
                include fastcgi_params;
                fastcgi_pass localhost:3333;
        }
}

Then run cgd like this: cgd -f -c /home/uriel/dvl/werc/bin/werc.rc

Once you have it working you can create a systemd unit to run cgd as a daemon.

e.g. /lib/systemd/system/cgd-werc.service

[Unit]
Description=Job that runs cgd for my cool swerc site.

[Service]
Type=simple
ExecStart=/home/cbrooks/develop/bin/cgd -f -c /home/cbrooks/swerc/bin/werc.rc
@Marneus68
Copy link

Maybe I'm not the best with systemd stuff, but I haven't been able to enable and start the newly created service without it having an [Install] section in it. Without that, when attempting to start the service I get the following message:

The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
settings in the [Install] section, and DefaultInstance for template units).
This means they are not meant to be enabled using systemctl.
Possible reasons for having this kind of units are:
1) A unit may be statically enabled by being symlinked from another unit's
   .wants/ or .requires/ directory.
2) A unit's purpose may be to act as a helper for some other unit which has
   a requirement dependency on it.
3) A unit may be started when needed via activation (socket, path, timer,
   D-Bus, udev, scripted systemctl call, ...).
4) In case of template units, the unit is meant to be enabled with some
   instance name specified.

I added the following to the service file to get it to work properly:

[Install]
WantedBy=multi-user.target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment