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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
|
11-05-2013, 05:19 PM
|
#1
|
LQ Newbie
Registered: Nov 2013
Posts: 11
Rep: 
|
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
|
|
|
11-05-2013, 06:47 PM
|
#2
|
Senior Member
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
|
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
|
|
|
11-05-2013, 07:48 PM
|
#3
|
LQ Newbie
Registered: Nov 2013
Posts: 11
Original Poster
Rep: 
|
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? :/
|
|
|
11-05-2013, 08:35 PM
|
#4
|
Senior Member
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
|
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.
|
|
|
11-06-2013, 05:58 AM
|
#5
|
LQ Newbie
Registered: Nov 2013
Posts: 11
Original Poster
Rep: 
|
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..
|
|
|
11-06-2013, 06:13 AM
|
#6
|
Senior Member
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683
|
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
|
|
|
11-06-2013, 06:25 AM
|
#7
|
LQ Newbie
Registered: Nov 2013
Posts: 11
Original Poster
Rep: 
|
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...
|
|
|
11-06-2013, 06:43 AM
|
#8
|
Senior Member
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683
|
do you really want to startvpn every time you open a shell?
just configure openvpn correctly, no need to 'hack' it
|
|
|
11-06-2013, 12:04 PM
|
#9
|
Senior Member
Registered: Nov 2006
Location: California
Distribution: Fedora , CentOS , RHEL
Posts: 1,979
|
Quote:
Originally Posted by stx
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
|
|
|
11-13-2013, 07:39 AM
|
#10
|
LQ Newbie
Registered: Nov 2013
Posts: 11
Original Poster
Rep: 
|
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... -__-
|
|
|
11-13-2013, 08:17 AM
|
#11
|
Senior Member
Registered: Feb 2003
Distribution: debian
Posts: 4,137
|
Make sure the script and rc.local have the execution bit enabled, aka chmod +x.
|
|
|
11-13-2013, 08:37 AM
|
#12
|
Senior Member
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683
|
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
|
|
|
11-13-2013, 08:38 AM
|
#13
|
Senior Member
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683
|
Quote:
Originally Posted by Shadow_7
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
|
|
|
11-13-2013, 10:49 AM
|
#14
|
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,326
|
Quote:
Originally Posted by Firerat
since fedora 19 uses systemd, the rc.local isn't going to work
|
does fedora still listen to the @reboot declaritive in cron ?
|
|
|
11-13-2013, 02:20 PM
|
#15
|
Senior Member
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683
|
Quote:
Originally Posted by schneidz
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.
|
All times are GMT -5. The time now is 07:23 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|