add service file and support in the program

This commit is contained in:
Solene Rapenne 2022-03-14 18:34:08 +01:00
parent 7a11809dd0
commit 5ea3cb0053
3 changed files with 33 additions and 2 deletions

View File

@ -9,13 +9,14 @@ use Getopt::Std;;
use Data::Dumper;
use File::HomeDir;
use File::Path qw(make_path);
use Sys::Syslog qw(:standard :macros);
use 5.010;
my $verbose = 0;
# display usage and quit
sub usage {
say "usage: $0 [-v] -d directory -u user (start|stop|restart)";
say "usage: $0 [-v] -d directory -u user (start|stop|restart|status)";
say " $0 -t conf";
exit 1;
}
@ -24,12 +25,14 @@ sub usage {
sub saydebug {
my $msg = shift;
say STDERR "DEBUG: $msg" if $verbose;
syslog(LOG_INFO, "$msg");
}
# display a message before exiting with status 2
sub trap_error {
my $msg = shift;
say STDERR "FATAL: $msg";
syslog(LOG_ERR, "$msg");
exit 2;
}
@ -228,6 +231,8 @@ sub main {
$start = 1;
}elsif( $ARGV[0] eq "stop" ) {
$stop = 1;
}elsif( $ARGV[0] eq "status" ) {
exit ! is_mounted($impermanence_home);
}else{
usage();
}
@ -246,4 +251,6 @@ sub main {
}
main()
openlog("impermanence", 'ndelay', LOG_DAEMON);
main();
closelog();

22
openbsd/impermanence.rc Executable file
View File

@ -0,0 +1,22 @@
#!/bin/ksh
#
daemon="/usr/local/bin/impermanence"
. /etc/rc.d/rc.subr
rc_reload=NO
rc_start() {
$daemon ${daemon_flags} start
}
rc_stop() {
$daemon ${daemon_flags} stop
}
rc_check() {
$daemon ${daemon_flags} status
}
rc_cmd $1

2
tests/errored.yml Normal file
View File

@ -0,0 +1,2 @@
key:
value