diff options
author | nous <archnous@users.noreply.github.com> | 2017-12-08 23:54:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-08 23:54:35 +0200 |
commit | 53c3fd2ff7a839de1535a3168584a7f36b4a02c6 (patch) | |
tree | 8ae901ad8c780de7b173b0c5ec7527a309655737 | |
parent | ac599df75fbfd02d6f7d1108d554810e8284d982 (diff) | |
download | initify-53c3fd2ff7a839de1535a3168584a7f36b4a02c6.tar.lz initify-53c3fd2ff7a839de1535a3168584a7f36b4a02c6.tar.xz initify-53c3fd2ff7a839de1535a3168584a7f36b4a02c6.zip |
Guess script name from systemd service filename
Also, write straight to file instead of stdout
-rw-r--r-- | initify.pl | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -1,6 +1,9 @@ +#!/usr/bin/perl # (c) goose121, 2017 # Released under the MIT license +use warnings; +#use strict; use v5.10.1; use feature "switch"; my $type = "simple"; @@ -8,6 +11,7 @@ my @cmds_start = (); my @cmds_stop = (); my $pidfile = ""; my $desc = ""; +(my $service=$ARGV[0])=~s/\.service//; while(<>) { #s/\s*|\s*$//g; # Trim whitespace @@ -38,7 +42,7 @@ while(<>) { } } if (m/^Description=(.*)/) { - $desc = $1 + $desc = $1 } } @@ -52,13 +56,17 @@ 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="(fill in)" +name="$service" description="$desc" EOF + +close FH; |