0

I've installed ocserv package using these commands on Ubuntu22:

mkdir /usr/local/src/ocserv
cd /usr/local/src/ocserv
wget ftp://ftp.infradead.org/pub/ocserv/ocserv-0.10.9.tar.xz
unxz ocserv-0.10.9.tar.xz
tar xvf ocserv-0.10.9.tar
cd ocserv-0.10.9
./configure --sysconfdir=/etc/ && make && make install

The ocserv package is installed and it run and works with this command:

ocserv -c /etc/ocserv/ocserv.conf

I need it to run as a service. can you please help me doing this?

  • I couldn't use the linux repository to install this package because of some considerations.
Ethan_m
  • 11
  • 4

3 Answers3

0

First create a systemd unit for this service:

systemctl edit --force --full ocserv.service

With these contents:

[Unit]
Description=OCServ service
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=on-failure
RestartSec=1
User=root
ExecStart=/usr/local/sbin/ocserv -c /etc/ocserv/ocserv.conf

[Install]
WantedBy=multi-user.target

Save it and enable the new service:

systemctl enable --now ocserv.service

You can view its status with this command:

systemctl status ocserv.service
Sergiu
  • 66
  • 3
  • Hello and thanks for the explanation. I did all the steps but service remains inactive. I'll share some logs in a new post – Ethan_m Jan 17 '23 at 19:58
0

systemctl status ocserv it should automatically create service for you. if you are talking about openconnect server.

however if you are talking about vpn client and you want the client to automatically connect to vpn server at startup do the steps below

nano /etc/systemd/system/openconnect.service

[Unit]
Description=Connect to VPN
After=network.target

[Service]
Type=simple
Environment=password=correcthorsebatterystaple
ExecStart=/bin/sh -c 'echo password | sudo openconnect -u username --passwd-on-stdin vpn.dixmata.com'
Restart=always

[Install]
WantedBy=multi-user.target


sudo systemctl daemon-reload
sudo systemctl enable openconnect.service --now
0

Thanks to Sergiu, with some modification to his instructions, I finally managed to run ocserv as a system service in ubuntu.

First I wanted to edit Sergiu's post but then I thought it may not be right. So I put the edited instruction here.

First create a systemd unit for this service:

systemctl edit --force --full ocserv.service

With these contents:

[Unit]
Description=OCServ service
After=network.target
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=on-failure
RestartSec=1
User=root
ExecStart=/usr/local/sbin/ocserv --foreground --pid-file /var/run/ocserv.pid --config /etc/ocserv/ocserv.conf

[Install]
WantedBy=multi-user.target

Save it and enable the new service:

systemctl enable --now ocserv.service

You can view its status with this command:

systemctl status ocserv.service

If the service was inactive or had any error:

systemctl restart ocserv.service

And recheck the service status:

systemctl status ocserv.service
Ethan_m
  • 11
  • 4