Re: [go-nuts] Single instance of program

2016-10-07 Thread Manlio Perillo
Il giorno giovedì 6 ottobre 2016 18:40:42 UTC+2, Ian Lance Taylor ha 
scritto:
>
> On Thu, Oct 6, 2016 at 8:28 AM, Manlio Perillo  > wrote: 
> > Il giorno giovedì 6 ottobre 2016 03:13:32 UTC+2, Dave Cheney ha scritto: 
> >> 
> >> Stick an @ at the start of the file name, or the socket will remain on 
> >> disk after the process has exited. 
> > 
> > 
> > According to http://man7.org/linux/man-pages/man7/unix.7.html, on Linux 
> an 
> > abstract socket address is specified by setting the first character to 
> \0. 
> > Is the use of @ supported by the Go stdlib or by the Linux kernel? 
>
> It's supported by the Go standard library, but it's a standard 
> convention.  For example, it's how abstract sockets are displayed by 
> netstat. 
>
>
However you can not create an abstract socket if the first character is @ 
instead of \0.
This only works with Go.  It does not work with Python, as an example.

IMHO, this should be documented.


Manlio 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-06 Thread Ian Lance Taylor
On Thu, Oct 6, 2016 at 8:28 AM, Manlio Perillo  wrote:
> Il giorno giovedì 6 ottobre 2016 03:13:32 UTC+2, Dave Cheney ha scritto:
>>
>> Stick an @ at the start of the file name, or the socket will remain on
>> disk after the process has exited.
>
>
> According to http://man7.org/linux/man-pages/man7/unix.7.html, on Linux an
> abstract socket address is specified by setting the first character to \0.
> Is the use of @ supported by the Go stdlib or by the Linux kernel?

It's supported by the Go standard library, but it's a standard
convention.  For example, it's how abstract sockets are displayed by
netstat.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-06 Thread Manlio Perillo
Il giorno giovedì 6 ottobre 2016 03:13:32 UTC+2, Dave Cheney ha scritto:
>
> Stick an @ at the start of the file name, or the socket will remain on 
> disk after the process has exited.


According to http://man7.org/linux/man-pages/man7/unix.7.html, on Linux an 
abstract socket address is specified by setting the first character to \0.
Is the use of @ supported by the Go stdlib or by the Linux kernel?


Thanks  Manlio

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-05 Thread Dave Cheney
It's a Linux thing, Google abstract domain socket. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-05 Thread Justin Israel
On Thu, Oct 6, 2016 at 2:13 PM Dave Cheney  wrote:

> Stick an @ at the start of the file name, or the socket will remain on
> disk after the process has exited
>

That's even better, and doesn't need to use the Remove().
I didn't see it documented about using @ for abstract socket. Did I miss
that somewhere?


> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-05 Thread Dave Cheney
Stick an @ at the start of the file name, or the socket will remain on disk 
after the process has exited. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-05 Thread Justin Israel
On Thu, Oct 6, 2016 at 3:15 AM dc0d  wrote:

> Nice! Seems working!
>
> I could not get Unix Domain Socket to work, since I expected an error on
> Listen or Accept but there were no errors.
>

Works fine when I tested it using this approach:

https://play.golang.org/p/A1C5BEIP2G

func main() {
_, err := net.ListenUnix("unix", {"/tmp/unixdomain", "unix"})
if err != nil {
panic("Already locked")
}
defer os.Remove("/tmp/unixdomain")
}

​

Justin


>
> On Wednesday, October 5, 2016 at 12:00:12 AM UTC+3:30, Ingo Oeser wrote:
>
> Are you looking for something like
> https://godoc.org/github.com/nightlyone/lockfile ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-05 Thread dc0d
Nice! Seems working!

I could not get Unix Domain Socket to work, since I expected an error on 
Listen or Accept but there were no errors.

On Wednesday, October 5, 2016 at 12:00:12 AM UTC+3:30, Ingo Oeser wrote:
>
> Are you looking for something like 
> https://godoc.org/github.com/nightlyone/lockfile ?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-04 Thread Justin Israel
A unix domain socket seems reliable since the OS will clean it up for you
regardless of how your application terminates.

Justin


On Wed, Oct 5, 2016 at 9:30 AM 'Ingo Oeser' via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> Are you looking for something like
> https://godoc.org/github.com/nightlyone/lockfile ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-04 Thread 'Ingo Oeser' via golang-nuts
Are you looking for something like 
https://godoc.org/github.com/nightlyone/lockfile ?

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-04 Thread Dave Cheney
Not directly, but a system wide mutex can be built on top of sysv 
semaphores, files on disk, or an open tcp or unix domain socket.

As this lock would be system wide, the main consideration is to ensure that 
it is _always_ unlocked when the owning process dies for any reason. Then 
that just leaves the problem of knowing _if_ the controlling process exited 
uncleanly, is the state it was protecting now corrupted. 

On Wednesday, 5 October 2016 06:55:47 UTC+11, dc0d wrote:
>
> I had the same question tonight! On Windows (using C#) I just create a 
> Named Mutex, which is system wide. One of values that it returns identifies 
> that if the mutex is already created by other instance, or it's the first 
> time it's being created on this system.
>
> Is there something similar on Linux?
>
> On Tuesday, July 19, 2011 at 3:55:45 PM UTC+4:30, Dave Cheney wrote:
>>
>> Hi. 
>>
>> This is a glib answer, but you should check the resource that your 
>> application requires to be a singleton.
>>
>> If that is a TCP port, then exit if you cannot bind. If it's a database, 
>> then use a lock file, etc. 
>>
>> This isn't a Go specific problem. If you can give some more details, 
>> maybe someone will be able to give a more specific answer. 
>>
>> Cheers
>>
>> Dave
>>
>> Sent from my iPhone
>>
>> On 19/07/2011, at 16:56, Ruslan Mezentsev  wrote:
>>
>> > Hello.
>> > How check only one instance of program is running? Use sockets,
>> > mutexes or pid files, or other?
>> > Thanks.
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [go-nuts] Single instance of program

2016-10-04 Thread dc0d
I had the same question tonight! On Windows (using C#) I just create a 
Named Mutex, which is system wide. One of values that it returns identifies 
that if the mutex is already created by other instance, or it's the first 
time it's being created on this system.

Is there something similar on Linux?

On Tuesday, July 19, 2011 at 3:55:45 PM UTC+4:30, Dave Cheney wrote:
>
> Hi. 
>
> This is a glib answer, but you should check the resource that your 
> application requires to be a singleton.
>
> If that is a TCP port, then exit if you cannot bind. If it's a database, 
> then use a lock file, etc. 
>
> This isn't a Go specific problem. If you can give some more details, maybe 
> someone will be able to give a more specific answer. 
>
> Cheers
>
> Dave
>
> Sent from my iPhone
>
> On 19/07/2011, at 16:56, Ruslan Mezentsev  > wrote:
>
> > Hello.
> > How check only one instance of program is running? Use sockets,
> > mutexes or pid files, or other?
> > Thanks.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.