LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-05-2013, 05:19 PM   #1
stx
LQ Newbie
 
Registered: Nov 2013
Posts: 11

Rep: Reputation: Disabled
Run script on boot (also known as: how do I autoconnect to a VPN server?)


Hey there,

I am a big fan of this forum (about 100 questions were answered because I found the solution in here), and now it's time to register.

I am using Fedora 19 with GNOME3. I want to connect to a VPN server when I boot the pc. I don't care whether this is before or after login, but it would be nice before I open the browser. I figured out how to start the connection in the terminal (nmi con list for getting the UUID, nmcli con up <UUID> for connecting) and this works fine. I created a file called runvpn.sh with the one line nmcli con up 00816530-4668-11e3-8f96-0800200c9a66, saved it in the /bin folder and now I can run the script by calling runvpn.sh. That's nice, so I thought, opening gnome properties and added this to the autostart programs. But nothing happens. Maybe this is because the script starts before OpenVPN? I don't know, I just know that this doesn't work. Can anyone help me out? :/

Thanks so much in advance!


stx
 
Old 11-05-2013, 06:47 PM   #2
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
You could enable the rc.local service in Fedora 19...


First create the file
Code:
touch /etc/rc.local
chmod +x /etc/rc.local
Edit this file with your commands
Code:
#!/bin/bash
/bin/runvpn.sh
##
##
Make sure it starts on boot
Code:
systemctl enable rc-local.service
Reboot and it should run your script before you login
 
Old 11-05-2013, 07:48 PM   #3
stx
LQ Newbie
 
Registered: Nov 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
Hello, thanks for this quick response. I didn't know that rc has to be enabled haha. Tried it, restarted, didn't work. Tried it again and found out that there was an error

Code:
sudo systemctl enable rc-local.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, ...).
So, what can I do? :/
 
Old 11-05-2013, 08:35 PM   #4
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Try symliking it manually

Code:
ln -s /usr/lib/systemd/system/rc-local.service /etc/systemd/system/multi-user.target.wants/rc-local.service
Then start the service

Code:
systemctl start rc-local.service
Make sure that you have #!/bin/bash on top of the file.

Then reboot and see if that works for you.

OR

You can just edit the file so it looks something like this (basically add the [Install] part)

Code:
[Unit]
Description=/etc/rc.d/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.d/rc.local
After=network.target

[Service]
Type=forking
ExecStart=/etc/rc.d/rc.local start
TimeoutSec=0
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target
Then try the enable step and reboot

--C

Last edited by custangro; 11-05-2013 at 08:42 PM.
 
Old 11-06-2013, 05:58 AM   #5
stx
LQ Newbie
 
Registered: Nov 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
Thanks for your help. But still, nothing happens. I didn't know that it was that complicated to run this simple command line.
I've added the #/bin/bash line to the runvpn.sh (before it was only a one-liner), but this had no effect.

Can I manipulate any other service that's started on boot? Like, I don't know, add the /bin/runvpn.sh line to the network service? Haha..
 
Old 11-06-2013, 06:13 AM   #6
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
I would read the documentation for OpenVPN

I appear to have miss placed my fedora VM ( Ok I deleted it a while back )

but , on Debian you have a config in

/etc/default/openvpn

Code:
# This is the configuration file for /etc/init.d/openvpn

#
# Start only these VPNs automatically via init script.
# Allowed values are "all", "none" or space separated list of
# names of the VPNs. If empty, "all" is assumed.
# The VPN name refers to the VPN configutation file name.
# i.e. "home" would be /etc/openvpn/home.conf
#
#AUTOSTART="all"
#AUTOSTART="none"
#AUTOSTART="home office"
#
# Refresh interval (in seconds) of default status files
# located in /var/run/openvpn.$NAME.status
# Defaults to 10, 0 disables status file generation
#
#STATUSREFRESH=10
#STATUSREFRESH=0
# Optional arguments to openvpn's command line
OPTARGS=""
#
# If you need openvpn running after sendsigs, i.e.
# to let umountnfs work over the vpn, set OMIT_SENDSIGS
# to 1 and include umountnfs as Required-Stop: in openvpn's
# init.d script (remember to run insserv after that)
#
OMIT_SENDSIGS=0

dig around, you will find something like the above
 
Old 11-06-2013, 06:25 AM   #7
stx
LQ Newbie
 
Registered: Nov 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
I'll try that, but before I'll try something else. What about the .~/.bash_profile?

