问题
I have a script that sends me a pushover notification when my headless Raspberry Pi (running Debian Wheezy) boots. I also have it set up to connect to OpenVPN on boot.
Problem 1: The problem is that it sends this notification before the OpenVPN connection is established. So I get sent the WAN IP, and not our secured VPN IP.
Problem 2: It runs the pushover notification when the system is shutting down. So when it shuts down I get the same PO notification: Hey, I'm online! My IP is: X.X.X.X
I think the problem has to do with update-rc.d
I created my pushover script in /etc/init.d/
I did chmod +x
I ran:
update-rc.d myscript defaults 02 98
Rebooted and still, the PO is sent first, and the VPN connects second.
So I also tried the reverse:
update-rc.d myscript defaults 98 02
Rebooted and still, the PO is sent first, and the VPN connects second.
So I tried adding sleep 15 to my script, and still the same problem.
How can I make OpenVPN connect first, then send the notification after that? How can I make this script NOT run when the system is shutting down?
Here is my script:
#!/bin/bash
sleep 30
WANIP=$(curl ident.me; echo)
echo "$WANIP"
curl -s \
-F "token=MYTOKENGOESHERE" \
-F "user=MYTOKENGOESHERETOO" \
-F "message=is online and connected. ${WANIP} is my IP." \
https://api.pushover.net/1/messages.json
回答1:
The update-rc application simply creates a symbolic link inside the rc.X folder, where the X will vary depending on your necessity of when the script should run. When you use the default option, the link will be created inside all the folders, resulting on the script being ran at every state of the defined states of the OS.
One solution would be to create the links manually only inside the folders that corresponds to the events that you want to trigger. The corresponding folder where the link should be created can be found here:
http://www.linux.com/news/enterprise/systems-management/8116-an-introduction-to-services-runlevels-and-rcd-scripts
Onother quick solution would be to use the default configuration and then remove the symbolic link from the rc.0 folder, which according to the article above carries the links to the scripts to be executed when you halt the OS.
来源:https://stackoverflow.com/questions/24434089/update-rc-d-custom-script-running-too-late-and-also-runs-at-shutdown