Tip: How to start OpenVPN server when systemd based service start to refuse on boot

0
Want create site? Find Free WordPress Themes and plugins.

For some weird reason, I can not get my OpenVPN server to come up at boot time using systemd on an Ubuntu Linux 16.04 LTS server. I have tried a few settings but failed so far.
So I twitted about it:
Here is my /lib/systemd/system/openvpn.service file:
# cat /lib/systemd/system/openvpn.service

# This service is actually a systemd target,
# but we are using a service since targets cannot be reloaded.
 
[Unit]
Description=OpenVPN service
After=network.target
 
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecReload=/bin/true
WorkingDirectory=/etc/openvpn
 
[Install]
WantedBy=multi-user.target

# This service is actually a systemd target,
# but we are using a service since targets cannot be reloaded.[Unit]
Description=OpenVPN service
After=network.target[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/true
ExecReload=/bin/true
WorkingDirectory=/etc/openvpn[Install]
WantedBy=multi-user.target

I wanted to run services after the network is up so that OpenVPN can bind to specific IP and port. The After=network.target tells to wait until the nework is “up”.

My fix

I finally gave up and simply wrote cron job that will start after each system reboot:
@reboot sleep 100;/etc/init.d/openvpn restart;/etc/init.d/ssh restart;/etc/init.d/squid reload
The @reboot forces to run job once, at startup. In this case, restart the openvpn server, and bind sshd/squid to openvpn port:
$ ss -tulpn
OR
$ netstat -tulpn
Sample outputs:

tcp        0      0 10.8.0.1:80             0.0.0.0:*               LISTEN      1549/lighttpd   
tcp        0      0 0.0.0.0:53              0.0.0.0:*               LISTEN      1524/dnsmasq    
tcp        0      0 10.8.0.1:22             0.0.0.0:*               LISTEN      1756/sshd       
tcp        0      0 10.8.0.1:3128           0.0.0.0:*               LISTEN      1675/(squid-1)  
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      1732/openvpn

There must be a way to run services (OpenVPN) after the network is up. However, I failed to figure it out. If anyone knows how to fix this problem without using cron, let me know in the comments section below.
Source

Did you find apk for android? You can find new Free Android Games and apps.

You might also like More from author