You are not logged in.
Pages: 1
hi to everybody,
i want to create a script that start a daemon, then launch an application and finally when the application close, stopping the daemon
anybody can help me ?
thanks
Last edited by nTia89 (2011-08-25 19:47:49)
+pc: custom | AMD Opteron 175 | nForce4 Ultra | 2GB ram DDR400 | nVidia 9800GT 1GB | ArchLinux x86_64 w/ openbox
+laptop: Apple | MacBook (2,1) | 2GB ram | Mac OS X 10.4 -> DIED
+ultrabook: Dell | XPS 13 (9343) | 8GB ram | 256GB ssd | FullHD display | Windows 8.1 64bit ArchLinux x86_64 w/ Gnome
Offline
#!/bin/sh
sudo rc.d start <daemon>
<application>
sudo rc.d stop <daemon>
?
Offline
Try something like
if pgrep app >/dev/null; then
sleep 60
else
sudo rc.d stop daemon
fi
to check if the app is running every minute.
Last edited by karol (2011-08-23 15:36:20)
Offline
Better use $! and wait:
# start daemon...
# start the app in background, get its pid and wait for it to terminate:
app & pid=$!
wait $pid
# stop daemon...
Offline
Better use $! and wait:
# start daemon... # start the app in background, get its pid and wait for it to terminate: app & pid=$! wait $pid # stop daemon...
Aka,
app # start the app in the foreground
?
I think karol was thinking about the case when the app forks into the background or something and you need to wait for it to close. But usually there's a --no-fork option or something for that case.
Offline
thanks very much hbekel, this is what i need:
now i have to refine it...... for example, don't start the application until the daemon is started, any idea ?
+pc: custom | AMD Opteron 175 | nForce4 Ultra | 2GB ram DDR400 | nVidia 9800GT 1GB | ArchLinux x86_64 w/ openbox
+laptop: Apple | MacBook (2,1) | 2GB ram | Mac OS X 10.4 -> DIED
+ultrabook: Dell | XPS 13 (9343) | 8GB ram | 256GB ssd | FullHD display | Windows 8.1 64bit ArchLinux x86_64 w/ Gnome
Offline
But seriously, why not this?
#!/bin/bash
gksudo /etc/rc.d/tor start
chromium --proxy-server="socks://localhost:9050"
gksudo /etc/rc.d/tor stop
Offline
what change between my (hbekel) script and your ?
Last edited by nTia89 (2011-08-23 21:34:54)
+pc: custom | AMD Opteron 175 | nForce4 Ultra | 2GB ram DDR400 | nVidia 9800GT 1GB | ArchLinux x86_64 w/ openbox
+laptop: Apple | MacBook (2,1) | 2GB ram | Mac OS X 10.4 -> DIED
+ultrabook: Dell | XPS 13 (9343) | 8GB ram | 256GB ssd | FullHD display | Windows 8.1 64bit ArchLinux x86_64 w/ Gnome
Offline
But seriously, why not this?
#!/bin/bash gksudo /etc/rc.d/tor start chromium --proxy-server="socks://localhost:9050" gksudo /etc/rc.d/tor stop
Yes, of course. Don't know what I was thinking, maybe Karol send me on the wrong track For the above purpose this is all that's needed. Sorry for causing confusion.
@nTia89: the method I described is useful only in the case where you want to start some app and do some more stuff right away before finally
waiting for the app to terminate. The way I use it in my example is pretty pointless, as it has the exact same effect as simply starting the app in the foreground.
Offline
ok,
now i want to refine my script.
how can i check if the daemon is already running ?
+pc: custom | AMD Opteron 175 | nForce4 Ultra | 2GB ram DDR400 | nVidia 9800GT 1GB | ArchLinux x86_64 w/ openbox
+laptop: Apple | MacBook (2,1) | 2GB ram | Mac OS X 10.4 -> DIED
+ultrabook: Dell | XPS 13 (9343) | 8GB ram | 256GB ssd | FullHD display | Windows 8.1 64bit ArchLinux x86_64 w/ Gnome
Offline
how can i check if the daemon is already running ?
if pgrep daemon_name >/dev/null; then
do_this
else
do_that
fi
works for most apps,
rc.d list started | grep daemon_name
may be better for daemons.
Last edited by karol (2011-08-24 12:12:29)
Offline
thanks very much, i think i can put solved
despite i used another if costruct...... because with your it can't works.....
but, this is the result: http://pastebin.com/YZqQvGTJ
with this script i finally can use tor as i need, without the firefox buggy extension !!!!
Last edited by nTia89 (2011-08-25 19:49:01)
+pc: custom | AMD Opteron 175 | nForce4 Ultra | 2GB ram DDR400 | nVidia 9800GT 1GB | ArchLinux x86_64 w/ openbox
+laptop: Apple | MacBook (2,1) | 2GB ram | Mac OS X 10.4 -> DIED
+ultrabook: Dell | XPS 13 (9343) | 8GB ram | 256GB ssd | FullHD display | Windows 8.1 64bit ArchLinux x86_64 w/ Gnome
Offline
Pages: 1