2013-02-28 25 views
7

Yapabilir miyim? Bu başlat servisi aşağıda, çalıştırdıktan sonra hata gösterilmiyor, ancak aşağıdaki sunucu betiği çalışmıyor!linux start up betiği systemd

ln /lib/systemd/aquarium.service aquarium.service 
systemctl daemon-reload 
systemctl enable aquarium.service 
systemctl start aquarium.service 

sayesinde

aquarium.service:

burada
[Unit] 
Description=Start aquarium server 

[Service] 
WorkingDirectory=/home/root/python/code/aquarium/ 
ExecStart=/bin/bash server.* start 
KillMode=process 

[Install] 
WantedBy=multi-user.target 

#!/bin/bash 

PID="" 

function get_pid { 
    PID=`pidof python ./udpthread.py` 
} 

function stop { 
    get_pid 
    if [ -z $PID ]; then 
     echo "server is not running." 
     exit 1 
    else 
     echo -n "Stopping server.." 
     kill -9 $PID 
     sleep 1 
     echo ".. Done." 
    fi 
} 


function start { 
    get_pid 
    if [ -z $PID ]; then 
     echo "Starting server.." 
     ./udpthread.py & 
     get_pid 
     echo "Done. PID=$PID" 
    else 
     echo "server is already running, PID=$PID" 
    fi 
} 

function restart { 
    echo "Restarting server.." 
    get_pid 
    if [ -z $PID ]; then 
     start 
    else 
     stop 
     sleep 5 
     start 
    fi 
} 


function status { 
    get_pid 
    if [ -z $PID ]; then 
     echo "Server is not running." 
     exit 1 
    else 
     echo "Server is running, PID=$PID" 
    fi 
} 

case "$1" in 
    start) 
     start 
    ;; 
    stop) 
     stop 
    ;; 
    restart) 
     restart 
    ;; 
    status) 
     status 
    ;; 
    *) 
     echo "Usage: $0 {start|stop|restart|status}" 
esac 
+0

daha ayrıntılı ve eksiksiz cevap: bunun için http://unix.stackexchange.com/a/47715 –

cevap

17

"Type = forking" ve kullanımını kullanmayı deneyin server.sh script tam dosya adı.

[Unit] 
Description=Start aquarium server 

[Service] 
WorkingDirectory=/home/root/python/code/aquarium/ 
Type=forking 
ExecStart=/bin/bash server.sh start 
KillMode=process 

[Install] 
WantedBy=multi-user.target 

işe, bu komutun sonrası çıkışı:

# journalctl -u aquarium.service 
+0

Teşekkür Ancak, yazdığınız tam komut dosyasını kullanırken bunu elde ediyorum./bin/bash server.sh start komut dosyasını başlattığını biliyorum! beaglebone: ~ # systemctl status aquarium.service akvaryum.service - Akvaryum sunucusunu başlat Yüklü: yüklü (/etc/systemd/system/aquarium.service; etkin) Aktif: başarısız (Sonuç: çıkış kodu), Cum, 01 Mar 2013 18:18:26 +1100; 23s ago İşlem: 12545 ExecStart =/bin/bash server.sh start (kod = çıkıldı, durum = 200/CHDIR) Ana PID: 12482 (kod = çıkıldı, durum = 200/CHDIR) CGroup: name = systemd: /system/aquarium.service – Ossama

+0

Bunu eklemeyi unuttum Mar 01 18:18:26 beaglebone (bash) [12545]: CHDIR adımında başarısız oldu/bin/bash: Böyle bir dosya veya dizin yok – Ossama

+0

hmm, hangi sistemi kullanıyorsunuz ? Arch Linux üzerinde bu dosyalar sembolik bağlantılar şunlardır: '% ls-l/bin/sh/bin/bash lrwxrwxrwx 1 kök kök 15 Ocak 26 21:19/bin/bash -> ../usr/bin/bash * lrwxrwxrwx 1 kök kökü 15 Ocak 26 21:19/bin/sh -> ../ usr/bin/bash * ' "/bin/bash "yerine"/bin/sh "yazmayı deneyin ve dosyaları "ls -l" –