Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New feature: run mole in background mode #10

Closed
davrodpin opened this issue Oct 15, 2018 · 8 comments
Closed

New feature: run mole in background mode #10

davrodpin opened this issue Oct 15, 2018 · 8 comments
Labels
enhancement New feature or request

Comments

@davrodpin
Copy link
Owner

Add a -detach argument to the CLI to flag the application must be detached from the current terminal and run in background. User should be able to redirect stdout and stdin to log files for auditing purposes

@davrodpin davrodpin added Hacktoberfest enhancement New feature or request labels Oct 15, 2018
@davrodpin davrodpin changed the title New Feature: run mole in background mode New feature: run mole in background mode Oct 15, 2018
@BenMcH
Copy link

BenMcH commented Oct 16, 2018

This will be a chore to implement. If someone wanted to take this on, you could look at utilizing https://github.com/sevlyar/go-daemon

@davrodpin
Copy link
Owner Author

Another good resource about support for daemonize in Go: golang/go#227

@tidjungs
Copy link
Contributor

Can i take this ?
Do i have to implement flag to stop daemon process ?

@davrodpin
Copy link
Owner Author

Can i take this ?
Do i have to implement flag to stop daemon process ?

Sure! Thanks for considering contributing to the project, @tidjungs.

Having a command (-stop?) to stop a detached mole instance seems to be a good idea.

Let's assume we will have a flag name -detach to indicate the app should run in background mode and another one, -stop, to stop the app that is already running in background mole.
The latter flag would required an application identifier to be able to stop it, which would be relatively easy to identify if the user had started the app with -start, but I am unsure how to approach the other cases where there is no clear identifier.

One could propose that pid could be provided, but if the app required the user to fetch the pid from the list of processes, then the user could just use kill or something like that.

$ mole -start example1 -detach
INFO[0000] listening on local address                    local_address="127.0.0.1:52218"
$ mole -stop example1

$ mole -detach -remote :3306 -server my-server
INFO[0000] listening on local address local_address="127.0.0.1:52219"
$ mole -stop ???

@tidjungs
Copy link
Contributor

what about

$mole -detach -remote :3306 -server my-server
daemon is running on <alias_name> (maybe name generate with random hex)
stop daemon: $mole -stop <alias_name>

and Alias case

$mole -start example1 -detach
$mole -stop example1

What do you think ?

And I have no idea how to manage structure of pid, log file
what you think about -log=/path/to/log and default is "./"
inside have
pid_alias_name
log_alias_name

@davrodpin
Copy link
Owner Author

We're getting there... so, every detached mole instance will have an identifier associated with it and the identifier will be generated either from the alias name or random combination of characters.

Mole would store information about the detached instances under $HOME/.mole/instances.
Each detached instances would have its own directory under $HOME/.mole/instances named after its identifier and the specific instance directory would have a file named mole.pid to store the process identifier, pid, making easier to save/retrieve it.

Examples:

$ mole -start example1 -detach
$ tree $HOME/.mole
$ tree ~/.mole
$HOME/.mole
└── instances
    └── example1
        └── pid
$ mole -stop example1 
$ tree $HOME/.mole
tree ~/.mole
$HOME/.mole
└── instances
$ mole -detach -remote :3306 -server my-server
mole is running under the alias 10df414a.
Execute "mole -stop 10df414a" if you like to stop it at any time
$ tree $HOME/.mole
$ tree ~/.mole
$HOME/.mole
└── instances
    └── 10df414a
        └── pid
$ mole -stop 10df414a
$ tree $HOME/.mole
tree ~/.mole
$HOME/.mole
└── instances

I wouldn't care about handling output redirection right now. The user can always use >, >>, etc. to achieve that.

@tidjungs
Copy link
Contributor

ok I got it

@davrodpin
Copy link
Owner Author

PR #35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants