Elegant way to have systemd user service wait for mysqld to be available on startup
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have a server on which I am running a daemon as a normal user. I intend to give access to this user in the future to people I trust... but, as a precaution, I would like any configuration and management to be done without su or sudo access. For this reason I've written a simple systemd user unit and tested that it works. It does.
The problem is when restarting the server. The systemd attempts to start the daemon before mariadb (which this daemon needs) is ready. This causes the daemon to fail repeatedly until it exceeds systemd's StartLimit and systemd stops attempting to start the daemon all together.
There are a number of approaches I could take with this. I could re-write the systemd unit to run a script that queries the sql server over and over till it gets a connection and only then attempts to launch the daemon. Or I could add to the systemd unit a timeout between restarts of say... 30 seconds? But both feel... messy... pedestrian. I'd rather a more elegant solution.
I've been looking over the manpages of systemd but... there's a lot there. Any thoughts?
The unit file in question:
[Unit]
Description=Teamspeak 3
[Service]
Type=forking
#User=teamspeak
#Group=teamspeak
UMask=0027
Restart=always
WorkingDirectory=/home/teamspeak/ts
PIDFile=/home/teamspeak/ts/ts3server.pid
ExecStart=/home/teamspeak/ts/ts3server_startscript.sh start inifile=/home/teamspeak/ts/ts3server.ini
ExecStop=/home/teamspeak/ts/ts3server_startscript.sh stop
ExecReload=/home/teamspeak/ts/ts3server_startscript.sh restart
[Install]
WantedBy=default.target
systemd systemd-boot
add a comment |Â
up vote
0
down vote
favorite
I have a server on which I am running a daemon as a normal user. I intend to give access to this user in the future to people I trust... but, as a precaution, I would like any configuration and management to be done without su or sudo access. For this reason I've written a simple systemd user unit and tested that it works. It does.
The problem is when restarting the server. The systemd attempts to start the daemon before mariadb (which this daemon needs) is ready. This causes the daemon to fail repeatedly until it exceeds systemd's StartLimit and systemd stops attempting to start the daemon all together.
There are a number of approaches I could take with this. I could re-write the systemd unit to run a script that queries the sql server over and over till it gets a connection and only then attempts to launch the daemon. Or I could add to the systemd unit a timeout between restarts of say... 30 seconds? But both feel... messy... pedestrian. I'd rather a more elegant solution.
I've been looking over the manpages of systemd but... there's a lot there. Any thoughts?
The unit file in question:
[Unit]
Description=Teamspeak 3
[Service]
Type=forking
#User=teamspeak
#Group=teamspeak
UMask=0027
Restart=always
WorkingDirectory=/home/teamspeak/ts
PIDFile=/home/teamspeak/ts/ts3server.pid
ExecStart=/home/teamspeak/ts/ts3server_startscript.sh start inifile=/home/teamspeak/ts/ts3server.ini
ExecStop=/home/teamspeak/ts/ts3server_startscript.sh stop
ExecReload=/home/teamspeak/ts/ts3server_startscript.sh restart
[Install]
WantedBy=default.target
systemd systemd-boot
add a comment |Â
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a server on which I am running a daemon as a normal user. I intend to give access to this user in the future to people I trust... but, as a precaution, I would like any configuration and management to be done without su or sudo access. For this reason I've written a simple systemd user unit and tested that it works. It does.
The problem is when restarting the server. The systemd attempts to start the daemon before mariadb (which this daemon needs) is ready. This causes the daemon to fail repeatedly until it exceeds systemd's StartLimit and systemd stops attempting to start the daemon all together.
There are a number of approaches I could take with this. I could re-write the systemd unit to run a script that queries the sql server over and over till it gets a connection and only then attempts to launch the daemon. Or I could add to the systemd unit a timeout between restarts of say... 30 seconds? But both feel... messy... pedestrian. I'd rather a more elegant solution.
I've been looking over the manpages of systemd but... there's a lot there. Any thoughts?
The unit file in question:
[Unit]
Description=Teamspeak 3
[Service]
Type=forking
#User=teamspeak
#Group=teamspeak
UMask=0027
Restart=always
WorkingDirectory=/home/teamspeak/ts
PIDFile=/home/teamspeak/ts/ts3server.pid
ExecStart=/home/teamspeak/ts/ts3server_startscript.sh start inifile=/home/teamspeak/ts/ts3server.ini
ExecStop=/home/teamspeak/ts/ts3server_startscript.sh stop
ExecReload=/home/teamspeak/ts/ts3server_startscript.sh restart
[Install]
WantedBy=default.target
systemd systemd-boot
I have a server on which I am running a daemon as a normal user. I intend to give access to this user in the future to people I trust... but, as a precaution, I would like any configuration and management to be done without su or sudo access. For this reason I've written a simple systemd user unit and tested that it works. It does.
The problem is when restarting the server. The systemd attempts to start the daemon before mariadb (which this daemon needs) is ready. This causes the daemon to fail repeatedly until it exceeds systemd's StartLimit and systemd stops attempting to start the daemon all together.
There are a number of approaches I could take with this. I could re-write the systemd unit to run a script that queries the sql server over and over till it gets a connection and only then attempts to launch the daemon. Or I could add to the systemd unit a timeout between restarts of say... 30 seconds? But both feel... messy... pedestrian. I'd rather a more elegant solution.
I've been looking over the manpages of systemd but... there's a lot there. Any thoughts?
The unit file in question:
[Unit]
Description=Teamspeak 3
[Service]
Type=forking
#User=teamspeak
#Group=teamspeak
UMask=0027
Restart=always
WorkingDirectory=/home/teamspeak/ts
PIDFile=/home/teamspeak/ts/ts3server.pid
ExecStart=/home/teamspeak/ts/ts3server_startscript.sh start inifile=/home/teamspeak/ts/ts3server.ini
ExecStop=/home/teamspeak/ts/ts3server_startscript.sh stop
ExecReload=/home/teamspeak/ts/ts3server_startscript.sh restart
[Install]
WantedBy=default.target
systemd systemd-boot
systemd systemd-boot
asked 2 mins ago
Cliff Armstrong
2261210
2261210
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f477867%2felegant-way-to-have-systemd-user-service-wait-for-mysqld-to-be-available-on-star%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