I have a custom systemd service in CentOS 7 whose startup script lives under version control at
[Unit] Description=website After=syslog.target network.target [Service] Type=forking User=website ExecStart=/opt/perl5/perls/perl-5.20.2/bin/hypnotoad /var/www/domains/<domain>/script/site.pl ExecStop=/opt/perl5/perls/perl-5.20.2/bin/hypnotoad --stop /var/www/domains/<domain>/script/site.pl [Install] WantedBy=multi-user.target
If I run
systemctl enable /srv/etc/systemd/website.service it creates the symlinks fine and I can run
systemctl start website and the service comes up, but it complains about a missing [Install] section, which clearly isn't correct:
$ sudo systemctl enable /srv/etc/systemd/website.service Created symlink from /etc/systemd/system/website.service to /srv/etc/systemd/website.service. The unit files have no [Install] section. 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, ...).
After rebooting, the service does not come up, and a
systemctl start website returns
Failed to start website.service: Unit not found. If I run
systemctl daemon-reload, the
start command works again.
However, if I copy the file into /etc/systemd/system and run
systemctl enable website, everything works as expected and the service comes up immediately after reboot.
Is it actually possible to do what I'm trying to do, or do I just need to live with remembering to manually copy the systemd script from my Git repo if I make any changes?