[CentOS] systemctl (again)

Andrew Holway andrew.holway at gmail.com
Thu Apr 2 21:16:33 UTC 2015


It might be SELinux. On a standard system; when we run things as a user
from the command line SELinux rules do not apply. It would explain why it
works manually but not via systemd.

Rather than using an init.d script you might want to try using a systemd
service. I haven't tested but something like this should work.

[Unit]
Description=timidity daemon

[Service]
PIDFile=/var/run/timidity.pid
User=someuser
Group=someuser
WorkingDirectory=/home/someuser
ExecStart=/bin/timidity
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true





On 2 April 2015 at 23:07, J Martin Rushton <martinrushton56 at btinternet.com>
wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I've been trying to get the timidity system running as a daemon.  I
> wrote the following init script:
>
>         #!/bin/sh
>         #
>         # timidity
>         #
>         ### BEGIN INIT INFO
>         # Provides: timidity
>         # Required-Start:
>         # Required-Stop:
>         # Default-Start:  2 3 4 5
>         # Default-Stop: 0 1 6
>         # Short-Description: Add and remove timidity
>         # Description:
>         ### END INIT INFO
>
>         . /etc/rc.d/init.d/functions
>
>         RETVAL=0
>         PROG=timidity
>         EXEC=/bin/$PROG
>         PIDFILE=/var/run/timidity.pid
>
>         function start {
>                 [[ -x $EXEC ]] || exit 5
>                 echo -n "Starting $PROG: "
>                 $EXEC -iAD
>                 RETVAL=$?
>                 echo
>                 return $RETVAL
>         }
>
>         function stop {
>                 echo -n "Stopping $PROG: "
>                 killproc $EXEC -TERM
>                 RETVAL=$?
>                 echo
>                 return $RETVAL
>         }
>
>         case "$1" in
>                 start)  start
>                         RETVAL=$?
>                         ;;
>                 stop)   stop
>                         RETVAL=$?
>                         ;;
>                 status)
>                         status $PROG
>                         RETVAL=$?
>                         ;;
>                 restart)
>                         stop
>                         start
>                         ;;
>                 reload)
>                         stop
>                         start
>                         ;;
>                 *)
>                         echo $"Usage: $prog
>  {start|stop|status|restart|reload}"
>                         exit 1
>         esac
>         exit $RETVAL
>
>
> When run through systemctl during startup it fails:
>
>         [root at tamar init.d]# systemctl status timidity
>         timidity.service - LSB: Add and remove timidity
>            Loaded: loaded (/etc/rc.d/init.d/timidity)
>            Active: active (exited) since Thu ...
>           Process: 784 ExecStart=/etc/rc.d/init.d/timidity start
> (code=exited, status=0/SUCCESS)
>
>         ... Starting LSB: Add and remove timidity...
>         ... Starting timidity:
>         ... jack_client_new: deprecated
>         ... Started LSB: Add and remove timidity.
>         ... Cannot connect to server socket err = No such file or directory
>         ... Cannot connect to server request channel
>         ... jack server is not running or cannot be started
>         ... Couldn't open output device
>
> But when run directly is works fine:
>
>         [root at tamar init.d]# ./timidity start
>         Starting timidity:
>         TiMidity starting in ALSA server mode
>         Opening sequencer port: 128:0 128:1 128:2 128:3
>
> If I use # service timidity start it also fails.
>
> I _think_ that what is happening is that systemctl is stripping off
> the switch.  I've spent a couple of hours searching for any links or
> explanation and got nowhere.  I even knocked up a script to try and
> separate the two parts:
>         #!/bin/sh
>         cd /etc/init.d
>         ./timidity start
> but to no avail.
>
> If there is a simple fix could someone point me there, if it's complex
> don't bother, I only need the daemon when running MIDI and can start
> it by hand.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.22 (GNU/Linux)
>
> iQIcBAEBAgAGBQJVHa+rAAoJEAF3yXsqtyBlKFUP/0olzOxF44xGa0/b1UI9LyKb
> 8LWLJ6XYXQfwJZvZ7N5v/r9g6WPesIuWf/TugXEz20MhrN0BhoqmUrkD9FjVnpFa
> B7zQxRQ/DUXs2Z/w2DCfHRs5QWr3o31EGNPw/cZtqMf2bq+Z0LXXlU6A4QozDFe8
> Aq/ZYduOr5GG6D8DPRCSV2ggFGvs27I7vvp48bvCNZ4jh2dAjBSlygI42Koug2Ga
> UcAGllj4Litdm+O5hUpyPtsJC58umfNy4Lq9Y6HBxIpeZrioxNE+trNQHoZuzoP/
> clLItDMwj990Hs7ft3eyt1oIihuCTsVQ3HOkn0fjZ0OAWPIudq7ZynzfHctMGtP2
> Htx0A3coYxFFZ/fZZfYUkM4FQU6OA6fQ378u9hdxq9+XKayCh4938PZHmKjGHUTH
> DSu+iZVJ8DEc62pfgeLUWMidEgSu5/n5ROGIHed/wwt4nE6rGv/fz0D33ArMwD3t
> Ozybkt+FW2u8XK4qkA/ehgf3SBK4AIHMNg9IDWiWSaF4krQlInhKHGoCp1Xi1ISV
> 2C/Lb7exn2CX/Uohdhqy86HNOhHHbZ6mkOL1k8XTIIazjRWJWQ/+gkt6Bj39q+K8
> NDnN03oVYsXgVz2nqFT3eQ001k/pRlkKn11ZYtEZ1fY77nzsOj+J3DD/txn8qTRi
> yNSvbWmxPj24hEVzSKu3
> =CEIq
> -----END PGP SIGNATURE-----
> _______________________________________________
> CentOS mailing list
> CentOS at centos.org
> http://lists.centos.org/mailman/listinfo/centos
>



More information about the CentOS mailing list