|
| 1 | +# Template file for 'svc' |
| 2 | +pkgname=svc |
| 3 | +version=1.0.0 |
| 4 | +revision=1 |
| 5 | +build_style=gnu-makefile |
| 6 | +make_build_args="CC=clang" |
| 7 | +make_install_args="PREFIX=/usr" |
| 8 | +hostmakedepends="clang" |
| 9 | +short_desc="Small and simple reimplementation of sv for runit" |
| 10 | +maintainer="Haris <plavpxl@proton.me>" |
| 11 | +license="AGPL-3.0-only" |
| 12 | +homepage="https://github.com/WladimirBec/svc" |
| 13 | +distfiles="https://github.com/WladimirBec/svc/archive/refs/tags/${version}.tar.gz" |
| 14 | +checksum=da46f8a65a2c18aa8ca502a0988ac6129ee2e973555c54c9bca37dcd94690701 |
| 15 | + |
| 16 | +post_extract() { |
| 17 | + # remove -march=native so it builds portably |
| 18 | + vsed -i 's/-march=native//g' Makefile |
| 19 | + |
| 20 | + # use void CFLAGS |
| 21 | + # see: https://github.com/void-linux/void-packages/tree/master/common/build-profiles |
| 22 | + # see: https://github.com/void-linux/void-packages/blob/master/common/environment/configure/hardening.sh |
| 23 | + vsed -i 's/CFLAGS :=/CFLAGS +=/g' Makefile |
| 24 | +} |
| 25 | + |
| 26 | +post_install() { |
| 27 | + vlicense LICENSE |
| 28 | +} |
| 29 | + |
| 30 | +do_check() { |
| 31 | + msg_normal "Running internal test suite...\n" |
| 32 | + |
| 33 | + local BIN="./bld/svc" |
| 34 | + export SVDIR="${wrksrc}/tmp/run" |
| 35 | + export AVDIR="${wrksrc}/tmp/avail" |
| 36 | + |
| 37 | + # wipe previous test runs |
| 38 | + rm -rf "${wrksrc}/tmp" |
| 39 | + |
| 40 | + # fake service directory |
| 41 | + mkdir -p "$SVDIR/testsvc/supervise" |
| 42 | + mkdir -p "$AVDIR/linkme" |
| 43 | + |
| 44 | + # create mock runit control files |
| 45 | + mkfifo "$SVDIR/testsvc/supervise/control" |
| 46 | + |
| 47 | + # Initial state: RUNNING |
| 48 | + echo "run" > "$SVDIR/testsvc/supervise/stat" |
| 49 | + echo "12345" > "$SVDIR/testsvc/supervise/pid" |
| 50 | + |
| 51 | + # test 1 view status |
| 52 | + if ! $BIN view | grep -q "testsvc"; then |
| 53 | + msg_error "FAIL: 'view' command did not list the running service.\n" |
| 54 | + return 1 |
| 55 | + fi |
| 56 | + |
| 57 | + # test 2 symlinking |
| 58 | + $BIN link linkme |
| 59 | + if [ ! -L "$SVDIR/linkme" ]; then |
| 60 | + msg_error "FAIL: 'link' command failed to create symlink.\n" |
| 61 | + return 1 |
| 62 | + fi |
| 63 | + |
| 64 | + # test 3 sym un-linking |
| 65 | + $BIN unlink linkme |
| 66 | + if [ -e "$SVDIR/linkme" ]; then |
| 67 | + msg_error "FAIL: 'unlink' command failed to remove symlink.\n" |
| 68 | + return 1 |
| 69 | + fi |
| 70 | + |
| 71 | + # test 4 permanent down (and verify permissions) |
| 72 | + $BIN down testsvc |
| 73 | + if [ ! -f "$SVDIR/testsvc/down" ]; then |
| 74 | + msg_error "FAIL: 'down' command failed to create down file.\n" |
| 75 | + return 1 |
| 76 | + fi |
| 77 | + # verify permissions are 644 (rw-r--r--) |
| 78 | + if [ "$(stat -c "%a" "$SVDIR/testsvc/down")" != "644" ]; then |
| 79 | + msg_error "FAIL: 'down' file has wrong permissions (expected 644).\n" |
| 80 | + return 1 |
| 81 | + fi |
| 82 | + |
| 83 | + # test 5 permanent up |
| 84 | + $BIN up testsvc |
| 85 | + if [ -f "$SVDIR/testsvc/down" ]; then |
| 86 | + msg_error "FAIL: 'up' command failed to remove down file.\n" |
| 87 | + return 1 |
| 88 | + fi |
| 89 | + |
| 90 | + echo "down" > "$SVDIR/testsvc/supervise/stat" |
| 91 | + |
| 92 | + # test 6 start service |
| 93 | + cat "$SVDIR/testsvc/supervise/control" > "${wrksrc}/tmp/pipe_out" & |
| 94 | + local BG_PID=$! |
| 95 | + $BIN start testsvc |
| 96 | + wait $BG_PID |
| 97 | + if ! grep -q "u" "${wrksrc}/tmp/pipe_out"; then |
| 98 | + msg_error "FAIL: 'start' command did not send 'u' byte to control pipe.\n" |
| 99 | + return 1 |
| 100 | + fi |
| 101 | + |
| 102 | + echo "run" > "$SVDIR/testsvc/supervise/stat" |
| 103 | + |
| 104 | + # test 7 stop service |
| 105 | + cat "$SVDIR/testsvc/supervise/control" > "${wrksrc}/tmp/pipe_out" & |
| 106 | + local BG_PID=$! |
| 107 | + $BIN stop testsvc |
| 108 | + wait $BG_PID |
| 109 | + if ! grep -q "d" "${wrksrc}/tmp/pipe_out"; then |
| 110 | + msg_error "FAIL: 'stop' command did not send 'd' byte to control pipe.\n" |
| 111 | + return 1 |
| 112 | + fi |
| 113 | + |
| 114 | + msg_normal "All tests passed successfully.\n" |
| 115 | +} |
0 commit comments