Skip to content

Commit f4fa32a

Browse files
committed
version 0.2.9
1 parent af9e067 commit f4fa32a

File tree

5 files changed

+192
-2
lines changed

5 files changed

+192
-2
lines changed

Changes

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ Revision history for Sparky
22

33
{{$NEXT}}
44

5+
0.2.9 2025-02-20T14:50:00Z
6+
7+
- Make sparman part of
8+
Sparky distribution
9+
10+
- Comment some noisy logs
11+
512
0.2.8 2024-07-14T12:30:00Z
613

714
- Migrate ci pipeline to Sparky

META6.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,5 @@
4242
},
4343
"tags" : [ ],
4444
"test-depends" : [ ],
45-
"version" : "0.2.8"
45+
"version" : "0.2.9"
4646
}

bin/sparman.raku

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
sub MAIN(
2+
Str $comp,
3+
Str $action,
4+
Bool :$verbose? = False,
5+
Str :$base?,
6+
Str :$env?,
7+
) {
8+
9+
say "Execute $action on $comp ...";
10+
11+
die "unknown component" unless $comp ~~ /^^ (worker|worker_ui) $$/;
12+
13+
my $c = _get_conf();
14+
my $vars = $env ?? $env.split(/","/).map({"export $_"}).join("\n") !! "";
15+
16+
if $comp eq "worker_ui" {
17+
if ! $c<worker><base> and $action eq "start" {
18+
say "worker ui base dir not found, tell me where to look it up:";
19+
say "sparman.raku --base /path/to/basedir worker_ui conf";
20+
exit(1)
21+
}
22+
if $action eq "start" {
23+
my $cmd = q[
24+
set -e
25+
pid=$(ps uax|grep "raku bin/sparky-web.raku"|grep -v grep | awk '{ print $2 }')
26+
if test -z $pid; then ] ~
27+
qq[\ncd {$c<worker><base>}\n] ~
28+
q[mkdir -p ~/.sparky ] ~
29+
qq[\n$vars\n] ~
30+
q[nohup raku bin/sparky-web.raku 1>~/.sparky/sparky-web.log 2>&1 < /dev/null &
31+
echo "run [OK]"
32+
else
33+
echo "already running pid=$pid ..."
34+
fi
35+
];
36+
say $cmd if $verbose;
37+
shell $cmd;
38+
} elsif $action eq "stop" {
39+
my $cmd = q[
40+
set -e
41+
pid=$(ps uax|grep "raku bin/sparky-web.raku"|grep -v grep | awk '{ print $2 }')
42+
if test -z $pid; then
43+
echo "already stopped"
44+
else
45+
echo "kill $pid ..."
46+
kill $pid
47+
echo "stop [OK] | pid=$pid"
48+
fi
49+
];
50+
say $cmd if $verbose;
51+
shell $cmd;
52+
} elsif $action eq "conf" {
53+
if $base {
54+
$c<worker><base> = $base;
55+
_update_conf($c);
56+
}
57+
} elsif $action eq "status" {
58+
my $cmd = q[
59+
set -e
60+
pid=$(ps uax|grep "raku bin/sparky-web.raku"|grep -v grep | awk '{ print $2 }')
61+
if test -z $pid; then
62+
echo "stop [OK]"
63+
else
64+
echo "run [OK] | pid=$pid"
65+
fi
66+
];
67+
say $cmd if $verbose;
68+
shell $cmd;
69+
} else {
70+
die "unknown action"
71+
}
72+
}
73+
if $comp eq "worker" {
74+
if $action eq "start" {
75+
my $cmd = q[
76+
set -e
77+
pid=$(ps uax|grep bin/sparkyd|grep rakudo|grep -v grep | awk '{ print $2 }')
78+
if test -z $pid; then
79+
mkdir -p ~/.sparky/] ~
80+
qq[\n$vars\n] ~
81+
q[nohup sparkyd 1>~/.sparky/sparkyd.log 2>&1 < /dev/null &
82+
echo "run [OK]"
83+
else
84+
echo "already running pid=$pid ..."
85+
fi
86+
];
87+
say $cmd if $verbose;
88+
shell $cmd;
89+
} elsif $action eq "stop" {
90+
my $cmd = q[
91+
set -e
92+
pid=$(ps uax|grep bin/sparkyd|grep rakudo|grep -v grep | awk '{ print $2 }')
93+
if test -z $pid; then
94+
echo "already stopped"
95+
else
96+
echo "kill $pid ..."
97+
kill $pid
98+
echo "stop [OK] | pid=$pid"
99+
fi
100+
];
101+
say $cmd if $verbose;
102+
shell $cmd;
103+
} elsif $action eq "status" {
104+
my $cmd = q[
105+
set -e
106+
pid=$(ps uax|grep bin/sparkyd|grep rakudo|grep -v grep | awk '{ print $2 }')
107+
if test -z $pid; then
108+
echo "stop [OK]"
109+
else
110+
echo "run [OK] | pid=$pid"
111+
fi
112+
];
113+
say $cmd if $verbose;
114+
shell $cmd;
115+
} else {
116+
die "unknown action"
117+
}
118+
}
119+
120+
}
121+
122+
sub _get_conf {
123+
if "{%*ENV<HOME>}/.sparky/conf.raku".IO ~~ :e {
124+
EVALFILE "{%*ENV<HOME>}/.sparky/conf.raku"
125+
} else {
126+
return {}
127+
}
128+
}
129+
130+
sub _update_conf (%c) {
131+
mkdir "{%*ENV<HOME>}/.sparky/";
132+
say "update {%*ENV<HOME>}/.sparky/conf.raku ...";
133+
"{%*ENV<HOME>}/.sparky/conf.raku".IO.spurt(%c.perl)
134+
}

docs/sparman.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Sparman
2+
3+
Sparman is a cli to run and configure Sparky components:
4+
5+
- sparkyd (aka sparky worker)
6+
7+
- web UI (aka sparky worker UI)
8+
9+
# API
10+
11+
## Sparky Worker
12+
13+
Sparky worker is a background process performing all SparrowCI tasks execution
14+
15+
```bash
16+
sparman.raku worker start
17+
sparman.raku worker stop
18+
sparman.raku worker status
19+
```
20+
21+
## Sparky Worker UI
22+
23+
Sparky worker UI allows to read worker reports and manage worker jobs. This
24+
is intended for SparrowCI operations people
25+
26+
```bash
27+
sparman.raku worker_ui start
28+
sparman.raku worker_ui stop
29+
sparman.raku worker_ui status
30+
```
31+
32+
## Pass environment variables
33+
34+
To pass environmental variables to services, use `--env var=val,var2=val ...` notation.
35+
36+
For example, to set worker polling timeout to 10 seconds and set SPARROWCI_HOST:
37+
38+
```bash
39+
sparman.raku --env SPARKY_TIMEOUT=10,SPARROWCI_HOST=http://127.0.0.1:2222 worker start
40+
```
41+
42+
## Logs
43+
44+
Logs are available at the following locations:
45+
46+
Sparky Woker UI - `~/.sparky/sparky-web.log`
47+
48+
Sparky Woker - `~/.sparky/sparkyd.log `
49+

lib/Sparky.rakumod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use v6;
22

3-
unit module Sparky:ver<0.2.8>;
3+
unit module Sparky:ver<0.2.9>;
44
use YAMLish;
55
use DBIish;
66
use Time::Crontab;

0 commit comments

Comments
 (0)