How to properly integrate your VPN (Or anything else) service

Wishing to create a service for, say, your VPN?

Of course you can always invoke "vpncommand /path/to/your/profilefile" and then look at the log spit it's guts into your terminal until you CTRL^C out. But that might kill your PID.

Or even worst: add a @reboot entry under root's crontab entries.

But the proper solution is not only easier but also quite more elegant:

Step 1 - Create your service name:
sudo systemctl edit --force --full MYNAME.service

Step 2 - Populate the .service file:
You're now in a nano screen. Key in something like:

[Unit]
Description=MY DESCRIPTION
[Service]
ExecStart=/path/to/my/binary /path/to/my/profile.file
[Install]
WantedBy=multi-user.target

CTRL^X will ask you to save and quit.

Step 3 - Refreshing systemctl with this newly created service:
sudo systemctl daemon-reload

Step 4 - Starting the service at boot:
sudo systemctl enable MYNAME.service

Step 5 - Managing the service:
sudo systemctl start MYNAME.service
sudo systemctl stop MYNAME.service
sudo systemctl status MYNAME.service

That was easy, enjoy!

3 Likes