Go to ...

Techpository

A Better Technical Repository

RSS Feed

Linux: Creating a systems service


Knockd was causing me a headache with the error “command returned non-zero status code (1)” when running with their stock init.d setup.

Rather than troubleshooting their bug I decided to create my own service that would start using the /usr/sbin/knockd directly.

Step (1) Create the startup script
nano /etc/systemd/system/knockd-security.service

[Unit]
Description=knockdservice
After=network-online.target

[Service]
Type=idle
ExecStart=/usr/local/bin/knockd-security.sh

[Install]
WantedBy=default.target

Ctrl X
y

chmod 664 /etc/systemd/system/knockd-security.service

Step (2) Create the startup shell script
nano /usr/local/bin/knockd-security.sh
#!/bin/bash
/usr/sbin/knockd

Ctrl X
y

chmod 744 /usr/local/bin/knockd-security.sh

Step(3) Finalization
systemctl daemon-reload
systemctl enable knockd-security.service

Step(4) Test before reboot
systemctl start knockd-security.service

Step(5) Reboot
reboot

By: Timothy Conrad