This forum is in archive mode. You will not be able to post new content.

Author Topic: How to create a daemon  (Read 1962 times)

0 Members and 2 Guests are viewing this topic.

Offline m0l0ko

  • Peasant
  • *
  • Posts: 129
  • Cookies: -4
    • View Profile
How to create a daemon
« on: September 14, 2013, 02:03:49 AM »
Don't know if daemon is the right word, I want to make a program that will always be running in the background, waiting for something to happen. In this case I want it to wait for me to get disconnected from my VPN, then it will reconnect me. Basically, I need it to make sure I am always connected to a VPN. What kinda programming concepts do I need to know for this? Can this be done with bash scripting? If not, I suppose I'll use java.

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: How to create a daemon
« Reply #1 on: September 14, 2013, 08:25:07 AM »
I'm not expert on this, but java is not the right tool to use. I'd recommend C++, but try bash first.

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: How to create a daemon
« Reply #2 on: September 14, 2013, 10:33:37 AM »
Have a look here: http://www.gabsoftware.com/tips/automatically-reconnect-to-your-vpn-on-linux/

They do it entirely with bash and also explain how to run it automatically after login in the background.
It is no special programming concept, just check for a variable and sleep for 30 seconds, then check again and sleep for 30 seconds.
« Last Edit: September 14, 2013, 10:36:10 AM by Deque »

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: How to create a daemon
« Reply #3 on: September 14, 2013, 04:34:38 PM »
I'd recommend C++, but try bash first.

C++ for a daemon?

Anything beyond C is overkill, especially if he's in a *nix environment.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline m0l0ko

  • Peasant
  • *
  • Posts: 129
  • Cookies: -4
    • View Profile
Re: How to create a daemon
« Reply #4 on: September 14, 2013, 08:43:57 PM »
Have a look here: http://www.gabsoftware.com/tips/automatically-reconnect-to-your-vpn-on-linux/

They do it entirely with bash and also explain how to run it automatically after login in the background.
It is no special programming concept, just check for a variable and sleep for 30 seconds, then check again and sleep for 30 seconds.

Thanks. I didn't think of just putting it on a sleep loop. Does adding the script to your .profile directory make it run as a background process?

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: How to create a daemon
« Reply #5 on: September 14, 2013, 09:58:59 PM »
Thanks. I didn't think of just putting it on a sleep loop. Does adding the script to your .profile directory make it run as a background process?

No. That just starts it after you logged in. The & in the end of the command makes it work in the background.

Offline m0l0ko

  • Peasant
  • *
  • Posts: 129
  • Cookies: -4
    • View Profile
Re: How to create a daemon
« Reply #6 on: September 20, 2013, 03:02:43 AM »
It works. Thanks a lot. Now I'm trying to think of a way to switch it off and on when I need to. I tried making an environment variable VPN_SWITCH and set it to either on or off, but the script can't read environment variables that I set in another instance of bash like that.
« Last Edit: September 20, 2013, 06:23:34 AM by m0l0ko »

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: How to create a daemon
« Reply #7 on: September 20, 2013, 09:21:11 AM »
Just shut down the program or start it again?

Offline m0l0ko

  • Peasant
  • *
  • Posts: 129
  • Cookies: -4
    • View Profile
Re: How to create a daemon
« Reply #8 on: September 22, 2013, 12:23:41 AM »
I can't seem to kill the process:
Quote
horse@box:~$ ps -e | grep 'vpn'
 2405 ?        00:00:00 vpn.sh <defunct>
horse@box:~$ kill 2405
horse@box:~$ ps -e | grep 'vpn'
 2405 ?        00:00:00 vpn.sh <defunct>

BTW why does it say <defunct> beside the process name?
« Last Edit: September 22, 2013, 12:28:14 AM by m0l0ko »

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: How to create a daemon
« Reply #9 on: September 22, 2013, 10:22:38 AM »
I can't seem to kill the process:
BTW why does it say <defunct> beside the process name?

Its a so called 'zombie' , it probably finished but is still around :)
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: How to create a daemon
« Reply #10 on: September 23, 2013, 08:55:03 PM »
Have you tried kill -9 ?

 



Want to be here? Contact Ande, Factionwars or Kulverstukas on the forum or at IRC.