Skip to content

Instantly share code, notes, and snippets.

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC7LeTtPBluCl0jSWtrvkn5MivdXIatdvrVhntWq5v6ZOfngO93W1TTCUNEbF0I+Rts9yvnsB6fRvG4SUeS/37Wu/TQQG/QTZ+eBb7whdZnf/0rc2Gon6RlKjr93GDZpnxAoRiZoz1JyMKve388TX7yqPNGqcxBZKFuWH37XZNXmy9jVvJ9JzuamyzGkiSPJ7Kzae1/ciO23uyUj7hilHdAb6Ryk7YWUedv5jfoyaE+DbYX5uj4LszzuI+rF/f+mdqh2jJH85YE1Ydf7RdbDvlE+elP6RQVpnmR0zsGh1yxNoYjSI9kQLmGy8HUleHRGGV0+evzy2elFqaYUqLxD5jp wkharold@Wards-MacBook-Pro.local
@wkharold
wkharold / msgrelay.go
Created December 4, 2013 04:54
Relay a message from a client to all listeners
package main
import (
"flag"
"fmt"
"net"
"os"
"sync"
)
s := srv.NewFileSrv(root)
s.Dotu = true
if *fldebug {
s.Debuglevel = 1
}
s.Start(s)
if err := s.StartNetListener("tcp", *flfsaddr); err != nil {
glog.Errorf("listener failed to start (%v)", err)
os.Exit(1)
@wkharold
wkharold / gist:9861636
Last active August 29, 2015 13:57
mkjobfs
/*** jobd.go ***/
// mkjobfs creates the static portion of the jobd file hierarchy: the 'clone'
// file, and the 'jobs' directory at the root of the hierarchy.
func mkjobfs() (*srv.File, error) {
var err error
user := p.OsUsers.Uid2User(os.Geteuid())
root := new(srv.File)
func main() {
// argument handling and initialization
root, err := mkjobfs()
if err != nil {
os.Exit(1)
}
// job database management
/*** clone.go ***/
type clonefile struct {
srv.File
}
// Write handles writes to the clone file by attempting to parse the data being
// written into a job definition and if successful adding the corresponding job
// to the jobs directory.
func (k *clonefile) Write(fid *srv.FFid, data []byte, offset uint64) (int, error) {
glog.V(4).Infof("Entering clonefile.Write(%v, %v, %v)", fid, data, offset)
/*** job.go ***/
type jobdef struct {
name string
schedule string
cmd string
state string
}
type jobreader func() []byte
type jobwriter func([]byte) (int, error)
/*** job.go ***/
// Read handles read operations on a jobfile using its associated reader.
func (jf jobfile) Read(fid *srv.FFid, buf []byte, offset uint64) (int, error) {
glog.V(4).Infof("Entering jobfile.Read(%v, %v, %)", fid, buf, offset)
defer glog.V(4).Infof("Exiting jobfile.Read(%v, %v, %v)", fid, buf, offset)
cont := jf.reader()
if offset > uint64(len(cont)) {
return 0, nil
/*** job.go ***/
// run executes the command associated with a job according to its schedule and
// records the results until it is told to stop.
func (j *job) run() {
j.history.Value = fmt.Sprintf("%s:started\n", time.Now().String())
j.history = j.history.Next()
for {
now := time.Now()
e, err := cronexpr.Parse(j.defn.schedule)
if err != nil {
@wkharold
wkharold / etcdcmds.txt
Created December 16, 2014 20:50
Issue getting etcdctl to talk to non-local etcd
core@db01 ~ $ ping 10.240.169.79
PING 10.240.169.79 (10.240.169.79) 56(84) bytes of data.
64 bytes from 10.240.169.79: icmp_seq=1 ttl=64 time=0.849 ms
64 bytes from 10.240.169.79: icmp_seq=2 ttl=64 time=0.404 ms
^C
--- 10.240.169.79 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.404/0.626/0.849/0.223 ms
core@db01 ~ $ export ETCDCTL_PEERS="http://10.240.169.79:4001"
core@db01 ~ $ etcdctl --debug set /tmp/foo "bar"