mikeperry-tor / vanguards

Vanguards help guard you from getting vanned...
MIT License
218 stars 23 forks source link

rc script #89

Open nyxnor opened 2 years ago

nyxnor commented 2 years ago

I am trying to run Vanguards and restart/start/stop as a daemon on OpenBSD. Currently it is failing. File inside /etc/rc.d/vanguards mod 755 root:wheel

  GNU nano 5.8                                                         /etc/rc.d/vanguards                                                                    
#!/bin/ksh
#
# $OnionJuggler: Vanguards,v ${vanguards_version} $(date +%Y/%m/%d' '%H:%M:%S) rpe Exp $

tor_data_dir="/var/tor"
tor_conf_dir="/etc/tor"
daemon="${tor_data_dir}/vanguards/src/vanguards.py"
daemon_flags="--config ${tor_conf_dir}/vanguards.conf"
. /etc/rc.d/rc.subr

rc_reload=NO

rcexec="su -fl -c ${daemon_class} -s /usr/local/bin/python3 ${daemon_user} -c"

rc_start() {
       ${rcexec} "${daemon_logger:+set -o pipefail; }${daemon} ${daemon_flags}${daemon_logger:+ 2>&1 |
               logger -ip ${daemon_logger} -t ${_name}}"
}

rc_cmd $1

the error: probably because it is a python script, not shellscript

bsdm64$ doas rcctl restart -d vanguards                                                                                                                      
rcctl: service -d does not exist
bsdm64$ doas rcctl -d restart vanguards 
doing _rc_parse_conf
doing _rc_quirks
vanguards_flags empty, using default >--config /etc/tor/vanguards.conf<
doing _rc_parse_conf /var/run/rc.d/vanguards
doing _rc_quirks
doing _rc_parse_conf
doing _rc_quirks
vanguards_flags empty, using default >--config /etc/tor/vanguards.conf<
doing _rc_parse_conf /var/run/rc.d/vanguards
doing _rc_quirks
doing rc_check
doing _rc_parse_conf
doing _rc_quirks
vanguards_flags empty, using default >--config /etc/tor/vanguards.conf<
doing rc_check
vanguards
doing rc_start
doing _rc_wait start
doing rc_check
  File "<string>", line 1
    /var/tor/vanguards/src/vanguards.py --config /etc/tor/vanguards.conf
    ^
SyntaxError: invalid syntax
doing _rc_rm_runfile
(failed)

I have to reassign rcexec because it expects /bin/sh, which will faill of course. Alternatively, I could include a start script inside vanguards repository for calling the python interpreter.

nyxnor commented 2 years ago

Now if I do /etc/rc.d/vanguards

#!/bin/ksh
#
# $OnionJuggler: Vanguards,v ${vanguards_version} $(date +%Y/%m/%d' '%H:%M:%S) rpe Exp $

daemon="/usr/local/bin/vanguards"
. /etc/rc.d/rc.subr

rc_reload=NO

rc_cmd $1

and in /usr/local/bin/vanguards

#!/usr/bin/env sh

python3 /var/tor/vanguards/src/vanguards.py --config /etc/tor/vanguards.conf --logfile /var/log/vanguards

I see on /var/log/vanguards:

NOTICE[Tue Dec 21 2021]: Vanguards 0.4.0-dev1 connected to Tor 0.4.6.7 using stem 1.8.0
NOTICE[Tue Dec 21 2021]: Vanguards successfilly applied config options from /etc/tor/vanguards.conf
NOTICE[Tue Dec 21 2021]: Connected to Tor via 127.0.0.1 control port
NOTICE[Tue Dec 21 2021]: Connected to Tor via 127.0.0.1 control port
NOTICE[Tue Dec 21 2021]: Vanguards 0.4.0-dev1 connected to Tor 0.4.6.7 using stem 1.8.0
NOTICE[Tue Dec 21 2021]: Vanguards 0.4.0-dev1 connected to Tor 0.4.6.7 using stem 1.8.0

Fortunately it does not quit after rc fails, but it means it is connecting to vanguards at least but not working as an rc script

$ doas rcctl -d restart vanguards
doing _rc_parse_conf
doing _rc_quirks
vanguards_flags empty, using default ><
doing _rc_parse_conf /var/run/rc.d/vanguards
doing _rc_quirks
doing _rc_parse_conf
doing _rc_quirks
vanguards_flags empty, using default ><
doing _rc_parse_conf /var/run/rc.d/vanguards
doing _rc_quirks
doing rc_check
doing _rc_parse_conf
doing _rc_quirks
vanguards_flags empty, using default ><
doing rc_check
vanguards
doing rc_start
doing _rc_wait start
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
doing rc_check
Alarm clock 
/etc/rc.d/vanguards: kill: 95135: No such process
doing _rc_write_runfile
(timeout)
$ doas rcctl -d check vanguards   
doing _rc_parse_conf
doing _rc_quirks
vanguards_flags empty, using default ><
doing _rc_parse_conf /var/run/rc.d/vanguards
doing _rc_quirks
vanguards
doing rc_check
(failed)