Added instructions
For running a python script as service/on boot
This commit is contained in:
parent
fb7708cf94
commit
a0369fff16
71
README.md
71
README.md
@ -277,7 +277,6 @@ Restart dnsmasq to apply the changes:
|
||||
Now all http requests will be directed to Meshenger!
|
||||
|
||||
|
||||
|
||||
### Installing meshenger
|
||||
|
||||
Get the dependencies and clone the git
|
||||
@ -285,3 +284,73 @@ Get the dependencies and clone the git
|
||||
`$ opkg install python git `
|
||||
|
||||
`$ git clone git://github.com/jngrt/meshenger.git `
|
||||
|
||||
|
||||
### Running Meshenger on Boot
|
||||
|
||||
To launch the Meshenger script (or python script in this case), we have to run it as a 'Service'.
|
||||
Befor we can do so we need to know some variable.
|
||||
|
||||
# Path to python
|
||||
Find out where your Python binary is located:
|
||||
|
||||
```$ which python```
|
||||
|
||||
This command outputs your path, for example: ` /usr/bin/python`, remember this path
|
||||
|
||||
# Boot order
|
||||
Alot of processes are started at boot, and we want to make sure our script runs after the system has booted completely. To find out the boot order, look in the rc.d folder:
|
||||
|
||||
```$ ls /etc/rc.d```
|
||||
|
||||
This will output a list of startup sctipts with prefixes like S10-, S20-, S30-. The numbers define the boot order, the higher, the later. Remember the highest 'S'(cript) number. We need to run our script after the last one.
|
||||
|
||||
|
||||
# Startup script
|
||||
Create a new file in `/etc/init.d/`
|
||||
|
||||
```$ vi /etc/init.d/meshenger```
|
||||
|
||||
And paste the script below and correct your path to pyton and boot order number, both found above.
|
||||
|
||||
```
|
||||
#!/bin/sh /etc/rc.common
|
||||
#meshenger startup script
|
||||
|
||||
START=99 #the boot order number, note in our case the SAME number as the highest one found.
|
||||
SERVICE_DAEMONIZE=1 #start as service, important!
|
||||
|
||||
start(){
|
||||
sleep 10 #make sure booting is finished
|
||||
echo 'starting meshenger'
|
||||
/usr/bin/python /root/meshenger/main.py & #path to python binary, space, full path to your script
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
stop(){
|
||||
echo 'stopping meshenger'
|
||||
killall python
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Make sure both your script (main.py) and the init.d script are executable!
|
||||
|
||||
```$ chmod +x /etc/init.d/meshenger```
|
||||
```$ chmod +x /root/meshenger/main.py```
|
||||
|
||||
|
||||
|
||||
# Enabling the service
|
||||
Now we have to activate the script we just pasted and make it run as service, on every (re)boot.
|
||||
|
||||
```$ /etc/init.d/meshenger enable```
|
||||
|
||||
This creates a symlink in `/etc/rc.d` with the boot order number prefix you provided in the init.d script (S99-meshenger). You can also start and stop the service manually with:
|
||||
|
||||
```$ /etc/init.d/meshenger start```
|
||||
```$ /etc/init.d/meshenger stop```
|
||||
|
||||
That's all, reboot and see if it works ( `$ ps | grep python` )!
|
||||
|
Loading…
Reference in New Issue
Block a user