diff options
Diffstat (limited to 'initify.pl')
-rwxr-xr-x | initify.pl | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -1,15 +1,20 @@ -#!/bin/env perl +#!/usr/bin/perl +# (c) goose121, 2017 +# Released under the MIT license + +use warnings; +#use strict; use v5.10.1; use feature "switch"; use Getopt::Long; use Pod::Usage; -my $name = "(fill in)"; my $type = "simple"; my @cmds_start = (); my @cmds_stop = (); my $pidfile = ""; my $desc = ""; +(my $service=$ARGV[0])=~s/\.service//; my %opt; GetOptions(\%opt, @@ -18,7 +23,7 @@ GetOptions(\%opt, pod2usage() if ($opt{help}); -$name = $opt{name} if (length $opt{name}); +$service = $opt{name} if (length $opt{name}); while(<>) { #s/\s*|\s*$//g; # Trim whitespace @@ -49,7 +54,7 @@ while(<>) { } } if (m/^Description=(.*)/) { - $desc = $1 + $desc = $1 } } @@ -63,17 +68,22 @@ map {my @sep = split(/ /, $_, 2); push(@cmd_argl, $sep[1]); } @cmds_start; -print <<"EOF"; +open(FH, '>', "$service") || die("Cannot create $service: $!\n"); + +print FH <<"EOF"; \#!/sbin/openrc-run command=$cmd_path[0] command_args="$cmd_argl[0]" pidfile=$pidfile -name="$name" +name="$service" description="$desc" EOF +close FH; + + __END__ =head1 NAME @@ -98,4 +108,4 @@ Set the name of the unit created =back -=cut
\ No newline at end of file +=cut |