Trying to convert RHEL6 init script to systemd

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
4
down vote

favorite
1












I currently have an init script on a RHEL 6.x box that is used to start various license servers for an engineering group.



Each vendor has their own processes, env variables and other specifics to start/stop license servers, so over the years I have created a START, STOP, STAT script for each application that map the vendor specific stuff into a standard for our site. This allowed me to create the following generic init script that I could soft link to any application via a link in /etc/sysconfig/init.d:



#!/bin/bash
#
# START/STOP/STAT license servers
#
# chkconfig: 345 95 05
# description: Startup/Shutdown license servers

#####################################
# Who/When/Where
#
WHO=`who am i`
WHEN=`date`
WHERE=`hostname | cut -f1 -d "."`

#####################################
# Figure out how we were called
#
APPNAME=`basename $0 | cut -f2 -d "_"` ; export APPNAME
SERVICELOG="/license/$APPNAME/logs/service.log" ; export SERVICELOG

echo "/etc/init.d/ License Script was ran at: $WHEN app was: $APPNAME command was: $1" >> $SERVICELOG

#################################################
# Time to call App Specific Executable
#
case "$1" in
start) su - licadmin /license/$APPNAME/scripts/START
echo "$APPNAME Daemon Started $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
stop)
su - licadmin /license/$APPNAME/scripts/STOP
echo "$APPNAME Daemon Stopped $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
status)
su - licadmin /license/$APPNAME/scripts/STAT
;;
reload|restart)
$0 stop
$0 start
echo "$APPNAME Daemon Restarted $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
*)
echo "Usage: $0 stop"
exit 1
;;
esac
exit 0
##########################################################################
#EOF(lic_init)


I've looked into the documentation for systemd and I am really struggling on how to preserve my standard since a lot of what I do "seems" to be native to systemd (start/stop/stat) and I don't want to just have a new systemd service that just calls my Bash script.



Any ideas on how to handle my conversion?







share|improve this question





















  • bolting a sysv script into systemd is not unknown, see for example /usr/lib/systemd/system/libvirt-guests.service on Centos 7 (libvirt-client RPM)
    – thrig
    Jul 18 at 16:59
















up vote
4
down vote

favorite
1












I currently have an init script on a RHEL 6.x box that is used to start various license servers for an engineering group.



Each vendor has their own processes, env variables and other specifics to start/stop license servers, so over the years I have created a START, STOP, STAT script for each application that map the vendor specific stuff into a standard for our site. This allowed me to create the following generic init script that I could soft link to any application via a link in /etc/sysconfig/init.d:



#!/bin/bash
#
# START/STOP/STAT license servers
#
# chkconfig: 345 95 05
# description: Startup/Shutdown license servers

#####################################
# Who/When/Where
#
WHO=`who am i`
WHEN=`date`
WHERE=`hostname | cut -f1 -d "."`

#####################################
# Figure out how we were called
#
APPNAME=`basename $0 | cut -f2 -d "_"` ; export APPNAME
SERVICELOG="/license/$APPNAME/logs/service.log" ; export SERVICELOG

echo "/etc/init.d/ License Script was ran at: $WHEN app was: $APPNAME command was: $1" >> $SERVICELOG

#################################################
# Time to call App Specific Executable
#
case "$1" in
start) su - licadmin /license/$APPNAME/scripts/START
echo "$APPNAME Daemon Started $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
stop)
su - licadmin /license/$APPNAME/scripts/STOP
echo "$APPNAME Daemon Stopped $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
status)
su - licadmin /license/$APPNAME/scripts/STAT
;;
reload|restart)
$0 stop
$0 start
echo "$APPNAME Daemon Restarted $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
*)
echo "Usage: $0 stop"
exit 1
;;
esac
exit 0
##########################################################################
#EOF(lic_init)


I've looked into the documentation for systemd and I am really struggling on how to preserve my standard since a lot of what I do "seems" to be native to systemd (start/stop/stat) and I don't want to just have a new systemd service that just calls my Bash script.



Any ideas on how to handle my conversion?







share|improve this question





















  • bolting a sysv script into systemd is not unknown, see for example /usr/lib/systemd/system/libvirt-guests.service on Centos 7 (libvirt-client RPM)
    – thrig
    Jul 18 at 16:59












up vote
4
down vote

favorite
1









up vote
4
down vote

favorite
1






1





I currently have an init script on a RHEL 6.x box that is used to start various license servers for an engineering group.



Each vendor has their own processes, env variables and other specifics to start/stop license servers, so over the years I have created a START, STOP, STAT script for each application that map the vendor specific stuff into a standard for our site. This allowed me to create the following generic init script that I could soft link to any application via a link in /etc/sysconfig/init.d:



#!/bin/bash
#
# START/STOP/STAT license servers
#
# chkconfig: 345 95 05
# description: Startup/Shutdown license servers

#####################################
# Who/When/Where
#
WHO=`who am i`
WHEN=`date`
WHERE=`hostname | cut -f1 -d "."`

#####################################
# Figure out how we were called
#
APPNAME=`basename $0 | cut -f2 -d "_"` ; export APPNAME
SERVICELOG="/license/$APPNAME/logs/service.log" ; export SERVICELOG

echo "/etc/init.d/ License Script was ran at: $WHEN app was: $APPNAME command was: $1" >> $SERVICELOG

#################################################
# Time to call App Specific Executable
#
case "$1" in
start) su - licadmin /license/$APPNAME/scripts/START
echo "$APPNAME Daemon Started $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
stop)
su - licadmin /license/$APPNAME/scripts/STOP
echo "$APPNAME Daemon Stopped $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
status)
su - licadmin /license/$APPNAME/scripts/STAT
;;
reload|restart)
$0 stop
$0 start
echo "$APPNAME Daemon Restarted $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
*)
echo "Usage: $0 stop"
exit 1
;;
esac
exit 0
##########################################################################
#EOF(lic_init)


I've looked into the documentation for systemd and I am really struggling on how to preserve my standard since a lot of what I do "seems" to be native to systemd (start/stop/stat) and I don't want to just have a new systemd service that just calls my Bash script.



Any ideas on how to handle my conversion?







share|improve this question













I currently have an init script on a RHEL 6.x box that is used to start various license servers for an engineering group.



Each vendor has their own processes, env variables and other specifics to start/stop license servers, so over the years I have created a START, STOP, STAT script for each application that map the vendor specific stuff into a standard for our site. This allowed me to create the following generic init script that I could soft link to any application via a link in /etc/sysconfig/init.d:



#!/bin/bash
#
# START/STOP/STAT license servers
#
# chkconfig: 345 95 05
# description: Startup/Shutdown license servers

#####################################
# Who/When/Where
#
WHO=`who am i`
WHEN=`date`
WHERE=`hostname | cut -f1 -d "."`

#####################################
# Figure out how we were called
#
APPNAME=`basename $0 | cut -f2 -d "_"` ; export APPNAME
SERVICELOG="/license/$APPNAME/logs/service.log" ; export SERVICELOG

echo "/etc/init.d/ License Script was ran at: $WHEN app was: $APPNAME command was: $1" >> $SERVICELOG

#################################################
# Time to call App Specific Executable
#
case "$1" in
start) su - licadmin /license/$APPNAME/scripts/START
echo "$APPNAME Daemon Started $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
stop)
su - licadmin /license/$APPNAME/scripts/STOP
echo "$APPNAME Daemon Stopped $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
status)
su - licadmin /license/$APPNAME/scripts/STAT
;;
reload|restart)
$0 stop
$0 start
echo "$APPNAME Daemon Restarted $WHEN by $WHO on $WHERE" >> $SERVICELOG
;;
*)
echo "Usage: $0 stop"
exit 1
;;
esac
exit 0
##########################################################################
#EOF(lic_init)


I've looked into the documentation for systemd and I am really struggling on how to preserve my standard since a lot of what I do "seems" to be native to systemd (start/stop/stat) and I don't want to just have a new systemd service that just calls my Bash script.



Any ideas on how to handle my conversion?









share|improve this question












share|improve this question




share|improve this question








edited Jul 18 at 16:49









slm♦

232k65479649




232k65479649









asked Jul 18 at 16:47









bj2348

212




212











  • bolting a sysv script into systemd is not unknown, see for example /usr/lib/systemd/system/libvirt-guests.service on Centos 7 (libvirt-client RPM)
    – thrig
    Jul 18 at 16:59
















  • bolting a sysv script into systemd is not unknown, see for example /usr/lib/systemd/system/libvirt-guests.service on Centos 7 (libvirt-client RPM)
    – thrig
    Jul 18 at 16:59















bolting a sysv script into systemd is not unknown, see for example /usr/lib/systemd/system/libvirt-guests.service on Centos 7 (libvirt-client RPM)
– thrig
Jul 18 at 16:59




bolting a sysv script into systemd is not unknown, see for example /usr/lib/systemd/system/libvirt-guests.service on Centos 7 (libvirt-client RPM)
– thrig
Jul 18 at 16:59










1 Answer
1






active

oldest

votes

















up vote
5
down vote













Let's break it down into smaller parts:



  • WHO/WHEN/WHERE are handled by systemd's journal. You can query the journal for any unit, e.g. journalctl -u $APPNAME.service, so these are not necessary here and could be removed.

  • Likewise, $SERVICELOG can be replaced by the systemd journal. No more concerns about managing your own log rotation.

  • Custom "status" commands are supported directly by systemd. Instead, you can use systemctl status for a standardized status output. If you really want a custom status command, that would be implemented as a separate systemd service.

  • What's left is that you have multiple services that you want to stop and start the same way, by the same user. systemd template units are designed to solve that problem. You can create a single template unit, and then for each app, you can create an instance of that that template: systemctl start licensedapps@someapp





share|improve this answer























    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457053%2ftrying-to-convert-rhel6-init-script-to-systemd%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    5
    down vote













    Let's break it down into smaller parts:



    • WHO/WHEN/WHERE are handled by systemd's journal. You can query the journal for any unit, e.g. journalctl -u $APPNAME.service, so these are not necessary here and could be removed.

    • Likewise, $SERVICELOG can be replaced by the systemd journal. No more concerns about managing your own log rotation.

    • Custom "status" commands are supported directly by systemd. Instead, you can use systemctl status for a standardized status output. If you really want a custom status command, that would be implemented as a separate systemd service.

    • What's left is that you have multiple services that you want to stop and start the same way, by the same user. systemd template units are designed to solve that problem. You can create a single template unit, and then for each app, you can create an instance of that that template: systemctl start licensedapps@someapp





    share|improve this answer



























      up vote
      5
      down vote













      Let's break it down into smaller parts:



      • WHO/WHEN/WHERE are handled by systemd's journal. You can query the journal for any unit, e.g. journalctl -u $APPNAME.service, so these are not necessary here and could be removed.

      • Likewise, $SERVICELOG can be replaced by the systemd journal. No more concerns about managing your own log rotation.

      • Custom "status" commands are supported directly by systemd. Instead, you can use systemctl status for a standardized status output. If you really want a custom status command, that would be implemented as a separate systemd service.

      • What's left is that you have multiple services that you want to stop and start the same way, by the same user. systemd template units are designed to solve that problem. You can create a single template unit, and then for each app, you can create an instance of that that template: systemctl start licensedapps@someapp





      share|improve this answer

























        up vote
        5
        down vote










        up vote
        5
        down vote









        Let's break it down into smaller parts:



        • WHO/WHEN/WHERE are handled by systemd's journal. You can query the journal for any unit, e.g. journalctl -u $APPNAME.service, so these are not necessary here and could be removed.

        • Likewise, $SERVICELOG can be replaced by the systemd journal. No more concerns about managing your own log rotation.

        • Custom "status" commands are supported directly by systemd. Instead, you can use systemctl status for a standardized status output. If you really want a custom status command, that would be implemented as a separate systemd service.

        • What's left is that you have multiple services that you want to stop and start the same way, by the same user. systemd template units are designed to solve that problem. You can create a single template unit, and then for each app, you can create an instance of that that template: systemctl start licensedapps@someapp





        share|improve this answer















        Let's break it down into smaller parts:



        • WHO/WHEN/WHERE are handled by systemd's journal. You can query the journal for any unit, e.g. journalctl -u $APPNAME.service, so these are not necessary here and could be removed.

        • Likewise, $SERVICELOG can be replaced by the systemd journal. No more concerns about managing your own log rotation.

        • Custom "status" commands are supported directly by systemd. Instead, you can use systemctl status for a standardized status output. If you really want a custom status command, that would be implemented as a separate systemd service.

        • What's left is that you have multiple services that you want to stop and start the same way, by the same user. systemd template units are designed to solve that problem. You can create a single template unit, and then for each app, you can create an instance of that that template: systemctl start licensedapps@someapp






        share|improve this answer















        share|improve this answer



        share|improve this answer








        edited Jul 22 at 13:45









        Jeff Schaller

        30.8k846104




        30.8k846104











        answered Jul 18 at 17:08









        Mark Stosberg

        3,4191023




        3,4191023






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f457053%2ftrying-to-convert-rhel6-init-script-to-systemd%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay