Trying to convert RHEL6 init script to systemd
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
4
down vote
favorite
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?
bash shell-script systemd sysvinit
add a comment |Â
up vote
4
down vote
favorite
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?
bash shell-script systemd sysvinit
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
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
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?
bash shell-script systemd sysvinit
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?
bash shell-script systemd sysvinit
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
add a comment |Â
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
add a comment |Â
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 systemdservice
. - 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
add a comment |Â
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 systemdservice
. - 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
add a comment |Â
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 systemdservice
. - 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
add a comment |Â
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 systemdservice
. - 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
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 systemdservice
. - 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
edited Jul 22 at 13:45
Jeff Schaller
30.8k846104
30.8k846104
answered Jul 18 at 17:08
Mark Stosberg
3,4191023
3,4191023
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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