Now, it looks like this (and nothing works), how can I arrange that this works?

Code:
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/.local/bin:$HOME/bin

export PATH

/run/openvpn.sh
When I add just the line to bashrc, I really autoconnect to VPN everytime I open a terminal! So it has to work with the bash_profile too...
 
Old 11-06-2013, 06:43 AM   #8
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
do you really want to startvpn every time you open a shell?


just configure openvpn correctly, no need to 'hack' it
 
Old 11-06-2013, 12:04 PM   #9
custangro
Senior Member
 
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
Blog Entries: 1

Rep: Reputation: 209Reputation: 209Reputation: 209
Quote:
Originally Posted by stx View Post
Thanks for your help. But still, nothing happens. I didn't know that it was that complicated to run this simple command line.
I've added the #/bin/bash line to the runvpn.sh (before it was only a one-liner), but this had no effect.

Can I manipulate any other service that's started on boot? Like, I don't know, add the /bin/runvpn.sh line to the network service? Haha..
I meant to add the bash line to /etc/rc.local

You may have some SELinux errors too; what does the log show?

Quote:
I didn't know that it was that complicated to run this simple command line.
Consider this a learning experience :-)

Also I agree with Firerat ...take the time to try and set up OpenVPN
 
Old 11-13-2013, 07:39 AM   #10
stx
LQ Newbie
 
Registered: Nov 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
Shit, I think I'm too stupid for that haha. There's no /etc/default/openvpn nor an openvpn file in init.d - but there's a network file! I've added nmcli con up uuid bla bla, but nothing's happening... -__-
 
Old 11-13-2013, 08:17 AM   #11
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 4,137
Blog Entries: 1

Rep: Reputation: 875Reputation: 875Reputation: 875Reputation: 875Reputation: 875Reputation: 875Reputation: 875
Make sure the script and rc.local have the execution bit enabled, aka chmod +x.
 
Old 11-13-2013, 08:37 AM   #12
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
I'll have to re-vm Fedora and dig around

can't right now as my box is busy 'trying' to compile kitkat

however, a quick search got me this
https://fedoraproject.org/wiki/Openv...OpenVPN_client
 
Old 11-13-2013, 08:38 AM   #13
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by Shadow_7 View Post
Make sure the script and rc.local have the execution bit enabled, aka chmod +x.
since fedora 19 uses systemd, the rc.local isn't going to work
 
Old 11-13-2013, 10:49 AM   #14
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326

Rep: Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920Reputation: 920
Quote:
Originally Posted by Firerat View Post
since fedora 19 uses systemd, the rc.local isn't going to work
does fedora still listen to the @reboot declaritive in cron ?
 
Old 11-13-2013, 02:20 PM   #15
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by schneidz View Post
does fedora still listen to the @reboot declaritive in cron ?
yeap

but still,
configuring the client as per https://fedoraproject.org/wiki/Openv...OpenVPN_client

is the way to go


I do have to correct my assumtion, from ( fedora 16 release notes )

https://docs.fedoraproject.org/en-US..._Sysadmin.html
Quote:
3.2.4. rc.local no longer packaged
The /etc/rc.d/rc.local local customization script is no longer included by default. Administrators who need this functionality merely have to create this file, make it executable, and it will run on boot.
Upgrades are not affected by this change.
guess it is the same for 19

but again, with a properly configured openvpn it is not required

rc.local vs @reboot ( cron )

I would prefer @reboot, since it is easier to 'build in' reporting ( cron will email any output it 'sees' *)

* get your custom scripts to be silent , unless they encounter an error in which case get it to 'print' relevant reports

Code:
export MAIL=/var/mail/$USER
export MAILCHECK=60
and your bash shell will check for mail every 60 seconds
https://www.gnu.org/software/bash/ma...ndex-MAILCHECK

Not all that relevant for an @reboot, but handy to know
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu: Autoconnect OpenVPN client (GUI) THEN afterwards run a script (as root) riahc3 Linux - Networking 8 03-11-2013 04:34 AM
Run custom boot script from a network server? cantab Ubuntu 1 06-16-2010 11:26 AM
VNC autoconnect script newbe45 Linux - Software 3 05-07-2007 10:34 PM
Autoconnect to AP with wpa_supplicant at boot android6011 Linux - Networking 2 09-15-2006 08:51 PM
Autoconnect at boot - Speedtouch 330 Nosra Linux - Hardware 5 03-13-2005 08:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 07:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration